Ali2206 commited on
Commit
3454516
·
verified ·
1 Parent(s): 8c16b9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -92,10 +92,30 @@ Analyze the following clinical notes and provide a detailed, concise summary foc
92
  Respond in well-structured bullet points with medical reasoning.
93
  """
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  def init_agent():
96
  tool_path = os.path.join(tool_cache_dir, "new_tool.json")
97
  if not os.path.exists(tool_path):
98
  shutil.copy(os.path.abspath("data/new_tool.json"), tool_path)
 
 
 
 
99
  agent = TxAgent(
100
  model_name="mims-harvard/TxAgent-T1-Llama-3.1-8B",
101
  rag_model_name="mims-harvard/ToolRAG-T1-GTE-Qwen2-1.5B",
 
92
  Respond in well-structured bullet points with medical reasoning.
93
  """
94
 
95
+ def validate_tool_file(file_path):
96
+ try:
97
+ with open(file_path, 'r') as f:
98
+ data = json.load(f)
99
+ if isinstance(data, list):
100
+ assert all(isinstance(t, dict) and "name" in t for t in data), "Invalid tool list format"
101
+ elif isinstance(data, dict):
102
+ assert "tools" in data and isinstance(data["tools"], list), "'tools' field missing or invalid"
103
+ assert all(isinstance(t, dict) and "name" in t for t in data["tools"]), "Invalid tools inside 'tools' field"
104
+ else:
105
+ raise ValueError("Tool file is neither a list nor a dict with 'tools'")
106
+ return True
107
+ except Exception as e:
108
+ print(f"❌ Error validating tool file {file_path}: {e}")
109
+ return False
110
+
111
  def init_agent():
112
  tool_path = os.path.join(tool_cache_dir, "new_tool.json")
113
  if not os.path.exists(tool_path):
114
  shutil.copy(os.path.abspath("data/new_tool.json"), tool_path)
115
+
116
+ if not validate_tool_file(tool_path):
117
+ raise ValueError("Tool file format invalid, cannot initialize agent.")
118
+
119
  agent = TxAgent(
120
  model_name="mims-harvard/TxAgent-T1-Llama-3.1-8B",
121
  rag_model_name="mims-harvard/ToolRAG-T1-GTE-Qwen2-1.5B",