MCPcopy Create free account
hub / github.com/WeixiangYAN/ClinicalLab / generate_hospital_guide

Function generate_hospital_guide

code/inference/eval.py:66–143  ·  view source on GitHub ↗
(example)

Source from the content-addressed store, hash-verified

64
65
66def generate_hospital_guide(example):
67 clinical_case_uid = example['clinical_case_uid']
68 language = example['language']
69 clinical_case_summary = example['clinical_case_summary']
70
71 if language == 'zh':
72 patient_information_pattern = r'患者基本信息:([\s\S]*?)主诉:'
73 chief_complaint_pattern = r'主诉:([\s\S]*?)病史:'
74 else:
75 patient_information_pattern = r'Patient Basic Information:([\s\S]*?)Chief Complaint:'
76 chief_complaint_pattern = r'Chief Complaint:([\s\S]*?)Medical History:'
77
78 patient_information_matches = re.search(patient_information_pattern, clinical_case_summary, re.DOTALL)
79 if patient_information_matches:
80 patient_information_content = patient_information_matches.group(1).strip()
81 else:
82 logging.error('### [Failed to extract patient information]')
83 raise Exception('Failed to extract patient information')
84
85 chief_complaint_matches = re.search(chief_complaint_pattern, clinical_case_summary, re.DOTALL)
86 if chief_complaint_matches:
87 chief_complaint_content = chief_complaint_matches.group(1).strip()
88 else:
89 logging.error('### [Failed to extract chief complaint]')
90 raise Exception('Failed to extract chief complain')
91
92 logging.info('===> [hospital guide inference]...')
93 logging.info('### [clinical case uid]: ' + str(clinical_case_uid))
94
95 if language == 'zh':
96 prompt = f'''您是一位经验丰富的医院导诊员,根据患者提供的性别、年龄和症状等信息,请从医院科室列表中选择一个患者最需要前往治疗的科室。
97请确保您的回答只包含选中的一个科室,不要包含多余的内容。
98
99以下是患者提供的信息:
100{patient_information_content + chief_complaint_content}
101
102以下是医院科室列表:
103{clinical_department_zh_list}
104您选中的科室:'''
105 else:
106 prompt = f'''You are an experienced hospital guide. Based on the information provided by the patient, including gender, age, and symptoms, please select a department from the list of hospital departments that the patient needs to visit for treatment most.
107Please ensure that your response includes only one selected department without any additional content.
108
109The following is the patient's information:
110{patient_information_content + chief_complaint_content}
111
112The following is the list of hospital departments:
113{clinical_department_en_list}
114Your selected department:'''
115 prompt_tokens = evaluator.count_tokens(prompt)
116
117 logging.info('### [prompt]: ' + str(prompt))
118 logging.info('### [prompt tokens]: ' + str(prompt_tokens))
119
120 try:
121 response = evaluator.generate_text(prompt)
122
123 logging.info('### [response]: ' + str(response))

Callers 1

mainFunction · 0.85

Calls 3

count_tokensMethod · 0.45
generate_textMethod · 0.45
format_promptMethod · 0.45

Tested by

no test coverage detected