diff --git a/src/app/courses/add-courses/courses-add.component.html b/src/app/courses/add-courses/courses-add.component.html index 3a4aa9c6d9..e53410414b 100644 --- a/src/app/courses/add-courses/courses-add.component.html +++ b/src/app/courses/add-courses/courses-add.component.html @@ -42,11 +42,15 @@
+ + +
+
diff --git a/src/app/courses/add-courses/courses-add.component.ts b/src/app/courses/add-courses/courses-add.component.ts index e50741d9e0..b4a8195e4a 100644 --- a/src/app/courses/add-courses/courses-add.component.ts +++ b/src/app/courses/add-courses/courses-add.component.ts @@ -18,6 +18,7 @@ import { PouchService } from '../../shared/database/pouch.service'; import { debug } from '../../debug-operator'; import { TagsService } from '../../shared/forms/tags.service'; import { showFormErrors } from '../../shared/table-helpers'; +import { ChatService } from '../../shared/chat.service'; @Component({ templateUrl: 'courses-add.component.html', @@ -58,6 +59,7 @@ export class CoursesAddComponent implements OnInit, OnDestroy { languageNames = languages.map(list => list.name); mockStep = { stepTitle: $localize`Add title`, description: '!!!' }; + rating: String; constructor( private router: Router, @@ -71,7 +73,8 @@ export class CoursesAddComponent implements OnInit, OnDestroy { private stateService: StateService, private planetStepListService: PlanetStepListService, private pouchService: PouchService, - private tagsService: TagsService + private tagsService: TagsService, + private chatService: ChatService ) { this.createForm(); this.onFormChanges(); @@ -273,4 +276,43 @@ export class CoursesAddComponent implements OnInit, OnDestroy { return { ...this.coursesService.storeMarkdownImages({ ...course, steps }) }; } + rateCourse() { + if (this.courseForm.valid) { + const stepsContent = this.steps.length > 0 ? + `The course has ${this.steps.length} steps: ${this.steps.map(step => `${step.stepTitle} - ${step.description}`).join('\n')}` + : ''; + + const content = `In 3 clear blobs, 1. provide a rating for this course(granular rating out of 100%), 2. Explain why you gave the rating 3. Explain how to improve the course + Course Title: ${this.courseForm.get('courseTitle').value} + Course Description: ${this.courseForm.get('description').value.text} + Grade Level: ${this.courseForm.get('gradeLevel').value} + Subject Level: ${this.courseForm.get('subjectLevel').value} + ${stepsContent} + `; + + this.chatService.getPrompt(content).subscribe( + (rating) => { + this.rating = this.sanitizeText(rating?.chat); + } + ); + } else { + showFormErrors(this.courseForm.controls); + return; + } + } + + sanitizeText(text: any): any { + // Replace newline characters with
tags + const textWithLineBreaks = text.replace(/\n/g, '
'); + + // Replace code block markers with tags + const codeBlockStart = /```/g; + const codeBlockEnd = /```/g; + const textWithCodeBlocks = textWithLineBreaks + .replace(codeBlockStart, '') + .replace(codeBlockEnd, ''); + + return textWithCodeBlocks; + } + } diff --git a/src/app/courses/add-courses/courses-step.component.html b/src/app/courses/add-courses/courses-step.component.html index a5e1111b91..a99cd01d6b 100644 --- a/src/app/courses/add-courses/courses-step.component.html +++ b/src/app/courses/add-courses/courses-step.component.html @@ -29,6 +29,10 @@ + + + +
{{activeStep?.exam ? 'Update' : 'Add' }} Test diff --git a/src/app/courses/add-courses/courses-step.component.ts b/src/app/courses/add-courses/courses-step.component.ts index c57e43def1..dc9d88c2c6 100644 --- a/src/app/courses/add-courses/courses-step.component.ts +++ b/src/app/courses/add-courses/courses-step.component.ts @@ -7,6 +7,7 @@ import { takeUntil } from 'rxjs/operators'; import { CoursesService } from '../courses.service'; import { DialogsAddResourcesComponent } from '../../shared/dialogs/dialogs-add-resources.component'; import { DialogsLoadingService } from '../../shared/dialogs/dialogs-loading.service'; +import { ChatService } from '../../shared/chat.service'; @Component({ selector: 'planet-courses-step', @@ -24,6 +25,7 @@ export class CoursesStepComponent implements OnDestroy { dialogRef: MatDialogRef; activeStep: any; activeStepIndex = -1; + rating: Text; private onDestroy$ = new Subject(); constructor( @@ -31,7 +33,8 @@ export class CoursesStepComponent implements OnDestroy { private fb: FormBuilder, private dialog: MatDialog, private coursesService: CoursesService, - private dialogsLoadingService: DialogsLoadingService + private dialogsLoadingService: DialogsLoadingService, + private chatService: ChatService ) { this.stepForm = this.fb.group({ id: '', @@ -100,4 +103,32 @@ export class CoursesStepComponent implements OnDestroy { this.addStepEvent.emit(); } + rateStep() { + const content = `In 3 clear blobs, 1. provide a rating for this course step(granular rating out of 100%), 2. Explain why you gave the rating 3. Explain how to improve the course step + ${this.stepForm.get('stepTitle').value} - ${this.stepForm.get('description').value.text}`; + + this.chatService.getPrompt(content).subscribe( + (completion: any) => { + this.rating = this.sanitizeText(completion?.chat); + }, + (error: any) => { + console.log(error); + } + ); + } + + sanitizeText(text: any): any { + // Replace newline characters with
tags + const textWithLineBreaks = text.replace(/\n/g, '
'); + + // Replace code block markers with tags + const codeBlockStart = /```/g; + const codeBlockEnd = /```/g; + const textWithCodeBlocks = textWithLineBreaks + .replace(codeBlockStart, '') + .replace(codeBlockEnd, ''); + + return textWithCodeBlocks; + } + }