|
@@ -1,7 +1,74 @@
|
|
|
+// import { Component } from '@angular/core';
|
|
|
+// import { IonicModule } from '@ionic/angular'; // 这里引入 IonicModule
|
|
|
+// import { ExploreContainerComponent } from '../explore-container/explore-container.component';
|
|
|
+// import { FmodeChatCompletion,MarkdownPreviewModule} from 'fmode-ng';
|
|
|
+
|
|
|
+// @Component({
|
|
|
+// selector: 'app-tab2',
|
|
|
+// templateUrl: 'tab2.page.html',
|
|
|
+// styleUrls: ['tab2.page.scss'],
|
|
|
+// standalone: true,
|
|
|
+// imports: [
|
|
|
+// ExploreContainerComponent,
|
|
|
+// IonicModule, // 引入 IonicModule
|
|
|
+// MarkdownPreviewModule,
|
|
|
+// ],
|
|
|
+// })
|
|
|
+// export class Tab2Page {
|
|
|
+// ngOnInit(){}
|
|
|
+// constructor() {}
|
|
|
+
|
|
|
+// // 用户输入提示词
|
|
|
+// qunti: string = ""
|
|
|
+
|
|
|
+// quntiInput(ev: any) {
|
|
|
+// this.qunti = ev.detail.value;
|
|
|
+// }
|
|
|
+// // 用户输入提示词
|
|
|
+// jikou: string = ""
|
|
|
+
|
|
|
+// jikouInput(ev: any) {
|
|
|
+// this.jikou = 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.qunti},用户的饮食忌口是${this.jikou}需求是${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){
|
|
|
+// this.isComplete=true
|
|
|
+// }
|
|
|
+// })
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
import { Component } from '@angular/core';
|
|
|
import { IonicModule } from '@ionic/angular'; // 这里引入 IonicModule
|
|
|
import { ExploreContainerComponent } from '../explore-container/explore-container.component';
|
|
|
-import { FmodeChatCompletion,MarkdownPreviewModule} from 'fmode-ng';
|
|
|
+import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-tab2',
|
|
@@ -15,51 +82,62 @@ import { FmodeChatCompletion,MarkdownPreviewModule} from 'fmode-ng';
|
|
|
],
|
|
|
})
|
|
|
export class Tab2Page {
|
|
|
- ngOnInit(){}
|
|
|
+ ngOnInit() {}
|
|
|
constructor() {}
|
|
|
|
|
|
// 用户输入提示词
|
|
|
- qunti: string = ""
|
|
|
-
|
|
|
+ qunti: string = "";
|
|
|
+ jikou: string = "";
|
|
|
+ userPrompt: string = "";
|
|
|
+
|
|
|
+ // 用户输入的需求
|
|
|
quntiInput(ev: any) {
|
|
|
this.qunti = ev.detail.value;
|
|
|
}
|
|
|
- // 用户输入提示词
|
|
|
- jikou: string = ""
|
|
|
-
|
|
|
+
|
|
|
jikouInput(ev: any) {
|
|
|
this.jikou = ev.detail.value;
|
|
|
}
|
|
|
- // 用户输入提示词
|
|
|
- userPrompt: string = ""
|
|
|
-
|
|
|
+
|
|
|
promptInput(ev: any) {
|
|
|
this.userPrompt = ev.detail.value;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 属性:组件内用于展示消息内容的变量
|
|
|
- responseMsg: any = ""
|
|
|
- // 方法:实例化completion对象,传入消息数组,并订阅生成的可观察对象。
|
|
|
- isComplete:boolean=false;
|
|
|
+ responseMsg: string = "";
|
|
|
+ // 是否完成生成
|
|
|
+ isComplete: boolean = false;
|
|
|
+
|
|
|
sendMessage() {
|
|
|
- console.log("create")
|
|
|
+ console.log("create");
|
|
|
+
|
|
|
+ // 每次生成新的饮食规划时,首先清空旧的规划
|
|
|
+ this.responseMsg = ""; // 清空旧的响应消息
|
|
|
+ this.isComplete = false; // 重置完成状态
|
|
|
+ // 拼接用户输入的需求
|
|
|
+ let newPrompt = `
|
|
|
+ 你是一名专业的饮食营养规划师,拥有丰富的营养学背景和实践经验。你的工作是为不同需求的人群提供个性化的饮食规划,帮助他们实现健康目标,如减肥、增肌、健康维护或疾病管理。
|
|
|
+ 你可以根据用户的需求为客户设计量身定制具体的饮食方案。
|
|
|
+ 当前来咨询的用户群体是${this.qunti},用户的饮食忌口是${this.jikou},需求是${this.userPrompt}.
|
|
|
+ `;
|
|
|
|
|
|
- let PromptTemplate=`
|
|
|
- 你是一名专业的饮食营养规划师,拥有丰富的营养学背景和实践经验。你的工作是为不同需求的人群提供个性化的饮食规划,帮助他们实现健康目标,如减肥、增肌、健康维护或疾病管理。
|
|
|
- 你可以根据用户的需求为客户设计量身定制具体的饮食方案。
|
|
|
- 当前来咨询的用户群体是${this.qunti},用户的饮食忌口是${this.jikou}需求是${this.userPrompt}`
|
|
|
+ // 创建消息请求,传递完整的需求
|
|
|
let completion = new FmodeChatCompletion([
|
|
|
- {role: "system", content: ""},
|
|
|
- {role: "user", content: this.userPrompt}
|
|
|
- ])
|
|
|
+ { role: "system", content: "" },
|
|
|
+ { role: "user", content: newPrompt }
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 执行生成并订阅返回结果
|
|
|
completion.sendCompletion().subscribe((message: any) => {
|
|
|
- // 打印消息体
|
|
|
- console.log(message.content)
|
|
|
- // 赋值消息内容给组件内属性
|
|
|
- this.responseMsg = message.content
|
|
|
- if(message?.complete){
|
|
|
- this.isComplete=true
|
|
|
+ console.log(message.content);
|
|
|
+
|
|
|
+ // 如果有新内容,更新组件的响应消息,覆盖旧的规划
|
|
|
+ this.responseMsg = message.content;
|
|
|
+
|
|
|
+ // 如果返回内容标记为完成,则更新状态
|
|
|
+ if (message?.complete) {
|
|
|
+ this.isComplete = true;
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
}
|
|
|
}
|