123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- import { Component, OnInit } from '@angular/core';
- import {
- IonButton,
- IonCard,
- IonCardHeader,
- IonCardSubtitle,
- IonCardTitle,
- IonCol,
- IonContent,
- IonGrid,
- IonHeader,
- IonInput,
- IonItem,
- IonList,
- IonRow,
- IonTextarea,
- IonTitle,
- IonToolbar,
- } from '@ionic/angular/standalone';
- /** 引用:从fmode-ng库引用FmodeChatCompletion类 */
- import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';
- @Component({
- selector: 'app-aiplan-page',
- templateUrl: './aiplan-page.component.html',
- styleUrls: ['./aiplan-page.component.scss'],
- standalone: true,
- imports: [
- IonHeader,
- IonTitle,
- IonToolbar,
- IonCard,
- IonContent,
- IonList,
- IonItem,
- IonInput,
- IonCardHeader,
- IonCardTitle,
- IonCardSubtitle,
- IonTextarea,
- IonButton,
- IonGrid,
- IonRow,
- IonCol,
- MarkdownPreviewModule,
- ],
- })
- export class AiplanPageComponent implements OnInit {
- constructor() {}
- ngOnInit() {}
- trainingType: string = '';
- sex: string = '';
- weight: number = NaN;
- trainingTime: number = NaN;
- trainingIntensity: string = '';
- trainingSite: string = '';
- needs: string = '';
- aiplan: string = '';
- userInputOntrainingType(ev: any) {
- this.trainingType = ev.detail.value;
- }
- userInputOnsex(ev: any) {
- this.sex = ev.detail.value;
- }
- userInputOnweight(ev: any) {
- this.weight = ev.detail.value;
- }
- userInputOntrainingTime(ev: any) {
- this.trainingTime = ev.detail.value;
- }
- userInputOntrainingIntensity(ev: any) {
- this.trainingIntensity = ev.detail.value;
- }
- userInputOntrainingSite(ev: any) {
- this.trainingSite = ev.detail.value;
- }
- userInputOnneeds(ev: any) {
- this.needs = ev.detail.value;
- }
- reset() {
- // 重置表单数据(有问题)
- // this.trainingType = '';
- // this.weight = NaN;
- // this.trainingTime = NaN;
- // this.trainingIntensity = '';
- // this.trainingSite = '';
- // this.needs = '';
- // 重置表单数据(无错误)
- let ipts = document.querySelectorAll('ion-input');
- let textarea = document.querySelectorAll('ion-textarea');
- ipts.forEach((ipt) => {
- ipt.value = '';
- });
- textarea.forEach((text) => {
- text.value = '';
- });
- }
- // 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 = true;
- sendMessage() {
- // 用户输入数据提取 不建议
- // 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);
- this.isComplete = false;
- this.aiplan = '';
- // ai对话实现
- let prompt = `我是一名体重为${this.weight}kg的${this.sex}性,我只有${this.trainingTime}分钟来${this.trainingType},我希望训练强度${this.trainingIntensity}一点,而我想训练的部位为${this.trainingSite}, 一些其他的需求有${this.needs}。 请你作为一名专业的健身教练,根据我提供的信息,为我制定${this.trainingType}计划。`;
- console.log(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;
- if (message?.complete) {
- // 判断message为完成状态,则设置isComplete为完成
- this.isComplete = true;
- }
- });
- }
- }
|