Moved system and welcome messages to be together
Browse files
app.py
CHANGED
|
@@ -110,31 +110,6 @@ def chat_with_model(messages, pid):
|
|
| 110 |
pad_id = current_tokenizer.pad_token_id or current_tokenizer.unk_token_id or 0
|
| 111 |
eos_id = current_tokenizer.eos_token_id
|
| 112 |
|
| 113 |
-
# Build system context
|
| 114 |
-
system_messages = [
|
| 115 |
-
{
|
| 116 |
-
"role": "system",
|
| 117 |
-
"content": (
|
| 118 |
-
"You are a radiologist's companion, here to answer questions about the patient and assist in the diagnosis if asked to do so. "
|
| 119 |
-
"You are able to call specialized tools. "
|
| 120 |
-
"At the moment, you have one tool available: an organ segmentation algorithm for abdominal CTs.\n\n"
|
| 121 |
-
"If the user requests an organ segmentation, output a JSON object in this structure:\n"
|
| 122 |
-
"{\n"
|
| 123 |
-
" \"function\": \"segment_organ\",\n"
|
| 124 |
-
" \"arguments\": {\n"
|
| 125 |
-
" \"scan_path\": \"<path_to_ct_scan>\",\n"
|
| 126 |
-
" \"organ\": \"<organ_name>\"\n"
|
| 127 |
-
" }\n"
|
| 128 |
-
"}\n\n"
|
| 129 |
-
"Once you call the function, the app will execute it and return the result."
|
| 130 |
-
)
|
| 131 |
-
},
|
| 132 |
-
{
|
| 133 |
-
"role": "system",
|
| 134 |
-
"content": f"Patient Information:\nName: {patient_name.value}\nAge: {patient_age.value}\nID: {patient_id.value}\nNotes: {patient_notes.value}"
|
| 135 |
-
}
|
| 136 |
-
]
|
| 137 |
-
|
| 138 |
# FULL conversation
|
| 139 |
full_messages = system_messages + messages
|
| 140 |
|
|
@@ -284,21 +259,46 @@ def load_patient_conversation(patient_key):
|
|
| 284 |
patient_id_val = patient_db[patient_key]["id"]
|
| 285 |
history = patient_conversations.get(patient_id_val, [])
|
| 286 |
if not history:
|
| 287 |
-
|
| 288 |
-
|
|
|
|
| 289 |
"content": (
|
| 290 |
-
"
|
| 291 |
-
"You
|
| 292 |
-
"
|
| 293 |
-
"
|
| 294 |
-
"
|
| 295 |
-
"
|
| 296 |
-
"
|
| 297 |
-
"
|
| 298 |
-
"
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
return history
|
| 303 |
return []
|
| 304 |
|
|
|
|
| 110 |
pad_id = current_tokenizer.pad_token_id or current_tokenizer.unk_token_id or 0
|
| 111 |
eos_id = current_tokenizer.eos_token_id
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
# FULL conversation
|
| 114 |
full_messages = system_messages + messages
|
| 115 |
|
|
|
|
| 259 |
patient_id_val = patient_db[patient_key]["id"]
|
| 260 |
history = patient_conversations.get(patient_id_val, [])
|
| 261 |
if not history:
|
| 262 |
+
system_message = [
|
| 263 |
+
{
|
| 264 |
+
"role": "system",
|
| 265 |
"content": (
|
| 266 |
+
"You are a radiologist's companion, here to answer questions about the patient and assist in the diagnosis if asked to do so. "
|
| 267 |
+
"You are able to call specialized tools. "
|
| 268 |
+
"At the moment, you have one tool available: an organ segmentation algorithm for abdominal CTs.\n\n"
|
| 269 |
+
"If the user requests an organ segmentation, output a JSON object in this structure:\n"
|
| 270 |
+
"{\n"
|
| 271 |
+
" \"function\": \"segment_organ\",\n"
|
| 272 |
+
" \"arguments\": {\n"
|
| 273 |
+
" \"scan_path\": \"<path_to_ct_scan>\",\n"
|
| 274 |
+
" \"organ\": \"<organ_name>\"\n"
|
| 275 |
+
" }\n"
|
| 276 |
+
"}\n\n"
|
| 277 |
+
"Once you call the function, the app will execute it and return the result."
|
| 278 |
+
)
|
| 279 |
+
},
|
| 280 |
+
{
|
| 281 |
+
"role": "system",
|
| 282 |
+
"content": f"Patient Information:\nName: {patient_name.value}\nAge: {patient_age.value}\nID: {patient_id.value}\nNotes: {patient_notes.value}"
|
| 283 |
+
}
|
| 284 |
+
]
|
| 285 |
+
welcome_message = [
|
| 286 |
+
{
|
| 287 |
+
"role": "assistant",
|
| 288 |
+
"content": (
|
| 289 |
+
"**Welcome to the Radiologist's Companion!**\n\n"
|
| 290 |
+
"You can ask me about the patient's medical history or available imaging data.\n"
|
| 291 |
+
"- I can summarize key details from the EHR.\n"
|
| 292 |
+
"- I can tell you which medical images are available.\n"
|
| 293 |
+
"- If you'd like an organ segmentation (e.g. spleen, liver, kidney_left, colon, femur_right) on an abdominal CT scan, just ask!\n\n"
|
| 294 |
+
"**Example Requests:**\n"
|
| 295 |
+
"- \"What do we know about this patient?\"\n"
|
| 296 |
+
"- \"Which images are available for this patient?\"\n"
|
| 297 |
+
"- \"Can you segment the spleen from the CT scan?\"\n"
|
| 298 |
+
)
|
| 299 |
+
}
|
| 300 |
+
]
|
| 301 |
+
history = system_message + welcome_message
|
| 302 |
return history
|
| 303 |
return []
|
| 304 |
|