Skip to content

Commit

Permalink
hot fix chat text format(for course ratings demo)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mutugiii committed Sep 8, 2023
1 parent 3b48767 commit 8b8a027
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/app/courses/add-courses/courses-add.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
</div>
<div class="steps-container">
<planet-courses-step [(steps)]="steps" (addStepEvent)="addStep()"></planet-courses-step>
{{rating}}
<!-- {{sanitizeText(rating)}} -->
<!-- {{rating}} -->
<br><span [innerHTML]="rating"></span>
</div>
<div class="actions-container">
<button type="submit" (click)="onSubmit()" [planetSubmit]="courseForm.valid" mat-raised-button color="primary" i18n>Submit</button>
Expand Down
16 changes: 15 additions & 1 deletion src/app/courses/add-courses/courses-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class CoursesAddComponent implements OnInit, OnDestroy {

this.chatService.getPrompt(content).subscribe(
(rating) => {
this.rating = rating?.chat;
this.rating = this.sanitizeText(rating?.chat);
}
);
} else {
Expand All @@ -301,4 +301,18 @@ export class CoursesAddComponent implements OnInit, OnDestroy {
}
}

sanitizeText(text: any): any {
// Replace newline characters with <br> tags
const textWithLineBreaks = text.replace(/\n/g, '<br>');

// Replace code block markers with <code> tags
const codeBlockStart = /```/g;
const codeBlockEnd = /```/g;
const textWithCodeBlocks = textWithLineBreaks
.replace(codeBlockStart, '<code>')
.replace(codeBlockEnd, '</code>');

return textWithCodeBlocks;
}

}
4 changes: 3 additions & 1 deletion src/app/courses/add-courses/courses-step.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
</mat-chip-list>
</ng-container>
<button mat-raised-button color="basic" (click)="rateStep()" i18n>Rate course step</button>
<br><div>{{rating}}</div>
<!-- <br><div>{{sanitizeText(rating)}}</div> -->
<!-- <br><div>{{rating}}</div> -->
<br><div [innerHTML]="rating"></div>
</div>
<div planetStepListActions>
<a mat-raised-button color="primary" (click)="addExam()" i18n>{{activeStep?.exam ? 'Update' : 'Add' }} Test</a>
Expand Down
16 changes: 15 additions & 1 deletion src/app/courses/add-courses/courses-step.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,26 @@ export class CoursesStepComponent implements OnDestroy {

this.chatService.getPrompt(content).subscribe(
(completion: any) => {
this.rating = completion?.chat;
this.rating = this.sanitizeText(completion?.chat);
},
(error: any) => {
console.log(error);
}
);
}

sanitizeText(text: any): any {
// Replace newline characters with <br> tags
const textWithLineBreaks = text.replace(/\n/g, '<br>');

// Replace code block markers with <code> tags
const codeBlockStart = /```/g;
const codeBlockEnd = /```/g;
const textWithCodeBlocks = textWithLineBreaks
.replace(codeBlockStart, '<code>')
.replace(codeBlockEnd, '</code>');

return textWithCodeBlocks;
}

}

0 comments on commit 8b8a027

Please sign in to comment.