|
@@ -1,11 +1,12 @@
|
|
|
-import { Component } from '@angular/core';
|
|
|
-import { IonHeader, IonToolbar, IonTitle, IonContent, IonItem, IonList, IonSelect, IonSelectOption, IonLabel, IonButton, IonTextarea, AlertController } from '@ionic/angular/standalone';
|
|
|
+import { ChangeDetectorRef, Component } from '@angular/core';
|
|
|
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonItem, IonList, IonSelect, IonSelectOption, IonLabel, IonButton, IonTextarea, AlertController, IonSegment, IonSegmentButton, ModalController } from '@ionic/angular/standalone';
|
|
|
import { ExploreContainerComponent } from '../explore-container/explore-container.component';
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
import { FormsModule } from '@angular/forms'; // 导入 FormsModule
|
|
|
/** 引用:从fmode-ng库引用FmodeChatCompletion类 */
|
|
|
-import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';
|
|
|
+import { ChatPanelOptions, FmChatModalInput, FmodeChat, FmodeChatCompletion, FmodeChatMessage, MarkdownPreviewModule, openChatPanelModal } from 'fmode-ng';
|
|
|
import { Router } from '@angular/router'; // 导入 Router
|
|
|
+import { DalleOptions, ImagineWork } from 'fmode-ng';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-tab3',
|
|
@@ -13,118 +14,165 @@ import { Router } from '@angular/router'; // 导入 Router
|
|
|
styleUrls: ['tab3.page.scss'],
|
|
|
standalone: true,
|
|
|
imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,IonItem,IonList,IonSelect,IonSelectOption,IonButton,CommonModule,IonTextarea,FormsModule,
|
|
|
- MarkdownPreviewModule,],
|
|
|
+ MarkdownPreviewModule,IonSegment,IonSegmentButton,IonLabel,// ASR语音输入模块
|
|
|
+ FmChatModalInput,],
|
|
|
})
|
|
|
export class Tab3Page {
|
|
|
- constructor(private alertController: AlertController, private router: Router) {}
|
|
|
- colors: string[] = [
|
|
|
- '#FF5733', '#33FF57', '#3357FF', '#F1C40F', '#8E44AD',
|
|
|
- '#E74C3C', '#3498DB', '#1ABC9C', '#2ECC71', '#9B59B6',
|
|
|
- '#34495E', '#E67E22', '#F39C12', '#D35400', '#C0392B',
|
|
|
- '#7F8C8D', '#BDC3C7', '#95A5A6', '#FFB6C1', '#FF4500',
|
|
|
- '#FFD700', '#ADFF2F', '#00CED1', '#FF69B4', '#8A2BE2',
|
|
|
- '#A52A2A', '#DEB887', '#5F9EA0', '#4682B4', '#D3D3D3',
|
|
|
- '#FF1493', '#7FFF00', '#FF6347', '#B22222', '#FF8C00',
|
|
|
- '#20B2AA', '#C71585', '#FFDAB9', '#F0E68C', '#FFFACD',
|
|
|
- '#FFE4E1', '#FFF0F5', '#FFF5EE', '#F5F5F5', '#DCDCDC',
|
|
|
- '#708090', '#778899',
|
|
|
- ];
|
|
|
-
|
|
|
- selectedColorFavorite: string = ''; // 第一个颜色选择器的选中颜色
|
|
|
- selectedColorSecondary: string = ''; // 第二个颜色选择器的选中颜色
|
|
|
- showColorPickerFavorite: boolean = false; // 控制第一个颜色选择器的显示
|
|
|
- showColorPickerSecondary: boolean = false; // 控制第二个颜色选择器的显示
|
|
|
-
|
|
|
- selectedSeason: string = ''; // 存储用户选择的季节
|
|
|
- selectedGender: string = ''; // 存储用户选择的性别
|
|
|
- selectedBodyType: string = ''; // 存储用户选择的体型
|
|
|
- selectedSkinTone: string = ''; // 存储用户选择的皮肤色调
|
|
|
- styleDescription: string = ''; // 存储用户的风格描述
|
|
|
- isComplete:boolean = false; // 定义完成状态属性,用来标记是否补全完成
|
|
|
-
|
|
|
- toggleColorPicker(type: string) {
|
|
|
- if (type === 'favorite') {
|
|
|
- this.showColorPickerFavorite = !this.showColorPickerFavorite; // 切换第一个颜色选择器的显示状态
|
|
|
- this.showColorPickerSecondary = false; // 关闭第二个颜色选择器
|
|
|
- } else if (type === 'secondary') {
|
|
|
- this.showColorPickerSecondary = !this.showColorPickerSecondary; // 切换第二个颜色选择器的显示状态
|
|
|
- this.showColorPickerFavorite = false; // 关闭第一个颜色选择器
|
|
|
- }
|
|
|
+ placeholderText: string = "职业:非必填\n喜好:非必填\n天气:非必填\n温度:非必填\n其他需求:显高显瘦?儒雅甜美?等";
|
|
|
+ selectedSegment: string = 'ai-outfit'; // 默认选中的导航项
|
|
|
+ selectedGender: string = ''; // 默认性别
|
|
|
+
|
|
|
+ // 新增变量
|
|
|
+ height: number | null = null; // 身高
|
|
|
+ weight: number | null = null; // 体重
|
|
|
+ age: number | null = null; // 年龄
|
|
|
+ comments: string = ''; // 用户评论
|
|
|
+ // 属性:组件内用于展示消息内容的变量
|
|
|
+ responseMsg:any = ""
|
|
|
+ // 用户输入提示词
|
|
|
+ userPrompt:string = ''
|
|
|
+ isComplete:boolean = false; // 定义完成状态属性,用来标记是否补全完成
|
|
|
+ isGenerating: boolean = false; // 按钮状态
|
|
|
+ imagineWork:ImagineWork|undefined
|
|
|
+ images:Array<string> = []
|
|
|
+ constructor(private alertController: AlertController,private modalCtrl:ModalController,
|
|
|
+ private router:Router, private cdRef:ChangeDetectorRef) { }
|
|
|
+
|
|
|
+ selectSegment(segment: string) {
|
|
|
+ this.selectedSegment = segment; // 更新选中的导航项
|
|
|
}
|
|
|
|
|
|
- selectColor(color: string, type: string) {
|
|
|
- if (type === 'favorite') {
|
|
|
- this.selectedColorFavorite = color; // 更新第一个颜色选择器的选中颜色
|
|
|
- } else if (type === 'secondary') {
|
|
|
- this.selectedColorSecondary = color; // 更新第二个颜色选择器的选中颜色
|
|
|
- }
|
|
|
- this.showColorPickerFavorite = false; // 选择颜色后关闭第一个颜色选择器
|
|
|
- this.showColorPickerSecondary = false; // 选择颜色后关闭第二个颜色选择器
|
|
|
+ isActivated(segment: string): boolean {
|
|
|
+ return this.selectedSegment === segment; // 判断当前导航项是否被激活
|
|
|
}
|
|
|
|
|
|
- // 用户输入提示词
|
|
|
- //userPrompt:string = '当前的季节是'+this.selectedSeason+',该用户性别是'+this.selectedGender+',体型是'+this.selectedBodyType+',皮肤色调是'+this.selectedSkinTone+',最喜欢的颜色是'+this.selectedColorFavorite+',次喜欢的颜色是'+this.selectedColorSecondary+',该用户的风格描述是'+this.styleDescription+',请你作为一名专业的服装穿搭大师,为该用户给出适合的服装搭配建议。'
|
|
|
-
|
|
|
- // 属性:组件内用于展示消息内容的变量
|
|
|
- responseMsg:any = ""
|
|
|
- // 方法:实例化completion对象,传入消息数组,并订阅生成的可观察对象。
|
|
|
- // 用户输入提示词
|
|
|
- userPrompt:string = ''
|
|
|
-
|
|
|
- //评价弹出框
|
|
|
- async presentAlert() {
|
|
|
- const alert = await this.alertController.create({
|
|
|
- header: '希望你对本次AI进行评价',
|
|
|
- buttons: [
|
|
|
- {
|
|
|
- text: '不了',
|
|
|
- role: 'cancel',
|
|
|
- handler: () => {
|
|
|
- console.log('用户选择留在本页面');
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- text: '去评价',
|
|
|
- handler: () => {
|
|
|
- // 假设评价页面的路由是'/评价'
|
|
|
- // 您可以根据实际的路由路径进行调整
|
|
|
-
|
|
|
- this.router.navigate(['/tabs/evaluate']);
|
|
|
-
|
|
|
- }
|
|
|
+ selectGender(gender: string) {
|
|
|
+ this.selectedGender = gender; // 更新选中的性别
|
|
|
+ }
|
|
|
+ async sendMessage(){
|
|
|
+ // 如果正在生成,弹出警告框并返回
|
|
|
+ if (this.isGenerating) {
|
|
|
+ const alert = await this.alertController.create({
|
|
|
+ header: '请等待AI回答完毕后再点击!',
|
|
|
+ buttons: ['确定']
|
|
|
+ });
|
|
|
+ await alert.present();
|
|
|
+ return; // 阻止继续执行
|
|
|
+ }
|
|
|
+ this.isComplete = false; // 重置完成状态
|
|
|
+ this.isGenerating = true; // 开始生成时设置为 true
|
|
|
+ this.userPrompt =`有一位${this.selectedGender}用户,该用户${this.age}岁,身高${this.height}cm,体重${this.weight}kg,该用户的补充说明是
|
|
|
+ ${this.comments},请你作为一名专业的服装穿搭大师并严格按照给定的例子格式,为该用户给出适合的服装搭配建议。
|
|
|
+ 例子:嘿,兄弟,你的信息我收到了,让我来帮你计算一下BMI值,再给你一些穿搭方面的建议吧!
|
|
|
+
|
|
|
+**一、计算BMI值**
|
|
|
+
|
|
|
+BMI是衡量身体状况的一个标准,计算方法是体重除以身高的平方。你的体重是50KG,身高是170CM,所以计算结果为:BMI = 体重 ÷ 身高^² = 50KG ÷ (身高达到肩膀手臂撑起风衣帅气的分界线两小块的分界线的位置。)看起来你的BMI值在正常范围内哦!冬天穿搭可以根据你的喜好来选择啦!
|
|
|
+
|
|
|
+**二、详细穿搭分析**
|
|
|
+
|
|
|
+你身高适中,体重偏轻,选择穿搭时需要注意平衡整体造型,避免显得过于瘦弱。可以选择一些稍微宽松一些的衣物来增添一些层次感。同时,注意色彩的搭配,选择一些深色系的衣服来增加视觉上的厚重感。此外,配饰的选择也很关键,可以选择一些简约的项链、手链等增添时尚感。
|
|
|
+
|
|
|
+**三、穿搭雷点分析**
|
|
|
+
|
|
|
+避免选择过于紧身或者过于宽松的衣服款式,以免显得不够协调。颜色上尽量不要选择过于跳跃的颜色或者过多的颜色搭配,以免显得过于花哨。保持整体造型的简约大方即可。
|
|
|
+
|
|
|
+**四、三套穿搭方案**
|
|
|
+
|
|
|
+方案一:运动风搭配(冬季保暖为主)
|
|
|
+外套:阿迪达斯运动系列羽绒服(保暖又时尚)
|
|
|
+内搭:长袖运动衫(颜色可选黑色或灰色)搭配运动裤或牛仔裤皆可
|
|
|
+鞋子:Nike运动鞋(保暖版)增添时尚感同时保暖十足。整体搭配既舒适又保暖。
|
|
|
+
|
|
|
+方案二:休闲风搭配(日常出行)
|
|
|
+外套:北面羽绒服系列(经典款式)搭配简约款围巾增添时尚感。内搭可以选择一件白色卫衣或者毛衣搭配普通牛仔裤即可。鞋子可以选择休闲鞋或板鞋即可打造出简约时尚的感觉。简约却不失品味是你想要的效果哦!👏
|
|
|
+
|
|
|
+方案三:街头风搭配(逛街约会) 可尝试今年大热的李宁秋冬卫衣系列或国潮品牌的羽绒服系列作为外套。下身搭配潮流一点的牛仔裤和潮鞋就可以打造出自己的风格啦!可以添加一些饰品如帽子等来增加时尚感!帅气满分就是这种感觉!✨当然了也要兼顾自身的舒适感和承受能力来选择适合的搭配哦!上面这三套方案你喜欢吗?如果你有别的需要还可以再告诉我哦!
|
|
|
+ `
|
|
|
+ console.log("开始生成")
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
+ {role:"system",content:""},
|
|
|
+ {role:"user",content:this.userPrompt}
|
|
|
+ ])
|
|
|
+ completion.sendCompletion().subscribe((message: any) => {
|
|
|
+ // 打印消息体
|
|
|
+ console.log(message.content);
|
|
|
+ // 赋值消息内容给组件内属性
|
|
|
+ this.responseMsg = message.content;
|
|
|
+ if (message?.complete) { // 判断message为完成状态,则设置isComplete为完成
|
|
|
+
|
|
|
+ this.isComplete = true;
|
|
|
+ this.isGenerating = false; // 生成完成后设置为 false
|
|
|
+ // 图片生成
|
|
|
+ let PicturePrompt = `描述:${this.responseMsg}\n请你作为一名专业的服装绘制大师,根据描述中的方案一生成对应的服装图片。`
|
|
|
+ let options:DalleOptions = {prompt:PicturePrompt}
|
|
|
+ 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");
|
|
|
}
|
|
|
- ]
|
|
|
- });
|
|
|
+ })
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- await alert.present();
|
|
|
}
|
|
|
- sendMessage(){
|
|
|
- // 每次点击按钮时清空之前的内容
|
|
|
- this.responseMsg = ""; // 清空之前的消息
|
|
|
- this.isComplete = false; // 重置完成状态
|
|
|
|
|
|
- this.userPrompt = '当前的季节是' + this.selectedSeason + ',该用户性别是' + this.selectedGender + ',体型是' + this.selectedBodyType + ',皮肤色调是' + this.selectedSkinTone + ',最喜欢的颜色是' + this.selectedColorFavorite + ',次喜欢的颜色是' + this.selectedColorSecondary + ',该用户的风格描述是' + this.styleDescription + ',请你作为一名专业的服装穿搭大师,为该用户给出适合的服装搭配建议。';
|
|
|
-
|
|
|
- console.log("开始生成");
|
|
|
- let completion = new FmodeChatCompletion([
|
|
|
- { role: "system", content: "" },
|
|
|
- { role: "user", content: this.userPrompt }
|
|
|
- ]);
|
|
|
|
|
|
- completion.sendCompletion().subscribe((message: any) => {
|
|
|
- // 打印消息体
|
|
|
- console.log(message.content);
|
|
|
- // 赋值消息内容给组件内属性
|
|
|
- this.responseMsg = message.content;
|
|
|
- if (message?.complete) { // 判断message为完成状态,则设置isComplete为完成
|
|
|
- this.isComplete = true;
|
|
|
- this.presentAlert(); // 调用弹出框
|
|
|
+openChat(){
|
|
|
+ localStorage.setItem("company","E4KpGvTEto")
|
|
|
+ let options:ChatPanelOptions = {
|
|
|
+ roleId:"2DXJkRsjXK",
|
|
|
+ onChatInit:(chat:FmodeChat)=>{
|
|
|
+ console.log("onChatInit");
|
|
|
+ console.log("预设角色",chat.role);
|
|
|
+ chat.role.set("name","小马");
|
|
|
+ chat.role.set("title","时尚顾问");
|
|
|
+ chat.role.set("desc","一名亲切和蔼的时尚顾问,小马,年龄28岁");
|
|
|
+ chat.role.set("tags",["全科","门诊"]);
|
|
|
+ chat.role.set("avatar","https://nova-cloud.obs.cn-south-1.myhuaweicloud.com/storage/aigc/imagine/Q4Zif7fTbK-0.png")
|
|
|
+ chat.role.set("prompt",`
|
|
|
+#角色设定
|
|
|
+您是一名时尚顾问,名叫晓晓,年龄28岁,热爱时尚,擅长根据用户的需求和个性推荐穿搭方案。您的风格亲切、幽默,旨在帮助用户找到最适合他们的服装搭配。
|
|
|
+
|
|
|
+#对话环节
|
|
|
+0破冰,跟用户打招呼,并引导用户聊穿搭话题,可以慢慢引导,不要太突兀,比如:
|
|
|
+“今天的心情怎么样?”
|
|
|
+1拓展话题
|
|
|
+“你平时喜欢什么样的穿搭风格呢?有没有特别喜欢的颜色或者品牌?”
|
|
|
+“如果有一个场合,你希望我帮你推荐搭配,比如约会、工作或休闲,你会选择哪个呢?”
|
|
|
+“你觉得在穿搭上,最让你困扰的是什么?是搭配技巧还是风格选择呢?”
|
|
|
+“有没有什么服装是你一直想尝试但还没有机会的?我们可以一起聊聊!”
|
|
|
+2引导收尾
|
|
|
+“今天聊得很开心呢!如果你还有其他问题或者想法,随时可以告诉我哦。”
|
|
|
+“如果你觉得今天的聊天已经足够了,我也很乐意下次再和你聊更多时尚的话题!”
|
|
|
+“希望你能找到自己喜欢的穿搭风格,期待下次再见!”`);
|
|
|
+ },
|
|
|
+ onMessage:(chat:FmodeChat,message:FmodeChatMessage)=>{
|
|
|
+ console.log("onMessage",message)
|
|
|
+ let content:any = message?.content
|
|
|
+ if(typeof content == "string"){
|
|
|
+ if(content?.indexOf("[完成]")>-1){
|
|
|
+ console.log("聊天已完成")
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onChatSaved:(chat:FmodeChat)=>{
|
|
|
+ // chat?.chatSession?.id 本次会话的 chatId
|
|
|
+ console.log("onChatSaved",chat,chat?.chatSession,chat?.chatSession?.id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ openChatPanelModal(this.modalCtrl,options)
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
+restoreChat(chatId:string){
|
|
|
+ let options:ChatPanelOptions = {
|
|
|
+ roleId:"2DXJkRsjXK",
|
|
|
+ chatId:chatId
|
|
|
}
|
|
|
- goTestPage(){
|
|
|
- this.router.navigate(['/tabs/test']);}
|
|
|
+ openChatPanelModal(this.modalCtrl,options)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+}
|