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

Function generate_imaging_diagnosis

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

Source from the content-addressed store, hash-verified

296
297
298def generate_imaging_diagnosis(example):
299 clinical_case_uid = example['clinical_case_uid']
300 language = example['language']
301 imageological_examination = example['imageological_examination']
302
303 logging.info('===> [imaging diagnosis inference]...')
304 logging.info('### [clinical case uid]: ' + str(clinical_case_uid))
305
306 if isinstance(imageological_examination, dict):
307 for imageological_examination_part_feature in imageological_examination.keys():
308 findings = imageological_examination[imageological_examination_part_feature]['findings']
309 if language == 'zh':
310 imageological_examination_part_name = imageological_examination_part_feature_to_name_zh_dict[imageological_examination_part_feature]
311 prompt = f'''您是一位经验丰富的放射科医生,根据给定的{imageological_examination_part_name}检查报告中的影像所见部分,请分析并分条列出专业的影像诊断。
312请确保您的回答高度简洁。
313
314以下是给定的影像所见:
315{findings}
316
317您提供的影像诊断:'''
318 else:
319 imageological_examination_part_name = imageological_examination_part_feature_to_name_en_dict[imageological_examination_part_feature]
320 prompt = f'''You are an experienced radiologist. Based on the findings section of the given {imageological_examination_part_name} examination report, please analyze and list professional impression.
321Please ensure that your response is highly concise.
322
323The following is the given findings:
324{findings}
325
326Your impression:'''
327 prompt_tokens = evaluator.count_tokens(prompt)
328
329 logging.info('### [prompt]: ' + str(prompt))
330 logging.info('### [prompt tokens]: ' + str(prompt_tokens))
331
332 try:
333 response = evaluator.generate_text(prompt)
334
335 logging.info('### [response]: ' + str(response))
336
337 if response is None:
338 response = ''
339 response_tokens = 0
340 else:
341 response_tokens = evaluator.count_tokens(response)
342 total_tokens = prompt_tokens + response_tokens
343
344 logging.info('### [response tokens]: ' + str(response_tokens))
345 logging.info('### [total tokens]: ' + str(total_tokens))
346
347 except Exception as e:
348 response = ''
349
350 logging.error('### [Failed to generate text]: ' + e.__str__())
351
352 imageological_examination[imageological_examination_part_feature]['prompt_impression'] = str(evaluator.format_prompt(prompt))
353 imageological_examination[imageological_examination_part_feature]['predicted_impression'] = response
354
355 return example

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