|
@@ -0,0 +1,65 @@
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
|
|
|
+import { IonTextarea, IonButton,IonInput } from "@ionic/angular/standalone";
|
|
|
+import { DalleOptions, ImagineWork,FmodeChatCompletion } from 'fmode-ng';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-consult-picture',
|
|
|
+ templateUrl: './consult-picture.component.html',
|
|
|
+ styleUrls: ['./consult-picture.component.scss'],
|
|
|
+ standalone: true,
|
|
|
+ imports: [
|
|
|
+ IonHeader, IonToolbar, IonTitle, IonContent,
|
|
|
+ IonButton,IonInput,
|
|
|
+ IonTextarea
|
|
|
+ ],
|
|
|
+})
|
|
|
+export class ConsultPictureComponent implements OnInit {
|
|
|
+
|
|
|
+ userPrompt:string = "一个智能咨询师机器人头像,要求小巧可爱,比例协调,圆润的线条,温和的主色调,眼睛设计成半圆形,面带微笑,加点耳机或者帽子装饰,简约的机器人线条,要有手有脚,给用户一种交互的感觉,加点语气泡泡"
|
|
|
+ promptInput(ev:any){
|
|
|
+ this.userPrompt = ev.detail.value;
|
|
|
+ }
|
|
|
+ imagineWork:ImagineWork|undefined
|
|
|
+ images:Array<string> = []
|
|
|
+ constructor(
|
|
|
+ ){
|
|
|
+ // 示例任务,自己生成图片后请存储新的ID
|
|
|
+ this.imagineWork = new ImagineWork("lpJGiFwWeA");
|
|
|
+ this.imagineWork.fetchTask().then(work=>{
|
|
|
+ this.images = this.imagineWork?.images || [];
|
|
|
+ })
|
|
|
+ }
|
|
|
+ PictureDescResult:string = `` // 画面描述结果
|
|
|
+ async createImage(){
|
|
|
+ this.imagineWork = new ImagineWork();
|
|
|
+ //文本生成
|
|
|
+ let PromptTemplate = `您是一名专业的美术画家,请您根据我描述的要求,将要求更加细致的描述出来
|
|
|
+ 要求如下:
|
|
|
+ ${this.userPrompt}
|
|
|
+ `
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
+ {role:"system",content:""},
|
|
|
+ {role:"user",content:PromptTemplate}
|
|
|
+ ])
|
|
|
+ completion.sendCompletion().subscribe((message:any)=>{
|
|
|
+ // 打印消息体
|
|
|
+ console.log(message.content)
|
|
|
+ // 赋值消息内容给组件内属性
|
|
|
+ this.PictureDescResult = message.content
|
|
|
+ if(message?.complete){ // 判断message为完成状态,则设置isComplete为完成
|
|
|
+ //图片生成
|
|
|
+ let options:DalleOptions = {prompt:this.userPrompt}
|
|
|
+ this.imagineWork?.draw(options).subscribe(work=>{
|
|
|
+ console.log("imagineWork",work?.toJSON())
|
|
|
+ console.log("images",work?.get("images"))
|
|
|
+ if(work?.get("images")?.length){
|
|
|
+ this.images = work?.get("images");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+ ngOnInit() {
|
|
|
+ }
|
|
|
+}
|