|
@@ -0,0 +1,58 @@
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { IonButton, IonContent, IonHeader, IonInput, IonTitle, IonToolbar } from '@ionic/angular/standalone';
|
|
|
+import { IonTextarea } from '@ionic/angular/standalone';
|
|
|
+import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-page-ailearning',
|
|
|
+ templateUrl: './page-ailearning.component.html',
|
|
|
+ styleUrls: ['./page-ailearning.component.scss'],
|
|
|
+ standalone: true,
|
|
|
+ imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton,
|
|
|
+ IonTextarea, IonInput, MarkdownPreviewModule
|
|
|
+ ],
|
|
|
+})
|
|
|
+export class PageAIlearningComponent implements OnInit {
|
|
|
+ constructor() { }
|
|
|
+
|
|
|
+ ngOnInit() { }
|
|
|
+
|
|
|
+ // 用户输入提示词
|
|
|
+ course: string = "课程名称"
|
|
|
+ courseInput(ev: any) {
|
|
|
+ this.course = ev.detail.value;
|
|
|
+ }
|
|
|
+ // 用户输入提示词
|
|
|
+ userPrompt: string = "请描述你想学习的内容。"
|
|
|
+ promptInput(ev: any) {
|
|
|
+ this.userPrompt = ev.detail.value;
|
|
|
+ }
|
|
|
+ // 属性:组件内用于展示消息内容的变量
|
|
|
+ responseMsg: any = ""
|
|
|
+ // 方法:实例化completion对象,传入消息数组,并订阅生成的可观察对象。
|
|
|
+ isComplete: boolean = false; // 定义完成状态属性,用来标记是否补全完成
|
|
|
+ sendMessage() {
|
|
|
+ console.log("create")
|
|
|
+
|
|
|
+ let PromptTemplate = `
|
|
|
+ 您作为一名专业的${this.courseInput}老师,请您根据用户描述的学习内容,给出知识点的解析,并给出一些建议。以下是用户的口述:${this.userPrompt}
|
|
|
+ `
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
+ { role: "system", content: "" },
|
|
|
+ { role: "user", content: this.userPrompt }
|
|
|
+ ])
|
|
|
+ completion.sendCompletion().subscribe((message: any) => {
|
|
|
+ // 打印消息体
|
|
|
+ console.log(message.content)
|
|
|
+ // 赋值消息内容给组件内属性
|
|
|
+ this.responseMsg = message.content
|
|
|
+ if (message?.complete) { // 判断message为完成状态,则设置isComplete为完成
|
|
|
+ this.isComplete = true
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ this.isComplete = false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|