3.inquiry-user-answer.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { AgentTaskStep } from 'src/app/agent/agent.task';
  2. import { getUserInput } from 'src/app/agent/agent.input';
  3. import { ModalController } from '@ionic/angular/standalone';
  4. import { FmodeChatCompletion } from 'fmode-ng';
  5. import { extactAndParseJsonFromString } from 'src/app/agent/agent.json';
  6. export function TaskInqueryUserAnswer(options: {
  7. modalCtrl: ModalController
  8. shareData: any
  9. }
  10. ): AgentTaskStep {
  11. /**
  12. shareData.userStory // 已经拥有的医生主动询问
  13. {
  14. "questionList": [
  15. {
  16. "title": "头痛的性质",
  17. "desc": "请问您的偏头痛是怎样的感觉?是刺痛、跳动还是压迫感?"
  18. },
  19. ]
  20. }
  21. */
  22. let task1 = new AgentTaskStep({ title: "诊断:患者回答具体内容后,医生给出诊断结果", shareData: options.shareData })
  23. task1.handle = () => {
  24. return new Promise(async (resolve, reject) => {
  25. // 获取用户输入的问题清单
  26. let questionList = options.shareData.userStory.questionList.map((item: any) => { return { name: item.title, desc: item.desc, type: "text" } })
  27. let userInputResult = await getUserInput(options.modalCtrl, { fieldsArray: questionList });
  28. console.log(userInputResult)
  29. //正好是他的标题
  30. questionList.forEach((question: any) => {
  31. question.answer = userInputResult[question.name]
  32. })
  33. // 文本生成
  34. let qaContent = options.shareData.userStory.questionList.map((item: any) => `医生问:${item.title},${item.desc}\n患者答:${item.answer || "没回答"}`).join("\n")
  35. let PromptTemplate = `您是一名专业的健身医疗主任医生,根据具体的询问,给出初步诊断。
  36. 症状口述:${options.shareData.userStory['症状口述']}
  37. 具体询问:${qaContent}
  38. 结果以JSON格式表示:
  39. 症状名称为具体的症状,症状描述为用户的感受,持续时间若没有直接说,可以写近期即可。
  40. {
  41. "title":"病例标题",
  42. "desc":"病情概括",
  43. "content":"给出完整的治疗方案和建议"
  44. }
  45. `
  46. let completion = new FmodeChatCompletion([
  47. { role: "system", content: "" },
  48. { role: "user", content: PromptTemplate }
  49. ])
  50. completion.sendCompletion().subscribe((message: any) => {
  51. if (task1.progress < 0.5) {
  52. task1.progress += 0.1
  53. }
  54. if (task1.progress >= 0.5 && task1.progress <= 0.9) {
  55. task1.progress += 0.01
  56. }
  57. if (task1.progress >= 0.9) {
  58. task1.progress += 0.001
  59. }
  60. // 打印消息体
  61. console.log(message.content)
  62. // 赋值消息内容给组件内属性
  63. if (message.complete) { // 判断message为完成状态,则设置isComplete为完成
  64. options.shareData.diagResult = extactAndParseJsonFromString(message.content)
  65. task1.progress = 1
  66. resolve(true)
  67. }
  68. })
  69. })
  70. }
  71. return task1
  72. }
  73. const TestShareData = {
  74. userStory: {
  75. "keshi": "神经内科",
  76. "sympList": [
  77. {
  78. "title": "偏头疼",
  79. "desc": "已经持续了2天了",
  80. "duration": "2天"
  81. },
  82. {
  83. "title": "发冷",
  84. "desc": "感觉已经有一天",
  85. "duration": "1天"
  86. }
  87. ],
  88. "症状口述": "偏头疼已经持续了2天了,发冷感觉已经有一天。",
  89. "questionList": [
  90. {
  91. "title": "头痛的性质",
  92. "desc": "请描述您的头痛是搏动性、压迫性还是其他类型?",
  93. "answer": "压迫性头疼"
  94. },
  95. {
  96. "title": "头痛的部位",
  97. "desc": "您的头痛主要集中在头部的哪个区域?",
  98. "answer": "左侧头疼"
  99. },
  100. {
  101. "title": "伴随症状",
  102. "desc": "除了头痛和发冷,您还有其他的症状吗?例如恶心、呕吐、视力模糊或对光敏感等?",
  103. "answer": "有点恶心但是没有呕吐"
  104. },
  105. {
  106. "title": "发冷的性质",
  107. "desc": "您感到发冷时是否伴随有发热、出汗或其他症状?",
  108. "answer": "没有"
  109. },
  110. {
  111. "title": "既往病史",
  112. "desc": "您是否有偏头痛或其他头痛的病史?",
  113. "answer": "没有"
  114. },
  115. {
  116. "title": "生活习惯",
  117. "desc": "您最近的生活习惯是否有变化?例如睡眠不足、压力增大或饮食不规律?",
  118. "answer": "经常熬夜,学习压力大"
  119. },
  120. {
  121. "title": "药物使用",
  122. "desc": "您是否有服用任何药物来缓解头痛或其他症状?",
  123. "answer": "没有"
  124. },
  125. {
  126. "title": "家族病史",
  127. "desc": "您的家族中是否有人有类似的头痛或神经系统疾病史?",
  128. "answer": "没有"
  129. },
  130. {
  131. "title": "过敏史",
  132. "desc": "您是否有药物或其他物质的过敏史?",
  133. "answer": "没有"
  134. }
  135. ]
  136. }
  137. }