mgbam commited on
Commit
a2143ab
Β·
verified Β·
1 Parent(s): ece1629

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -10
app.py CHANGED
@@ -38,7 +38,7 @@ if missing_keys:
38
 
39
  # --- Configuration & Constants ---
40
  class ClinicalAppSettings:
41
- APP_TITLE = "SynapseAI "
42
  PAGE_LAYOUT = "wide"
43
  MODEL_NAME = "llama3-70b-8192"
44
  TEMPERATURE = 0.1
@@ -437,10 +437,14 @@ def tool_node(state: AgentState):
437
  for med_name, prescribe_call in prescriptions_requested.items():
438
  if med_name not in interaction_checks_requested:
439
  st.error(f"**Safety Violation:** AI tried to prescribe '{med_name}' without check.")
440
- error_msg = ToolMessage(content=json.dumps({
441
- "status": "error",
442
- "message": f"Interaction check needed for '{med_name}'."
443
- }), tool_call_id=prescribe_call['id'], name=prescribe_call['name'])
 
 
 
 
444
  tool_messages.append(error_msg)
445
  blocked_ids.add(prescribe_call['id'])
446
  valid_tool_calls_for_execution = [call for call in tool_calls if call['id'] not in blocked_ids]
@@ -467,17 +471,27 @@ def tool_node(state: AgentState):
467
  print(f"ERROR executing tool '{tool_name}': {error_type} - {error_str}")
468
  traceback.print_exc()
469
  st.error(f"Error: {error_type}")
470
- error_content = json.dumps({"status": "error", "message": f"Failed: {error_type} - {error_str}"})
 
 
 
471
  tool_messages.append(ToolMessage(content=error_content, tool_call_id=tool_call_id, name=tool_name))
472
  else:
473
  print(f"Tool '{tool_name}' executed.")
474
- content_str = str(resp)
 
 
 
 
475
  tool_messages.append(ToolMessage(content=content_str, tool_call_id=tool_call_id, name=tool_name))
476
  except Exception as e:
477
  print(f"CRITICAL TOOL NODE ERROR: {e}")
478
  traceback.print_exc()
479
  st.error(f"Critical error: {e}")
480
- error_content = json.dumps({"status": "error", "message": f"Internal error: {e}"})
 
 
 
481
  processed_ids = {msg.tool_call_id for msg in tool_messages}
482
  [tool_messages.append(ToolMessage(content=error_content, tool_call_id=call['id'], name=call['name']))
483
  for call in valid_tool_calls_for_execution if call['id'] not in processed_ids]
@@ -598,7 +612,7 @@ def main():
598
 
599
  # --- Main Chat Interface Area ---
600
  st.header("πŸ’¬ Clinical Consultation")
601
- # Display loop - SyntaxError Fixed
602
  for msg in st.session_state.messages:
603
  if isinstance(msg, HumanMessage):
604
  with st.chat_message("user"):
@@ -693,7 +707,7 @@ def main():
693
  message = tool_data.get("message", msg.content)
694
  details = tool_data.get("details")
695
  warnings = tool_data.get("warnings")
696
- if status == "success" or status == "clear" or status == "flagged":
697
  st.success(f"{message}", icon="βœ…" if status != "flagged" else "🚨")
698
  elif status == "warning":
699
  st.warning(f"{message}", icon="⚠️")
 
38
 
39
  # --- Configuration & Constants ---
40
  class ClinicalAppSettings:
41
+ APP_TITLE = "SynapseAI (UMLS/FDA Integrated)"
42
  PAGE_LAYOUT = "wide"
43
  MODEL_NAME = "llama3-70b-8192"
44
  TEMPERATURE = 0.1
 
437
  for med_name, prescribe_call in prescriptions_requested.items():
438
  if med_name not in interaction_checks_requested:
439
  st.error(f"**Safety Violation:** AI tried to prescribe '{med_name}' without check.")
440
+ error_msg = ToolMessage(
441
+ content=json.dumps({
442
+ "status": "error",
443
+ "message": f"Interaction check needed for '{med_name}'."
444
+ }),
445
+ tool_call_id=prescribe_call['id'],
446
+ name=prescribe_call['name']
447
+ )
448
  tool_messages.append(error_msg)
449
  blocked_ids.add(prescribe_call['id'])
450
  valid_tool_calls_for_execution = [call for call in tool_calls if call['id'] not in blocked_ids]
 
471
  print(f"ERROR executing tool '{tool_name}': {error_type} - {error_str}")
472
  traceback.print_exc()
473
  st.error(f"Error: {error_type}")
474
+ error_content = json.dumps({
475
+ "status": "error",
476
+ "message": f"Failed: {error_type} - {error_str}"
477
+ })
478
  tool_messages.append(ToolMessage(content=error_content, tool_call_id=tool_call_id, name=tool_name))
479
  else:
480
  print(f"Tool '{tool_name}' executed.")
481
+ # If response is a dict, convert it to a JSON string.
482
+ if isinstance(resp, dict):
483
+ content_str = json.dumps(resp)
484
+ else:
485
+ content_str = str(resp)
486
  tool_messages.append(ToolMessage(content=content_str, tool_call_id=tool_call_id, name=tool_name))
487
  except Exception as e:
488
  print(f"CRITICAL TOOL NODE ERROR: {e}")
489
  traceback.print_exc()
490
  st.error(f"Critical error: {e}")
491
+ error_content = json.dumps({
492
+ "status": "error",
493
+ "message": f"Internal error: {e}"
494
+ })
495
  processed_ids = {msg.tool_call_id for msg in tool_messages}
496
  [tool_messages.append(ToolMessage(content=error_content, tool_call_id=call['id'], name=call['name']))
497
  for call in valid_tool_calls_for_execution if call['id'] not in processed_ids]
 
612
 
613
  # --- Main Chat Interface Area ---
614
  st.header("πŸ’¬ Clinical Consultation")
615
+ # Display loop
616
  for msg in st.session_state.messages:
617
  if isinstance(msg, HumanMessage):
618
  with st.chat_message("user"):
 
707
  message = tool_data.get("message", msg.content)
708
  details = tool_data.get("details")
709
  warnings = tool_data.get("warnings")
710
+ if status in ["success", "clear", "flagged"]:
711
  st.success(f"{message}", icon="βœ…" if status != "flagged" else "🚨")
712
  elif status == "warning":
713
  st.warning(f"{message}", icon="⚠️")