(example)
| 296 | |
| 297 | |
| 298 | def 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. |
| 321 | Please ensure that your response is highly concise. |
| 322 | |
| 323 | The following is the given findings: |
| 324 | {findings} |
| 325 | |
| 326 | Your 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 |
no test coverage detected