|
@@ -17,7 +17,8 @@ import {
|
|
IonTitle,
|
|
IonTitle,
|
|
IonToolbar,
|
|
IonToolbar,
|
|
} from '@ionic/angular/standalone';
|
|
} from '@ionic/angular/standalone';
|
|
-import { TestChatCompletion } from './fmode-chat-completion';
|
|
|
|
|
|
+/** 引用:从fmode-ng库引用FmodeChatCompletion类 */
|
|
|
|
+import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'app-aiplan-page',
|
|
selector: 'app-aiplan-page',
|
|
@@ -41,6 +42,7 @@ import { TestChatCompletion } from './fmode-chat-completion';
|
|
IonGrid,
|
|
IonGrid,
|
|
IonRow,
|
|
IonRow,
|
|
IonCol,
|
|
IonCol,
|
|
|
|
+ MarkdownPreviewModule,
|
|
],
|
|
],
|
|
})
|
|
})
|
|
export class AiplanPageComponent implements OnInit {
|
|
export class AiplanPageComponent implements OnInit {
|
|
@@ -77,18 +79,74 @@ export class AiplanPageComponent implements OnInit {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- submit() {
|
|
|
|
- // 提交表单数据
|
|
|
|
- // let data = {
|
|
|
|
- // trainingType: this.trainingType,
|
|
|
|
- // weight: this.weight,
|
|
|
|
- // trainingTime: this.trainingTime,
|
|
|
|
- // trainingIntensity: this.trainingIntensity,
|
|
|
|
- // trainingSite: this.trainingSite,
|
|
|
|
- // needs: this.needs,
|
|
|
|
- // };
|
|
|
|
|
|
+ // submit() {
|
|
|
|
+ // // 提交表单数据
|
|
|
|
+ // // let data = {
|
|
|
|
+ // // trainingType: this.trainingType,
|
|
|
|
+ // // weight: this.weight,
|
|
|
|
+ // // trainingTime: this.trainingTime,
|
|
|
|
+ // // trainingIntensity: this.trainingIntensity,
|
|
|
|
+ // // trainingSite: this.trainingSite,
|
|
|
|
+ // // needs: this.needs,
|
|
|
|
+ // // };
|
|
|
|
|
|
|
|
+ // // 用户输入数据提取
|
|
|
|
+ // let ipts = document.querySelectorAll('ion-input');
|
|
|
|
+ // let textarea = document.querySelectorAll('ion-textarea');
|
|
|
|
+ // let userinputs = '';
|
|
|
|
+ // ipts.forEach((ipt) => {
|
|
|
|
+ // userinputs += ipt.value + ' ';
|
|
|
|
+ // });
|
|
|
|
+ // textarea.forEach((text) => {
|
|
|
|
+ // userinputs += text.value + ' ';
|
|
|
|
+ // });
|
|
|
|
+ // let userinputlist = userinputs.split(' ');
|
|
|
|
+ // let data = {
|
|
|
|
+ // trainingType: userinputlist[0],
|
|
|
|
+ // sex: userinputlist[1],
|
|
|
|
+ // weight: userinputlist[2],
|
|
|
|
+ // trainingTime: userinputlist[3],
|
|
|
|
+ // trainingIntensity: userinputlist[4],
|
|
|
|
+ // trainingSite: userinputlist[5],
|
|
|
|
+ // needs: userinputlist[6],
|
|
|
|
+ // };
|
|
|
|
+ // console.log(data);
|
|
|
|
+
|
|
|
|
+ // // ai对话实现
|
|
|
|
+ // let prompt = `我是一名体重为${data.weight}kg的${data.sex}性,我只有${data.trainingTime}分钟来${data.trainingType},我希望训练强度${data.trainingIntensity}一点,而我想训练的部位为${data.trainingSite}, 一些其他的需求有${data.needs}。 请你作为一名专业的健身教练,根据我提供的信息,为我制定${data.trainingType}计划。`;
|
|
|
|
+ // console.log(prompt);
|
|
|
|
+
|
|
|
|
+ // let token = `r:E4KpGvTEto-187799890851732794669`;
|
|
|
|
+ // localStorage.setItem('token', token);
|
|
|
|
+
|
|
|
|
+ // let messageList = [
|
|
|
|
+ // {
|
|
|
|
+ // role: 'system',
|
|
|
|
+ // content: `${new Date().toLocaleString}`,
|
|
|
|
+ // },
|
|
|
|
+ // {
|
|
|
|
+ // role: 'user',
|
|
|
|
+ // content: prompt,
|
|
|
|
+ // },
|
|
|
|
+ // ];
|
|
|
|
+
|
|
|
|
+ // //fmode-chat
|
|
|
|
+ // let completion = new TestChatCompletion(messageList);
|
|
|
|
+ // completion.createCompletionByStream();
|
|
|
|
+
|
|
|
|
+ // this.aiplan = '';
|
|
|
|
+ // setInterval(() => {
|
|
|
|
+ // // console.log(messageList);
|
|
|
|
+ // this.aiplan = messageList[messageList.length - 1].content;
|
|
|
|
+ // }, 1000);
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ isComplete: boolean = false;
|
|
|
|
+
|
|
|
|
+ sendMessage() {
|
|
// 用户输入数据提取
|
|
// 用户输入数据提取
|
|
|
|
+ this.isComplete = false;
|
|
|
|
+ this.aiplan = '';
|
|
let ipts = document.querySelectorAll('ion-input');
|
|
let ipts = document.querySelectorAll('ion-input');
|
|
let textarea = document.querySelectorAll('ion-textarea');
|
|
let textarea = document.querySelectorAll('ion-textarea');
|
|
let userinputs = '';
|
|
let userinputs = '';
|
|
@@ -114,28 +172,20 @@ export class AiplanPageComponent implements OnInit {
|
|
let prompt = `我是一名体重为${data.weight}kg的${data.sex}性,我只有${data.trainingTime}分钟来${data.trainingType},我希望训练强度${data.trainingIntensity}一点,而我想训练的部位为${data.trainingSite}, 一些其他的需求有${data.needs}。 请你作为一名专业的健身教练,根据我提供的信息,为我制定${data.trainingType}计划。`;
|
|
let prompt = `我是一名体重为${data.weight}kg的${data.sex}性,我只有${data.trainingTime}分钟来${data.trainingType},我希望训练强度${data.trainingIntensity}一点,而我想训练的部位为${data.trainingSite}, 一些其他的需求有${data.needs}。 请你作为一名专业的健身教练,根据我提供的信息,为我制定${data.trainingType}计划。`;
|
|
console.log(prompt);
|
|
console.log(prompt);
|
|
|
|
|
|
- let token = `r:E4KpGvTEto-187799890851732794669`;
|
|
|
|
- localStorage.setItem('token', token);
|
|
|
|
-
|
|
|
|
- let messageList = [
|
|
|
|
- {
|
|
|
|
- role: 'system',
|
|
|
|
- content: `${new Date().toLocaleString}`,
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- role: 'user',
|
|
|
|
- content: prompt,
|
|
|
|
- },
|
|
|
|
- ];
|
|
|
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
|
+ { role: 'system', content: '' },
|
|
|
|
+ { role: 'user', content: prompt },
|
|
|
|
+ ]);
|
|
|
|
+ completion.sendCompletion().subscribe((message: any) => {
|
|
|
|
+ // 打印消息体
|
|
|
|
+ // console.log(message.content);
|
|
|
|
+ // 赋值消息内容给组件内属性
|
|
|
|
+ this.aiplan = message.content;
|
|
|
|
|
|
- //fmode-chat
|
|
|
|
- let completion = new TestChatCompletion(messageList);
|
|
|
|
- completion.createCompletionByStream();
|
|
|
|
-
|
|
|
|
- this.aiplan = '';
|
|
|
|
- setInterval(() => {
|
|
|
|
- // console.log(messageList);
|
|
|
|
- this.aiplan = messageList[messageList.length - 1].content;
|
|
|
|
- }, 1000);
|
|
|
|
|
|
+ if (message?.complete) {
|
|
|
|
+ // 判断message为完成状态,则设置isComplete为完成
|
|
|
|
+ this.isComplete = true;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|