|
@@ -0,0 +1,67 @@
|
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
|
+import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
|
|
|
|
+import { IonTextarea, IonButton } from "@ionic/angular/standalone";
|
|
|
|
+import { DalleOptions, FmodeChatCompletion, ImagineWork } from 'fmode-ng';
|
|
|
|
+
|
|
|
|
+@Component({
|
|
|
|
+ selector: 'app-hotel-picture',
|
|
|
|
+ templateUrl: './hotel-picture.component.html',
|
|
|
|
+ styleUrls: ['./hotel-picture.component.scss'],
|
|
|
|
+ standalone: true,
|
|
|
|
+ imports: [
|
|
|
|
+ IonHeader, IonToolbar, IonTitle, IonContent,
|
|
|
|
+ IonButton,
|
|
|
|
+ IonTextarea
|
|
|
|
+ ],
|
|
|
|
+})
|
|
|
|
+export class HotelPictureComponent 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 PromptTemple = `您是一名专业的美术画家,请您根据用户描述的房间类型和需求直接写出画面,并且以写实的风格为主。
|
|
|
|
+ 房间描述如下:
|
|
|
|
+ ${this.userPrompt}
|
|
|
|
+ `
|
|
|
|
+
|
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
|
+ {role:"system",content:""},
|
|
|
|
+ {role:"user",content:PromptTemple}
|
|
|
|
+ ])
|
|
|
|
+ completion.sendCompletion().subscribe((message:any)=>{
|
|
|
|
+ // 打印消息体
|
|
|
|
+ console.log(message.content)
|
|
|
|
+ // 赋值消息内容给组件内属性
|
|
|
|
+ this.PictureDescResult = message.content
|
|
|
|
+ if(message?.complete){
|
|
|
|
+ let picturePrompt = `${this.PictureDescResult}`//画面描述结果
|
|
|
|
+ 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() {}
|
|
|
|
+
|
|
|
|
+}
|