import { Component, OnInit } from '@angular/core';
import { IonButton, IonContent, IonHeader, IonInput, IonTextarea, IonTitle, IonToolbar } from '@ionic/angular/standalone';
import { FmodeChatCompletion } from 'fmode-ng';

@Component({
  selector: 'app-page-inquiry',
  templateUrl: './page-inquiry.component.html',
  styleUrls: ['./page-inquiry.component.scss'],
  imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton,
    IonTextarea,IonInput
    ],
  standalone: true,
})
export class PageInquiryComponent  implements OnInit {

  ngOnInit() {}

  constructor() {}

  // 用户输入提示词

  keshi:string = "门诊"
  keshiInput(ev:any){
    this.keshi = ev.detail.value;
  }
   userPrompt:string = "请描述您的症状"
  promptInput(ev:any){
    this.userPrompt = ev.detail.value;
  }
  // 属性：组件内用于展示消息内容的变量
  responseMsg:any = ""
  // 方法：实例化completion对象，传入消息数组，并订阅生成的可观察对象。
  sendMessage(){
    console.log("create")

    let PromptTemplate =`您作为一名专业的${this.keshi}医生，请您根据用户描述的症状，给出初步的诊断，并给出一些建议。以下是用户口述：${this.userPrompt}`

    let completion = new FmodeChatCompletion([
      {role:"system",content:""},
      {role:"user",content:PromptTemplate}
    ])
    completion.sendCompletion().subscribe((message:any)=>{
      // 打印消息体
      console.log(message.content)
      // 赋值消息内容给组件内属性
      this.responseMsg = message.content
    })
  }

}
