|
|
@@ -0,0 +1,55 @@
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonButton, IonTextarea, IonInput } from '@ionic/angular/standalone';
|
|
|
+/** 引用:从fmode-ng库引用FmodeChatCompletion类 */
|
|
|
+import { FmodeChatCompletion,MarkdownPreviewModule } from 'fmode-ng';
|
|
|
+@Component({
|
|
|
+ selector: 'app-eatadvice',
|
|
|
+ templateUrl: './eatadvice.component.html',
|
|
|
+ styleUrls: ['./eatadvice.component.scss'],
|
|
|
+ standalone: true,
|
|
|
+ imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton,IonTextarea,IonInput,
|
|
|
+ // 引入fm-markdown-preview组件模块
|
|
|
+ MarkdownPreviewModule
|
|
|
+ ],
|
|
|
+})
|
|
|
+export class EatadviceComponent implements OnInit {
|
|
|
+
|
|
|
+ constructor() {}
|
|
|
+ ngOnInit(){}
|
|
|
+ // 用户输入提示词
|
|
|
+ keshi:string = "填写食物"
|
|
|
+ keshiInput(ev:any){
|
|
|
+ this.keshi = 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.keshi},请您根据我的饮食描述,给出初步的分析,并给出一些建议。
|
|
|
+ 以下是用户的口述:${this.userPrompt}
|
|
|
+ `
|
|
|
+
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
+ {role:"system",content:""},
|
|
|
+ {role:"user",content:PromptTemplate}
|
|
|
+ ])
|
|
|
+ completion.sendCompletion().subscribe((message:any)=>{
|
|
|
+ // 打印消息体
|
|
|
+ console.log(message.content)
|
|
|
+ // 赋值消息内容给组件内属性
|
|
|
+ this.responseMsg = message.content
|
|
|
+ if(message?.complete){ // 判断message为完成状态,则设置isComplete为完成
|
|
|
+ this.isComplete = true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|