123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import { Component, OnInit } from '@angular/core';
- import { ChatMessage, TestFmodeChatCompletion } from '../test.chat.completion';
- import { IonicModule } from '@ionic/angular';
- import { CommonModule } from '@angular/common';
- import { FormsModule } from '@angular/forms';
- @Component({
- selector: 'app-page-test-completion',
- templateUrl: './page-test-completion.component.html',
- styleUrls: ['./page-test-completion.component.scss'],
- imports: [IonicModule, CommonModule, FormsModule],
- standalone: true,
- })
- export class PageTestCompletionComponent implements OnInit {
- userDescription: string = '';
- aiResponse: string = '';
- isLoading: boolean = false;
- constructor() { }
- ngOnInit() { return; }
- startConsult() {
- if (!this.userDescription.trim()) {
- console.warn('用户描述不能为空');
- return;
- }
- this.isLoading = true;
- this.aiResponse = ''; // 清空之前的响应
- // 导诊系统提示词
- const diagnosisPrompt = `你是一个专业的医疗导诊助手。
- 请根据患者描述的症状,进行以下分析:
- 1. 可能的疾病方向(列出2-3个最可能的)
- 2. 建议就诊的科室
- 3. 是否需要立即就医的紧急程度评估
- 4. 日常护理建议
- 请用专业但易懂的语言回答,避免直接诊断,而是提供就医指导。
- 结果要求:
- 1.首先,直接给出就诊的科室
- 2.给用户建议
- `;
- const messages: ChatMessage[] = [
- { role: 'system', content: `` },
- { role: 'user', content: diagnosisPrompt+`患者症状描述:${this.userDescription}` }
- ];
- localStorage.setItem("token",'r:9485439b35a9ce34bb95a9f3cfec2e6e'), // 替换为您的实际token
- TestFmodeChatCompletion(
- {
- messages
- },
- (chunk, isLast) => {
- if (isLast) {
- this.isLoading = false;
- console.log('\n对话完成');
- } else {
- this.aiResponse += chunk; // 累积AI返回的内容
- console.log(chunk); // 实时输出内容
- }
- },
- (error) => {
- this.isLoading = false;
- console.error('发生错误:', error.message);
- this.aiResponse = '获取导诊建议时出错,请稍后再试。';
- }
- );
- }
- }
|