|
@@ -3,13 +3,18 @@ import {
|
|
|
IonButton,
|
|
|
IonCard,
|
|
|
IonCardContent,
|
|
|
+ IonCardHeader,
|
|
|
+ IonCardSubtitle,
|
|
|
+ IonCardTitle,
|
|
|
IonContent,
|
|
|
IonHeader,
|
|
|
IonIcon,
|
|
|
IonItem,
|
|
|
+ IonList,
|
|
|
IonProgressBar,
|
|
|
IonTitle,
|
|
|
IonToolbar,
|
|
|
+ ModalController,
|
|
|
} from '@ionic/angular/standalone';
|
|
|
import { AgentTaskStep } from 'src/app/agent/agent.task';
|
|
|
import { addIcons } from 'ionicons';
|
|
@@ -18,6 +23,8 @@ import {
|
|
|
ellipseOutline,
|
|
|
reloadCircleOutline,
|
|
|
} from 'ionicons/icons';
|
|
|
+import { AgentUserinputComponent } from 'src/app/agent/agent-userinput/agent-userinput.component';
|
|
|
+import { DalleOptions, FmodeChatCompletion, ImagineWork } from 'fmode-ng';
|
|
|
addIcons({ ellipseOutline, checkmarkCircleOutline, reloadCircleOutline });
|
|
|
|
|
|
@Component({
|
|
@@ -33,44 +40,120 @@ addIcons({ ellipseOutline, checkmarkCircleOutline, reloadCircleOutline });
|
|
|
IonContent,
|
|
|
IonItem,
|
|
|
IonCard,
|
|
|
+ IonCardHeader,
|
|
|
+ IonCardTitle,
|
|
|
+ IonCardSubtitle,
|
|
|
IonCardContent,
|
|
|
IonProgressBar,
|
|
|
IonIcon,
|
|
|
+ IonList,
|
|
|
],
|
|
|
})
|
|
|
export class TaskchainPageComponent {
|
|
|
- constructor() {}
|
|
|
+ constructor(private modalCtrl: ModalController) {}
|
|
|
+ // constructor() {}
|
|
|
|
|
|
taskList: AgentTaskStep[] = [];
|
|
|
wait(duration: number = 1000) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
+ return new Promise((resolve) => {
|
|
|
setInterval(() => {
|
|
|
resolve(true);
|
|
|
}, duration);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ // 组件用户输入
|
|
|
+ async userInput(options: { fieldsArray: any }) {
|
|
|
+ const modal = await this.modalCtrl.create({
|
|
|
+ component: AgentUserinputComponent,
|
|
|
+ componentProps: {
|
|
|
+ fieldsArray: options.fieldsArray,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ modal.present();
|
|
|
+ const { data, role } = await modal.onWillDismiss();
|
|
|
+ if (role === 'confirm') {
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建任务集
|
|
|
shareData: any = {};
|
|
|
createTask() {
|
|
|
+ // task1
|
|
|
let task1 = new AgentTaskStep({
|
|
|
title: 'AI扩展更多信息',
|
|
|
shareData: this.shareData,
|
|
|
});
|
|
|
- task1.handle = async () => {
|
|
|
- await this.wait(5000);
|
|
|
- console.log('AI扩展更多信息,执行中...');
|
|
|
- task1.progress = 1;
|
|
|
+ task1.handle = () => {
|
|
|
+ return new Promise(async (resolve) => {
|
|
|
+ // await this.wait(5000);
|
|
|
+ console.log('AI扩展更多信息,执行中...');
|
|
|
+ let userInput = await this.userInput({
|
|
|
+ fieldsArray: [
|
|
|
+ {
|
|
|
+ name: '绘图要求',
|
|
|
+ type: 'text',
|
|
|
+ placeholder: '主题+元素+风格',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '图片类型',
|
|
|
+ type: 'text',
|
|
|
+ placeholder: 'logo/普通图片/海报',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ console.log(userInput);
|
|
|
+ // console.log(userInput['图片类型']);
|
|
|
+
|
|
|
+ // ai生成更详细的内容
|
|
|
+ let PromptTemplate = `请您作为一名专业的美术大家,请根据以下需求给出更详细的补充,用最少的文字表达出来。需求有:${userInput['绘图要求']} + ${userInput['图片类型']}`;
|
|
|
+ console.log(PromptTemplate);
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ task1.progress = 1;
|
|
|
+ resolve(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
+ // task2
|
|
|
let task2 = new AgentTaskStep({
|
|
|
title: 'AI生成图片',
|
|
|
shareData: this.shareData,
|
|
|
});
|
|
|
- task2.handle = async () => {
|
|
|
- await this.wait(3000);
|
|
|
- console.log('AI生成图片,执行中...');
|
|
|
- task2.progress = 1;
|
|
|
+ task2.handle = () => {
|
|
|
+ return new Promise(async (resolve) => {
|
|
|
+ // await this.wait(3000);
|
|
|
+ console.log('AI生成图片,执行中...');
|
|
|
+
|
|
|
+ let imagineWork = new ImagineWork();
|
|
|
+ let PicturePrompt = `${task1.shareData.PictureDescResult}风格,画面不带任何文字。`;
|
|
|
+ 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;
|
|
|
+ resolve(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
+ //taskList
|
|
|
this.taskList = [task1, task2];
|
|
|
this.AngentExecutor(this.taskList);
|
|
|
}
|