|
@@ -1,9 +1,9 @@
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
import { Router } from '@angular/router';
|
|
import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
-import { IonHeader, IonToolbar, IonTitle, IonContent, IonButton,IonIcon, ModalController, IonTextarea, IonInput, IonCard, IonCardHeader, IonCardTitle, IonThumbnail, IonCardContent, IonCardSubtitle, IonItem, IonList, IonLabel, IonAvatar, IonSelect, IonSelectOption } from '@ionic/angular/standalone';
|
|
|
|
|
|
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonButton,IonIcon, ModalController, IonTextarea, IonInput, IonCard, IonCardHeader, IonCardTitle, IonThumbnail, IonCardContent, IonCardSubtitle, IonItem, IonList, IonLabel, IonAvatar, IonSelect, IonSelectOption, AlertController, IonButtons, IonProgressBar, IonText } from '@ionic/angular/standalone';
|
|
import { CommonModule } from '@angular/common';
|
|
import { CommonModule } from '@angular/common';
|
|
-import { AvatarModule } from 'fmode-ng';
|
|
|
|
|
|
+import { AvatarModule, ChatPanelOptions, DalleOptions, FmodeChat, FmodeChatCompletion, FmodeChatMessage, ImagineWork, openChatPanelModal } from 'fmode-ng';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
@@ -15,7 +15,8 @@ import { AvatarModule } from 'fmode-ng';
|
|
IonHeader, IonToolbar, IonTitle, IonContent, IonButton,IonTextarea,IonInput,
|
|
IonHeader, IonToolbar, IonTitle, IonContent, IonButton,IonTextarea,IonInput,
|
|
IonIcon,IonCard,IonCardHeader,IonCardTitle,
|
|
IonIcon,IonCard,IonCardHeader,IonCardTitle,
|
|
IonCardSubtitle,IonCardContent, IonThumbnail, IonItem,IonList,CommonModule,IonLabel,
|
|
IonCardSubtitle,IonCardContent, IonThumbnail, IonItem,IonList,CommonModule,IonLabel,
|
|
- IonAvatar, IonSelect, IonSelectOption
|
|
|
|
|
|
+ IonAvatar, IonSelect, IonSelectOption,IonButtons,IonProgressBar,
|
|
|
|
+ IonText, IonCardHeader, IonCardSubtitle,
|
|
],
|
|
],
|
|
})
|
|
})
|
|
export class PageCreateAgentComponent implements OnInit {
|
|
export class PageCreateAgentComponent implements OnInit {
|
|
@@ -23,11 +24,21 @@ export class PageCreateAgentComponent implements OnInit {
|
|
currentUser: CloudUser;
|
|
currentUser: CloudUser;
|
|
constructor(
|
|
constructor(
|
|
private modalCtrl:ModalController,
|
|
private modalCtrl:ModalController,
|
|
- private router:Router
|
|
|
|
|
|
+ private router:Router,
|
|
|
|
+ private alertController: AlertController
|
|
) {
|
|
) {
|
|
- this.currentUser = new CloudUser();
|
|
|
|
|
|
+ this.currentUser = new CloudUser();
|
|
|
|
+ // 示例任务,自己生成图片后请存储新的ID
|
|
|
|
+ this.imagineWork = new ImagineWork("");
|
|
|
|
+ this.imagineWork.fetchTask().then(work=>{
|
|
|
|
+ if(work){
|
|
|
|
+ this.imagineWork.id = work.id
|
|
|
|
+ }
|
|
|
|
+ this.images = this.imagineWork?.images || '../../assets/image/头像示例.png';
|
|
|
|
+ })
|
|
|
|
+ this.loadAgentData()
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ images:Array<string> = []
|
|
back:string = "<";
|
|
back:string = "<";
|
|
|
|
|
|
backhome() {
|
|
backhome() {
|
|
@@ -57,20 +68,27 @@ export class PageCreateAgentComponent implements OnInit {
|
|
genderDismiss(){
|
|
genderDismiss(){
|
|
|
|
|
|
}
|
|
}
|
|
- keshi: string = 'male'
|
|
|
|
- keshiChange(e:any) {
|
|
|
|
- console.log('ionChange fired with value: ' + e.detail.value);
|
|
|
|
- this.keshi = e.detail.value;
|
|
|
|
- }
|
|
|
|
- keshiCancel(){
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- keshiDismiss(){
|
|
|
|
-
|
|
|
|
|
|
+ // 描述
|
|
|
|
+ desc: string = ''
|
|
|
|
+ descInput(e:any) {
|
|
|
|
+ this.desc = e.detail.value;
|
|
|
|
+ console.log(this.desc);
|
|
}
|
|
}
|
|
|
|
+ imagineWork:ImagineWork
|
|
|
|
+ PictureDescResult:string = `` // 画面描述结果
|
|
|
|
|
|
- desc: string = ''
|
|
|
|
- createAgent() {
|
|
|
|
|
|
+ // 创建医生
|
|
|
|
+ async createAgent() {
|
|
|
|
+ const alert = await this.alertController.create({
|
|
|
|
+ header: '温馨提示',
|
|
|
|
+ subHeader: 'Tips',
|
|
|
|
+ message: '把信息填写完整哦~',
|
|
|
|
+ buttons: ['好的'],
|
|
|
|
+ });
|
|
|
|
+ if (this.name == '' || this.age == 0 || this.gender == '' || this.desc == '') {
|
|
|
|
+ await alert.present();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
localStorage.setItem("company","E4KpGvTEto")
|
|
localStorage.setItem("company","E4KpGvTEto")
|
|
|
|
|
|
let consult = new CloudObject("DoctorAgent")
|
|
let consult = new CloudObject("DoctorAgent")
|
|
@@ -83,15 +101,162 @@ export class PageCreateAgentComponent implements OnInit {
|
|
if(this.currentUser?.id){
|
|
if(this.currentUser?.id){
|
|
ACL[this.currentUser?.id] = {read:true,write:true}
|
|
ACL[this.currentUser?.id] = {read:true,write:true}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ this.imagineWork = new ImagineWork();
|
|
|
|
+ // 文本生成
|
|
|
|
+ let PromptTemplate = `您是一名专业的美术画家,擅长画各类型头像图,请您根据下面提供的需求内容,将其描述的画面、场景、人物、物品等用最简短的语言表达,直接写出画面,
|
|
|
|
+ 需求如下:
|
|
|
|
+ ${this.name},${this.age}岁,${this.gender},描述:${this.desc}
|
|
|
|
+ `
|
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
|
+ {role:"system",content:""},
|
|
|
|
+ {role:"user",content:PromptTemplate}
|
|
|
|
+ ])
|
|
|
|
+ let avatar = ""
|
|
|
|
+ completion.sendCompletion().subscribe((message:any)=>{
|
|
|
|
+ // 打印消息体
|
|
|
|
+ console.log(message.content)
|
|
|
|
+ // 赋值消息内容给组件内属性
|
|
|
|
+ this.PictureDescResult = message.content
|
|
|
|
+ if(message?.complete){ // 判断message为完成状态,则设置isComplete为完成
|
|
|
|
+ // 图片生成
|
|
|
|
+ let PicturePrompt = `${this.PictureDescResult}\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){
|
|
|
|
+ avatar = work?.get("images")[0];
|
|
|
|
+ console.log(work?.get("images"));
|
|
|
|
+ console.log("work",work);
|
|
|
|
+ console.log("里面的avatar",avatar);
|
|
|
|
+ consult.set({
|
|
|
|
+ avatar:`${avatar}`,
|
|
|
|
+ name:`${this.name}`,
|
|
|
|
+ age:`${this.age}`,
|
|
|
|
+ gender:`${this.gender}`,
|
|
|
|
+ desc:`${this.desc}`,
|
|
|
|
+ user:this.currentUser.toPointer(),
|
|
|
|
+ ACL:ACL,
|
|
|
|
+ })
|
|
|
|
+ consult.save();
|
|
|
|
+ console.log(consult);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ console.log("外面的avatar",avatar);
|
|
|
|
+ if (avatar.length){ // 暂时不能创建头像
|
|
|
|
+ // 保存医生
|
|
|
|
+ consult.set({
|
|
|
|
+ avatar:`${avatar}`,
|
|
|
|
+ name:`${this.name}`,
|
|
|
|
+ age:`${this.age}`,
|
|
|
|
+ gender:`${this.gender}`,
|
|
|
|
+ desc:`${this.desc}`,
|
|
|
|
+ user:this.currentUser.toPointer(),
|
|
|
|
+ ACL:ACL,
|
|
|
|
+ })
|
|
|
|
+ consult.save();
|
|
|
|
+ console.log(consult);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ agentList: Array<CloudObject> = [];
|
|
|
|
+ async loadAgentData() {
|
|
|
|
+ let query = new CloudQuery("DoctorAgent")
|
|
|
|
+ this.agentList = await query.find()
|
|
|
|
+ console.log(this.agentList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ openInquiry(doctor:CloudObject){
|
|
|
|
+ // 验证用户登录
|
|
|
|
+ let currentUser = new CloudUser();
|
|
|
|
+ let userPrompt = ``
|
|
|
|
+ if(currentUser?.get("realname")){
|
|
|
|
+ userPrompt += `当前来访的患者,姓名:${currentUser?.get("realname")}`
|
|
|
|
+ }
|
|
|
|
+ if(currentUser?.get("gender")){
|
|
|
|
+ userPrompt += `,性别:${currentUser?.get("gender")}`
|
|
|
|
+ }
|
|
|
|
+ if(currentUser?.get("age")){
|
|
|
|
+ userPrompt += `,年龄:${currentUser?.get("age")}`
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ localStorage.setItem("company","E4KpGvTEto")
|
|
|
|
+
|
|
|
|
+ let consult = new CloudObject("Consultation")
|
|
|
|
+ let now = new Date();
|
|
|
|
+ let dateStr = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()}`
|
|
|
|
+ // 对象权限的精确指定
|
|
|
|
+ let ACL:any = {
|
|
|
|
+ "*":{read:true,write:true}
|
|
|
|
+ }
|
|
|
|
+ if(currentUser?.id){
|
|
|
|
+ ACL[currentUser?.id] = {read:true,write:true}
|
|
|
|
+ }
|
|
consult.set({
|
|
consult.set({
|
|
- avatar:``,
|
|
|
|
- name:`${this.name}`,
|
|
|
|
- age:`${this.age}`,
|
|
|
|
- gender:`${this.gender}`,
|
|
|
|
- desc:`${this.desc}`,
|
|
|
|
- user:this.currentUser.toPointer(),
|
|
|
|
|
|
+ title:`门诊记录${dateStr}-${doctor?.get("name")}`,
|
|
|
|
+ doctor:doctor.toPointer(),
|
|
|
|
+ user:currentUser.toPointer(),
|
|
ACL:ACL
|
|
ACL:ACL
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+ let options:ChatPanelOptions = {
|
|
|
|
+ roleId:"2DXJkRsjXK",
|
|
|
|
+ onChatInit:(chat:FmodeChat)=>{
|
|
|
|
+ console.log("onChatInit");
|
|
|
|
+ console.log("预设角色",chat.role);
|
|
|
|
+ chat.role.set("name",doctor?.get("name"));
|
|
|
|
+ chat.role.set("desc",doctor?.get("desc"));
|
|
|
|
+ chat.role.set("avatar",doctor?.get("avatar") || "../../assets/image/doctor7.png")
|
|
|
|
+ chat.role.set("prompt",`
|
|
|
|
+# 角色设定
|
|
|
|
+您是${doctor?.get("name")},${doctor?.get("desc")},年龄${doctor?.get("age")}岁,需要完成一次完整的门诊服务。
|
|
|
|
+
|
|
|
|
+# 对话环节
|
|
|
|
+0.导诊(根据用户基本情况,引导挂号合适的科室)
|
|
|
|
+1.预设的问询方式(根据不同症状来问询具体的情况)
|
|
|
|
+- 打招呼,以用户自述为主
|
|
|
|
+- 当信息充足时候,确认用户症状对应的科室,并进入下一个环节
|
|
|
|
+2.拓展的问询细节
|
|
|
|
+例如:用户反映呼吸不畅,拓展出:是否咳嗽;是否感觉痛或者痒等其他需要的问题。
|
|
|
|
+- 当问询细节补充完成后进入下一个环节
|
|
|
|
+3.初步的诊断结果,并且同时列出检查检验项目
|
|
|
|
+初步诊断:确定需要有哪些进一步检查
|
|
|
|
+检查检验:获取医学客观数据
|
|
|
|
+- 等待用户提交客观数据,进入下一阶段
|
|
|
|
+4.给出诊断方案并给出处方
|
|
|
|
+- 完成处方时,请在消息结尾附带: [处方完成]
|
|
|
|
+
|
|
|
|
+# 开始话语
|
|
|
|
+当您准备好了,可以以一个医生的身份,向来访的用户打招呼。
|
|
|
|
+${userPrompt}
|
|
|
|
+`);
|
|
|
|
+ },
|
|
|
|
+ onMessage:(chat:FmodeChat,message:FmodeChatMessage)=>{
|
|
|
|
+ console.log("onMessage",message)
|
|
|
|
+ let content:any = message?.content
|
|
|
|
+ if(typeof content == "string"){
|
|
|
|
+ if(content?.indexOf("[处方完成]")>-1){
|
|
|
|
+ console.log("门诊已完成")
|
|
|
|
+ consult.set({
|
|
|
|
+ content:content // 处方内容
|
|
|
|
+ })
|
|
|
|
+ consult.save();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ onChatSaved:(chat:FmodeChat)=>{
|
|
|
|
+ // chat?.chatSession?.id 本次会话的 chatId
|
|
|
|
+ console.log("onChatSaved",chat,chat?.chatSession,chat?.chatSession?.id)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ openChatPanelModal(this.modalCtrl,options)
|
|
|
|
+ }
|
|
|
|
+ deleteAgent(agent:CloudObject){
|
|
|
|
+ console.log("删除了",agent);
|
|
}
|
|
}
|
|
}
|
|
}
|