Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ from langchain_community.tools.tavily_search import TavilySearchResults
|
|
4 |
from langchain_core.messages import HumanMessage, SystemMessage
|
5 |
from typing import TypedDict, Annotated, List, Optional
|
6 |
import json
|
7 |
-
import time
|
8 |
|
9 |
# Configuration
|
10 |
class MedicalConfig:
|
@@ -41,7 +40,9 @@ class MedicalAgent:
|
|
41 |
|
42 |
def analyze_patient(self, patient_data: dict) -> Optional[dict]:
|
43 |
try:
|
44 |
-
|
|
|
|
|
45 |
SystemMessage(content=MedicalConfig.SYSTEM_PROMPT),
|
46 |
HumanMessage(content=f"Patient Data: {json.dumps(patient_data)}")
|
47 |
])
|
@@ -54,7 +55,7 @@ class MedicalAgent:
|
|
54 |
try:
|
55 |
if action['name'] in self.tools['medical_actions']:
|
56 |
return self.tools['medical_actions'][action['name']](action['args'])
|
57 |
-
return "Unknown action"
|
58 |
except Exception as e:
|
59 |
return f"Error processing action: {str(e)}"
|
60 |
|
@@ -109,12 +110,14 @@ def main():
|
|
109 |
response = st.session_state.agent.analyze_patient(patient_data)
|
110 |
|
111 |
if response:
|
112 |
-
|
|
|
113 |
for action in response.tool_calls:
|
114 |
result = st.session_state.agent.process_action(action)
|
115 |
st.success(result)
|
116 |
else:
|
117 |
-
st.info(
|
|
|
118 |
|
119 |
# Run the app
|
120 |
if __name__ == "__main__":
|
|
|
4 |
from langchain_core.messages import HumanMessage, SystemMessage
|
5 |
from typing import TypedDict, Annotated, List, Optional
|
6 |
import json
|
|
|
7 |
|
8 |
# Configuration
|
9 |
class MedicalConfig:
|
|
|
40 |
|
41 |
def analyze_patient(self, patient_data: dict) -> Optional[dict]:
|
42 |
try:
|
43 |
+
# Bind tools to the model
|
44 |
+
model_with_tools = self.model.bind_tools(list(self.tools["medical_actions"].keys()))
|
45 |
+
response = model_with_tools.invoke([
|
46 |
SystemMessage(content=MedicalConfig.SYSTEM_PROMPT),
|
47 |
HumanMessage(content=f"Patient Data: {json.dumps(patient_data)}")
|
48 |
])
|
|
|
55 |
try:
|
56 |
if action['name'] in self.tools['medical_actions']:
|
57 |
return self.tools['medical_actions'][action['name']](action['args'])
|
58 |
+
return f"Unknown action: {action['name']}"
|
59 |
except Exception as e:
|
60 |
return f"Error processing action: {str(e)}"
|
61 |
|
|
|
110 |
response = st.session_state.agent.analyze_patient(patient_data)
|
111 |
|
112 |
if response:
|
113 |
+
st.subheader("Analysis Results")
|
114 |
+
if hasattr(response, 'tool_calls') and response.tool_calls:
|
115 |
for action in response.tool_calls:
|
116 |
result = st.session_state.agent.process_action(action)
|
117 |
st.success(result)
|
118 |
else:
|
119 |
+
st.info("No specific actions recommended. Here's the analysis:")
|
120 |
+
st.write(response.content)
|
121 |
|
122 |
# Run the app
|
123 |
if __name__ == "__main__":
|