Skip to content

Commit

Permalink
Experiment: Course Ratings & suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mutugiii committed Aug 15, 2023
1 parent 07a21d4 commit 14881a1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app/courses/add-courses/courses-add.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@
</div>
<div class="steps-container">
<planet-courses-step [(steps)]="steps" (addStepEvent)="addStep()"></planet-courses-step>
{{rating}}
</div>
<div class="actions-container">
<button type="submit" (click)="onSubmit()" [planetSubmit]="courseForm.valid" mat-raised-button color="primary" i18n>Submit</button>
<button class="margin-lr-2" type="button" mat-raised-button color="warn" (click)="cancel()" i18n>Cancel</button>
<button mat-raised-button color="accent" (click)="addStep()" i18n>Add Step</button>
<button class="margin-lr-2" type="button" mat-raised-button color="basic" (click)="rateCourse()" i18n>Rate Course</button>
</div>
</div>
</div>
30 changes: 29 additions & 1 deletion src/app/courses/add-courses/courses-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -273,4 +276,29 @@ 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 = rating?.chat;
}
);
} else {
showFormErrors(this.courseForm.controls);
return;
}
}

}
2 changes: 2 additions & 0 deletions src/app/courses/add-courses/courses-step.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
</mat-chip>
</mat-chip-list>
</ng-container>
<button mat-raised-button color="basic" (click)="rateStep()" i18n>Rate course step</button>
<br><div>{{rating}}</div>
</div>
<div planetStepListActions>
<a mat-raised-button color="primary" (click)="addExam()" i18n>{{activeStep?.exam ? 'Update' : 'Add' }} Test</a>
Expand Down
19 changes: 18 additions & 1 deletion src/app/courses/add-courses/courses-step.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -24,14 +25,16 @@ export class CoursesStepComponent implements OnDestroy {
dialogRef: MatDialogRef<DialogsAddResourcesComponent>;
activeStep: any;
activeStepIndex = -1;
rating: Text;
private onDestroy$ = new Subject<void>();

constructor(
private router: Router,
private fb: FormBuilder,
private dialog: MatDialog,
private coursesService: CoursesService,
private dialogsLoadingService: DialogsLoadingService
private dialogsLoadingService: DialogsLoadingService,
private chatService: ChatService
) {
this.stepForm = this.fb.group({
id: '',
Expand Down Expand Up @@ -100,4 +103,18 @@ 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 = completion?.chat;
},
(error: any) => {
console.log(error);
}
);
}

}

0 comments on commit 14881a1

Please sign in to comment.