|
@@ -1,14 +1,137 @@
|
|
|
import { Component } from '@angular/core';
|
|
|
-import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
|
|
|
+import { IonHeader, IonToolbar, IonTitle, IonContent,IonButton,IonIcon, ModalController, } from '@ionic/angular/standalone';
|
|
|
import { ExploreContainerComponent } from '../explore-container/explore-container.component';
|
|
|
-
|
|
|
+import { AgentTaskStep } from 'src/agent/agent.task';
|
|
|
+import { closeCircleOutline,radioButtonOffOutline,reloadOutline,checkmarkCircleOutline} from 'ionicons/icons';
|
|
|
+import { addIcons } from 'ionicons';
|
|
|
+import { DalleOptions, FmodeChatCompletion, ImagineWork } from 'fmode-ng';
|
|
|
+import { getUserInput } from 'src/agent/agent.input';
|
|
|
+import { startTask } from 'src/agent/agent.start';
|
|
|
+addIcons({radioButtonOffOutline,reloadOutline,checkmarkCircleOutline,closeCircleOutline})
|
|
|
@Component({
|
|
|
selector: 'app-tab3',
|
|
|
templateUrl: 'tab3.page.html',
|
|
|
styleUrls: ['tab3.page.scss'],
|
|
|
standalone: true,
|
|
|
- imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent],
|
|
|
+ imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,IonButton,IonIcon],
|
|
|
})
|
|
|
export class Tab3Page {
|
|
|
- constructor() {}
|
|
|
+ constructor(private modalCtrl:ModalController) {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ taskList:AgentTaskStep[] = []
|
|
|
+
|
|
|
+ wait(duration:number=1000){
|
|
|
+ return new Promise(resolve=>{
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve(true)
|
|
|
+ }, duration);
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ shareData:any = {}
|
|
|
+
|
|
|
+ // 任务:完成故事意境描述及图像绘制
|
|
|
+ doPoemTask(){
|
|
|
+ let task1 = new AgentTaskStep({title:"意境分析",shareData:this.shareData});
|
|
|
+ task1.handle=async()=>{
|
|
|
+ //获取用户输入的诗词
|
|
|
+ let userInput=await getUserInput(this.modalCtrl,{filedsArray:[{name:"诗文内容",type:"text",desc:"诗文内容"}]});
|
|
|
+ console.log("已获取用户输入:",userInput)
|
|
|
+ console.log("已获取诗文内容:",userInput.poem)
|
|
|
+
|
|
|
+ // 文本生成
|
|
|
+ let PromptTemplate = `您是一名专业的美术画家,请您根据古诗文的内容,将其描述的画面、场景、人物、物品等用最简短的语言表达,直接写出画面,并且以中国的古风意境为主
|
|
|
+ 诗文如下:${userInput.poem}`
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
+ {role:"system",content:""},
|
|
|
+ {role:"user",content:PromptTemplate}
|
|
|
+ ])
|
|
|
+ completion.sendCompletion().subscribe((message:any)=>{
|
|
|
+ // 打印消息体
|
|
|
+ console.log(message.content)
|
|
|
+ // 赋值消息内容给组件内属性
|
|
|
+ this.shareData.PictureDescResult = message.content
|
|
|
+ if(message?.complete){ // 判断message为完成状态,则设置isComplete为完成
|
|
|
+ task1.progress=1
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // await this.wait(1000);
|
|
|
+ // console.log("意境分析")
|
|
|
+ }
|
|
|
+
|
|
|
+ let task2=new AgentTaskStep({title:"意境绘制",shareData:this.shareData});
|
|
|
+ task2.handle=async()=>{
|
|
|
+ await this.wait(10000);
|
|
|
+ //let userInput=await getUserInput(this.modalCtrl,{filedsArray:[{name:"绘图要求",type:"text",desc:"画风、构图等"}]});
|
|
|
+ // console.log("已获取用户输入:",userInput)
|
|
|
+ // console.log("已获取诗文内容:",userInput.poem)
|
|
|
+ console.log("意境绘制:执行过程");
|
|
|
+ let imagineWork = new ImagineWork();
|
|
|
+
|
|
|
+ // 图片生成
|
|
|
+ let PicturePrompt = `${this.shareData.PictureDescResult}\n风格:中国古风。画面不带任何文字。`
|
|
|
+ let options:DalleOptions = {prompt:PicturePrompt}
|
|
|
+ imagineWork?.draw(options).subscribe((work:any)=>{
|
|
|
+ console.log("imagineWork",work?.toJSON())
|
|
|
+ console.log("images",work?.get("images"))
|
|
|
+ if(work?.get("images")?.length){
|
|
|
+ this.shareData.images = work?.get("images");
|
|
|
+ task2.progress=1
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 定义任务集
|
|
|
+ let PoemTaskList = [task1,task2]
|
|
|
+ // 传递给显示组件
|
|
|
+ this.taskList = PoemTaskList
|
|
|
+ // 开始执行任务
|
|
|
+ startTask(PoemTaskList)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 任务集:医疗问诊任务集 完成一次完整的门诊服务
|
|
|
+ doInqueryTask(){
|
|
|
+ let task1 = new AgentTaskStep({title:"导诊",shareData:this.shareData});
|
|
|
+ task1.handle=async()=>{
|
|
|
+ await this.wait(1000)
|
|
|
+ console.log("导诊:执行过程")
|
|
|
+ task1.progress=1
|
|
|
+ }
|
|
|
+ let task2 = new AgentTaskStep({title:"问诊",shareData:this.shareData});
|
|
|
+ task2.handle=async()=>{
|
|
|
+ await this.wait(1000)
|
|
|
+ console.log("问诊:执行过程")
|
|
|
+ task2.progress=1
|
|
|
+ }
|
|
|
+ let task3 = new AgentTaskStep({title:"初诊",shareData:this.shareData});
|
|
|
+ task3.handle=async()=>{
|
|
|
+ await this.wait(1000)
|
|
|
+ console.log("初诊:执行过程")
|
|
|
+ task3.progress=1
|
|
|
+ }
|
|
|
+ let task4 = new AgentTaskStep({title:"检验",shareData:this.shareData});
|
|
|
+ task4.handle=async()=>{
|
|
|
+ await this.wait(1000)
|
|
|
+ console.log("检验:执行过程")
|
|
|
+ task4.progress=1
|
|
|
+ }
|
|
|
+ let task5 = new AgentTaskStep({title:"处方",shareData:this.shareData});
|
|
|
+ task5.handle=async()=>{
|
|
|
+ await this.wait(1000)
|
|
|
+ console.log("处方:执行过程")
|
|
|
+ task5.progress=1
|
|
|
+ }
|
|
|
+ // 定义任务集
|
|
|
+ let InquireServiceTaskList = [
|
|
|
+ task1,task2,task3,task4,task5
|
|
|
+ ]
|
|
|
+ // 传递给显示组件
|
|
|
+ this.taskList = InquireServiceTaskList
|
|
|
+ // 开始执行任务
|
|
|
+ startTask(InquireServiceTaskList)
|
|
|
+ }
|
|
|
+
|
|
|
}
|