Spaces:
Sleeping
Sleeping
Commit
·
c2d68af
1
Parent(s):
62f919c
Update: prototype development finished
Browse files- modules/data_class.py +1 -1
- modules/nodes.py +3 -3
- modules/tools.py +4 -3
- paintrek-chat-v2.ipynb +150 -27
modules/data_class.py
CHANGED
@@ -45,7 +45,7 @@ class Pain(TypedDict):
|
|
45 |
class MedicalHistory(TypedDict):
|
46 |
medical_condition: str
|
47 |
first_time: date
|
48 |
-
surgery_history:
|
49 |
medication: str
|
50 |
allergy: str
|
51 |
|
|
|
45 |
class MedicalHistory(TypedDict):
|
46 |
medical_condition: str
|
47 |
first_time: date
|
48 |
+
surgery_history: str
|
49 |
medication: str
|
50 |
allergy: str
|
51 |
|
modules/nodes.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from modules.data_class import DataState
|
2 |
from modules.instrctions import MEDICAL_INTAKE_SYSINT, WELCOME_MSG
|
3 |
from modules.llm_in_use import get_llm
|
4 |
-
from modules.tools import patient_id, symptom, confirm_data, get_data, clear_data, save_data
|
5 |
|
6 |
from datetime import date
|
7 |
from typing import Literal
|
@@ -10,7 +10,7 @@ from langchain_core.messages.ai import AIMessage
|
|
10 |
|
11 |
llm = get_llm()
|
12 |
# Order-tools will be handled by the order node.
|
13 |
-
intake_tools = [patient_id, symptom, confirm_data, get_data, clear_data, save_data]
|
14 |
|
15 |
# The LLM needs to know about all of the tools, so specify everything here.
|
16 |
llm_with_tools = llm.bind_tools(intake_tools)
|
@@ -64,7 +64,7 @@ def chatbot_with_tools(state: DataState) -> DataState:
|
|
64 |
"medical_hist": {
|
65 |
"medical_condition": "",
|
66 |
"first_time": date(1900, 1, 1),
|
67 |
-
"surgery_history":
|
68 |
"medication": "",
|
69 |
"allergy": ""
|
70 |
},
|
|
|
1 |
from modules.data_class import DataState
|
2 |
from modules.instrctions import MEDICAL_INTAKE_SYSINT, WELCOME_MSG
|
3 |
from modules.llm_in_use import get_llm
|
4 |
+
from modules.tools import patient_id, symptom, pain, medical_hist, family_hist, social_hist, review_system, pain_manage, functional, plan, confirm_data, get_data, clear_data, save_data
|
5 |
|
6 |
from datetime import date
|
7 |
from typing import Literal
|
|
|
10 |
|
11 |
llm = get_llm()
|
12 |
# Order-tools will be handled by the order node.
|
13 |
+
intake_tools = [patient_id, symptom, pain, medical_hist, family_hist, social_hist, review_system, pain_manage, functional, plan, confirm_data, get_data, clear_data, save_data]
|
14 |
|
15 |
# The LLM needs to know about all of the tools, so specify everything here.
|
16 |
llm_with_tools = llm.bind_tools(intake_tools)
|
|
|
64 |
"medical_hist": {
|
65 |
"medical_condition": "",
|
66 |
"first_time": date(1900, 1, 1),
|
67 |
+
"surgery_history": "",
|
68 |
"medication": "",
|
69 |
"allergy": ""
|
70 |
},
|
modules/tools.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import pprint
|
|
|
2 |
|
3 |
from langchain_core.tools import tool
|
4 |
from modules.data_class import DataState
|
@@ -48,7 +49,7 @@ def pain(pain_location: str, pain_side: str, pain_intensity: int, pain_descripti
|
|
48 |
"""
|
49 |
|
50 |
@tool
|
51 |
-
def medical_hist(medical_condition: str, first_time: str, surgery_history:
|
52 |
"""Collecting patient's medical history including:
|
53 |
- Existing medical conditions
|
54 |
- First occurrence date
|
@@ -69,7 +70,7 @@ def family_hist(family_history: str) -> str:
|
|
69 |
"""
|
70 |
|
71 |
@tool
|
72 |
-
def social_hist(occupation: str,
|
73 |
"""Collecting patient's social history including:
|
74 |
- Occupation
|
75 |
- smoking or not
|
@@ -274,7 +275,7 @@ def data_node(state: DataState) -> DataState:
|
|
274 |
|
275 |
# TODO(you!): Implement cafe.
|
276 |
data_saved = True
|
277 |
-
|
278 |
|
279 |
else:
|
280 |
raise NotImplementedError(f'Unknown tool call: {tool_call["name"]}')
|
|
|
1 |
import pprint
|
2 |
+
import random
|
3 |
|
4 |
from langchain_core.tools import tool
|
5 |
from modules.data_class import DataState
|
|
|
49 |
"""
|
50 |
|
51 |
@tool
|
52 |
+
def medical_hist(medical_condition: str, first_time: str, surgery_history: str, medication: str, allergy: str) -> str:
|
53 |
"""Collecting patient's medical history including:
|
54 |
- Existing medical conditions
|
55 |
- First occurrence date
|
|
|
70 |
"""
|
71 |
|
72 |
@tool
|
73 |
+
def social_hist(occupation: str, smoke: bool, alcohol: bool, drug: bool, support_system: str, living_condition: str) -> str:
|
74 |
"""Collecting patient's social history including:
|
75 |
- Occupation
|
76 |
- smoking or not
|
|
|
275 |
|
276 |
# TODO(you!): Implement cafe.
|
277 |
data_saved = True
|
278 |
+
response = random.randint(1, 5) # ETA in minutes
|
279 |
|
280 |
else:
|
281 |
raise NotImplementedError(f'Unknown tool call: {tool_call["name"]}')
|
paintrek-chat-v2.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {
|
7 |
"execution": {
|
8 |
"iopub.execute_input": "2025-01-29T20:09:11.440091Z",
|
@@ -35,7 +35,7 @@
|
|
35 |
},
|
36 |
{
|
37 |
"cell_type": "code",
|
38 |
-
"execution_count":
|
39 |
"metadata": {
|
40 |
"execution": {
|
41 |
"iopub.execute_input": "2025-01-29T20:09:11.906458Z",
|
@@ -55,7 +55,7 @@
|
|
55 |
"<IPython.core.display.Image object>"
|
56 |
]
|
57 |
},
|
58 |
-
"execution_count":
|
59 |
"metadata": {},
|
60 |
"output_type": "execute_result"
|
61 |
}
|
@@ -84,7 +84,7 @@
|
|
84 |
},
|
85 |
{
|
86 |
"cell_type": "code",
|
87 |
-
"execution_count":
|
88 |
"metadata": {
|
89 |
"execution": {
|
90 |
"iopub.execute_input": "2025-01-29T20:09:38.185616Z",
|
@@ -103,27 +103,115 @@
|
|
103 |
"text": [
|
104 |
"Executing the chatbot graph...\n",
|
105 |
"Model: Welcome to the Paintrek world. I am a health assistant, an interactive clinical recording system. I will ask you questions about your pain and related symptoms and record your responses. I will then store this information securely. At any time, you can type `q` to quit.\n",
|
106 |
-
"Model:
|
107 |
-
"Model: Thank you. Now, can you describe your main symptom
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
]
|
109 |
},
|
110 |
{
|
111 |
-
"
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
}
|
128 |
],
|
129 |
"source": [
|
@@ -159,18 +247,53 @@
|
|
159 |
" 'gender': 'male',\n",
|
160 |
" 'contact': '12345',\n",
|
161 |
" 'emergency_contact': 'Zoe, 67890'},\n",
|
162 |
-
" 'symptom': {'main_symptom': '
|
163 |
-
"
|
164 |
-
" '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
]
|
166 |
},
|
167 |
-
"execution_count":
|
168 |
"metadata": {},
|
169 |
"output_type": "execute_result"
|
170 |
}
|
171 |
],
|
172 |
"source": [
|
173 |
-
"state[\"data\"]
|
174 |
]
|
175 |
},
|
176 |
{
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
"metadata": {
|
7 |
"execution": {
|
8 |
"iopub.execute_input": "2025-01-29T20:09:11.440091Z",
|
|
|
35 |
},
|
36 |
{
|
37 |
"cell_type": "code",
|
38 |
+
"execution_count": 2,
|
39 |
"metadata": {
|
40 |
"execution": {
|
41 |
"iopub.execute_input": "2025-01-29T20:09:11.906458Z",
|
|
|
55 |
"<IPython.core.display.Image object>"
|
56 |
]
|
57 |
},
|
58 |
+
"execution_count": 2,
|
59 |
"metadata": {},
|
60 |
"output_type": "execute_result"
|
61 |
}
|
|
|
84 |
},
|
85 |
{
|
86 |
"cell_type": "code",
|
87 |
+
"execution_count": 3,
|
88 |
"metadata": {
|
89 |
"execution": {
|
90 |
"iopub.execute_input": "2025-01-29T20:09:38.185616Z",
|
|
|
103 |
"text": [
|
104 |
"Executing the chatbot graph...\n",
|
105 |
"Model: Welcome to the Paintrek world. I am a health assistant, an interactive clinical recording system. I will ask you questions about your pain and related symptoms and record your responses. I will then store this information securely. At any time, you can type `q` to quit.\n",
|
106 |
+
"Model: First, I need to collect some basic information for identification. Could you please provide your full name, date of birth, gender, and contact number? Also, please provide the name and contact information for an emergency contact.\n",
|
107 |
+
"Model: Thank you. Now, can you describe your main symptom and how long you've been experiencing it?\n",
|
108 |
+
"Model: Could you tell me more about the headache? Where is the pain located? Is it on the left, right, or both sides? On a scale of 0 to 10, with 0 being no pain and 10 being the worst pain imaginable, how intense is the pain? What are the characteristics of the pain (e.g., sharp, dull, throbbing)? When did it start? Does the pain radiate to any other areas? What, if anything, triggers the headache? Are there any other symptoms associated with the headache (e.g., nausea, vomiting, visual disturbances)?\n",
|
109 |
+
"Model: Let's move on to your medical history. Do you have any existing medical conditions? When were they first diagnosed? Have you ever had any surgeries? If so, when? Are you currently taking any medications? Do you have any allergies?\n",
|
110 |
+
"Model: Now, let's discuss your family medical history. Are there any significant medical conditions that run in your family?\n",
|
111 |
+
"Model: To get a more complete picture, could you share some information about your lifestyle? What is your occupation? Do you smoke, drink alcohol, or use drugs? Could you describe your living situation and support system?\n",
|
112 |
+
"Model: We're almost done. Let's do a quick system review. Have you experienced any recent weight changes? Have you had any fever, chills, or night sweats? How is your sleep? How are your gastrointestinal and urinary functions?\n",
|
113 |
+
"Model: Finally, let's talk about your pain management. What pain medications are you currently using? Have you consulted any specialists for your pain? Have you tried any alternative therapies? How effective has your pain management been so far?\n",
|
114 |
+
"Model: To conclude, could you please describe how this headache impacts your quality of life, any limitations on your activities, and your current mood? Also, what are your treatment goals and expectations? Are there any alternative treatments you'd consider?\n",
|
115 |
+
"Model: Before we finalize this record, could you please confirm that all the information we've gathered is accurate?\n",
|
116 |
+
"Saving the data!\n",
|
117 |
+
"{'ID': {'name': 'Frank', 'DOB': '1986-01-01', 'gender': 'male', 'contact': '12345', 'emergency_contact': 'Zoe, 67890'}, 'symptom': {'main_symptom': 'Headache', 'symptom_length': '2 days'}, 'pain': {'pain_location': 'Right head', 'pain_side': 'Right', 'pain_intensity': 2.0, 'pain_description': 'Sharp', 'start_time': '2 days ago', 'radiation': False, 'triggers': 'Cold', 'symptom': 'No other symptoms'}, 'medical_hist': {'medical_condition': 'Sinus', 'first_time': '2001-01-01', 'surgery_history': 'None', 'medication': 'Ibprofin', 'allergy': 'None'}, 'family_hist': {'family_history': 'Mother had lung cancer at 45'}, 'social_hist': {'occupation': 'Data scientist', 'smoke': False, 'alcohol': False, 'drug': False, 'support_system': 'Unknown', 'living_condition': 'Unknown'}, 'review_system': {'weight_change': 'None', 'fever': False, 'chill': False, 'night_sweats': False, 'sleep': 'Well', 'gastrointestinal': 'Normal', 'urinary': 'Normal'}, 'pain_manage': {'pain_medication': 'No', 'specialist': False, 'other_therapy': 'No', 'effectiveness': 'Unknown'}, 'functional': {'life_quality': 'Good', 'limit_activity': 'None', 'mood': 'Okay'}, 'plan': {'goal': 'Fix headache', 'expectation': 'Fix headache', 'alternative_treatment': 'None'}}\n"
|
118 |
]
|
119 |
},
|
120 |
{
|
121 |
+
"data": {
|
122 |
+
"text/plain": [
|
123 |
+
"{'messages': [AIMessage(content='Welcome to the Paintrek world. I am a health assistant, an interactive clinical recording system. I will ask you questions about your pain and related symptoms and record your responses. I will then store this information securely. At any time, you can type `q` to quit.', additional_kwargs={}, response_metadata={}, id='9d9f4dc0-206c-474f-8322-458b7aeec747'),\n",
|
124 |
+
" HumanMessage(content=\"Let's start\", additional_kwargs={}, response_metadata={}, id='c5cbbc6e-1cd8-4924-84ad-19636037a42b'),\n",
|
125 |
+
" AIMessage(content='First, I need to collect some basic information for identification. Could you please provide your full name, date of birth, gender, and contact number? Also, please provide the name and contact information for an emergency contact.', additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-625a1eff-7e43-46a9-b824-0ca7de7959a5-0', usage_metadata={'input_tokens': 1526, 'output_tokens': 47, 'total_tokens': 1573, 'input_token_details': {'cache_read': 0}}),\n",
|
126 |
+
" HumanMessage(content='I am Frank, DOB 1986-01-01, male, phone number is 12345, emergency name is Zoe, number is 67890.', additional_kwargs={}, response_metadata={}, id='efaee7ea-596d-4152-8872-5eb8633f76a5'),\n",
|
127 |
+
" AIMessage(content='', additional_kwargs={'function_call': {'name': 'patient_id', 'arguments': '{\"contact\": \"12345\", \"DOB\": \"1986-01-01\", \"gender\": \"male\", \"emergency_contact\": \"Zoe, 67890\", \"name\": \"Frank\"}'}}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-3c5557d4-313e-482e-8901-d7ecd490a9f0-0', tool_calls=[{'name': 'patient_id', 'args': {'contact': '12345', 'DOB': '1986-01-01', 'gender': 'male', 'emergency_contact': 'Zoe, 67890', 'name': 'Frank'}, 'id': 'bb2eb4b7-ff42-4584-aa0b-f6bca017bd51', 'type': 'tool_call'}], usage_metadata={'input_tokens': 1615, 'output_tokens': 35, 'total_tokens': 1650, 'input_token_details': {'cache_read': 0}}),\n",
|
128 |
+
" ToolMessage(content='ID\\nsymptom\\npain\\nmedical_hist\\nfamily_hist\\nsocial_hist\\nreview_system\\npain_manage\\nfunctional\\nplan', name='patient_id', id='25805edd-4bea-4d24-864f-e23cb87306cf', tool_call_id='bb2eb4b7-ff42-4584-aa0b-f6bca017bd51'),\n",
|
129 |
+
" AIMessage(content=\"Thank you. Now, can you describe your main symptom and how long you've been experiencing it?\", additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-f7885dbe-c5e7-48c3-9e85-e111c07625dc-0', usage_metadata={'input_tokens': 1684, 'output_tokens': 22, 'total_tokens': 1706, 'input_token_details': {'cache_read': 0}}),\n",
|
130 |
+
" HumanMessage(content='I had a headache, and it started two days ago.', additional_kwargs={}, response_metadata={}, id='aa33a92d-255f-483a-93e1-ef552dc5b109'),\n",
|
131 |
+
" AIMessage(content='', additional_kwargs={'function_call': {'name': 'symptom', 'arguments': '{\"symptom_length\": \"2 days\", \"main_symptom\": \"Headache\"}'}}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-e2451cbe-be34-4d38-b8d4-5fd8797ee910-0', tool_calls=[{'name': 'symptom', 'args': {'symptom_length': '2 days', 'main_symptom': 'Headache'}, 'id': 'bfdd9836-6f09-4d36-8308-c5571241e899', 'type': 'tool_call'}], usage_metadata={'input_tokens': 1717, 'output_tokens': 14, 'total_tokens': 1731, 'input_token_details': {'cache_read': 0}}),\n",
|
132 |
+
" ToolMessage(content='ID\\nsymptom\\npain\\nmedical_hist\\nfamily_hist\\nsocial_hist\\nreview_system\\npain_manage\\nfunctional\\nplan', name='symptom', id='ed5418d4-6e70-46fd-ad59-3eb26e72d84d', tool_call_id='bfdd9836-6f09-4d36-8308-c5571241e899'),\n",
|
133 |
+
" AIMessage(content='Could you tell me more about the headache? Where is the pain located? Is it on the left, right, or both sides? On a scale of 0 to 10, with 0 being no pain and 10 being the worst pain imaginable, how intense is the pain? What are the characteristics of the pain (e.g., sharp, dull, throbbing)? When did it start? Does the pain radiate to any other areas? What, if anything, triggers the headache? Are there any other symptoms associated with the headache (e.g., nausea, vomiting, visual disturbances)?', additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-2fe7272d-2b5a-4fa0-81e2-837f3fcd95d0-0', usage_metadata={'input_tokens': 1764, 'output_tokens': 125, 'total_tokens': 1889, 'input_token_details': {'cache_read': 0}}),\n",
|
134 |
+
" HumanMessage(content='My pain is located on the right head, and the scale is 2, the pain is sharp, the pain started 2 days ago, and the pain is not radiating. Cold will trigger the pain, and no other symptoms. ', additional_kwargs={}, response_metadata={}, id='2e0970d1-76f8-46e1-b9e5-f6c6da1f2a65'),\n",
|
135 |
+
" AIMessage(content='', additional_kwargs={'function_call': {'name': 'pain', 'arguments': '{\"pain_location\": \"Right head\", \"radiation\": false, \"start_time\": \"2 days ago\", \"symptom\": \"No other symptoms\", \"pain_side\": \"Right\", \"pain_intensity\": 2.0, \"pain_description\": \"Sharp\", \"triggers\": \"Cold\"}'}}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-ccea4875-140d-4d67-8257-972f59fef2d6-0', tool_calls=[{'name': 'pain', 'args': {'pain_location': 'Right head', 'radiation': False, 'start_time': '2 days ago', 'symptom': 'No other symptoms', 'pain_side': 'Right', 'pain_intensity': 2.0, 'pain_description': 'Sharp', 'triggers': 'Cold'}, 'id': 'c00f1773-566e-4caa-b920-6316efd45ef6', 'type': 'tool_call'}], usage_metadata={'input_tokens': 1936, 'output_tokens': 31, 'total_tokens': 1967, 'input_token_details': {'cache_read': 0}}),\n",
|
136 |
+
" ToolMessage(content='ID\\nsymptom\\npain\\nmedical_hist\\nfamily_hist\\nsocial_hist\\nreview_system\\npain_manage\\nfunctional\\nplan', name='pain', id='1f2dbda4-bcad-41a6-b415-d034211f2836', tool_call_id='c00f1773-566e-4caa-b920-6316efd45ef6'),\n",
|
137 |
+
" AIMessage(content=\"Let's move on to your medical history. Do you have any existing medical conditions? When were they first diagnosed? Have you ever had any surgeries? If so, when? Are you currently taking any medications? Do you have any allergies?\", additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-1584fcb0-bea9-47b1-88ec-7a2acacd22e0-0', usage_metadata={'input_tokens': 1999, 'output_tokens': 52, 'total_tokens': 2051, 'input_token_details': {'cache_read': 0}}),\n",
|
138 |
+
" HumanMessage(content='I had sinus, diagnosed in 2001-01-01, I did not have any surgery. I am taking ibprofin, no allergies.', additional_kwargs={}, response_metadata={}, id='f59997a9-b21b-4506-9a76-bd11f8d45570'),\n",
|
139 |
+
" AIMessage(content='', additional_kwargs={'function_call': {'name': 'medical_hist', 'arguments': '{\"medical_condition\": \"Sinus\", \"first_time\": \"2001-01-01\", \"allergy\": \"None\", \"surgery_history\": \"None\", \"medication\": \"Ibprofin\"}'}}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-b577e889-c382-4b92-bb64-436a179d42f3-0', tool_calls=[{'name': 'medical_hist', 'args': {'medical_condition': 'Sinus', 'first_time': '2001-01-01', 'allergy': 'None', 'surgery_history': 'None', 'medication': 'Ibprofin'}, 'id': '909c6e8c-1f8b-4dfa-8419-444ef8e1c3ba', 'type': 'tool_call'}], usage_metadata={'input_tokens': 2085, 'output_tokens': 32, 'total_tokens': 2117, 'input_token_details': {'cache_read': 0}}),\n",
|
140 |
+
" ToolMessage(content='ID\\nsymptom\\npain\\nmedical_hist\\nfamily_hist\\nsocial_hist\\nreview_system\\npain_manage\\nfunctional\\nplan', name='medical_hist', id='d3a4d6fe-c438-491d-9491-ba863db704db', tool_call_id='909c6e8c-1f8b-4dfa-8419-444ef8e1c3ba'),\n",
|
141 |
+
" AIMessage(content=\"Now, let's discuss your family medical history. Are there any significant medical conditions that run in your family?\", additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-a39755e6-5a91-4af1-8519-bf5505f87420-0', usage_metadata={'input_tokens': 2151, 'output_tokens': 24, 'total_tokens': 2175, 'input_token_details': {'cache_read': 0}}),\n",
|
142 |
+
" HumanMessage(content='My mom had a lung cancer at 45.', additional_kwargs={}, response_metadata={}, id='5e7229d4-75c1-4af0-86ee-0bf6b0cf79b8'),\n",
|
143 |
+
" AIMessage(content='', additional_kwargs={'function_call': {'name': 'family_hist', 'arguments': '{\"family_history\": \"Mother had lung cancer at 45\"}'}}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-649911e3-2e04-411f-9748-6118b678c995-0', tool_calls=[{'name': 'family_hist', 'args': {'family_history': 'Mother had lung cancer at 45'}, 'id': '00538952-3a24-43af-bd00-d8be94a23c0d', 'type': 'tool_call'}], usage_metadata={'input_tokens': 2185, 'output_tokens': 14, 'total_tokens': 2199, 'input_token_details': {'cache_read': 0}}),\n",
|
144 |
+
" ToolMessage(content='ID\\nsymptom\\npain\\nmedical_hist\\nfamily_hist\\nsocial_hist\\nreview_system\\npain_manage\\nfunctional\\nplan', name='family_hist', id='185e4a86-c4f7-467c-9cc4-694e90f14fd5', tool_call_id='00538952-3a24-43af-bd00-d8be94a23c0d'),\n",
|
145 |
+
" AIMessage(content='To get a more complete picture, could you share some information about your lifestyle? What is your occupation? Do you smoke, drink alcohol, or use drugs? Could you describe your living situation and support system?', additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-b7feb925-e20f-4f26-8e6a-d6d0b6d6f535-0', usage_metadata={'input_tokens': 2233, 'output_tokens': 44, 'total_tokens': 2277, 'input_token_details': {'cache_read': 0}}),\n",
|
146 |
+
" HumanMessage(content=\"I am a data scientist, I am a viggie. I don't use tobbaco or alcohol. My stress level is midium. \", additional_kwargs={}, response_metadata={}, id='9729418d-ccaf-499e-b113-102bda1ffb44'),\n",
|
147 |
+
" AIMessage(content='', additional_kwargs={'function_call': {'name': 'social_hist', 'arguments': '{\"occupation\": \"Data scientist\", \"alcohol\": false, \"support_system\": \"Unknown\", \"living_condition\": \"Unknown\", \"smoke\": false, \"drug\": false}'}}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-4cd83ff3-1c6c-4a25-b6ce-324f643a9983-0', tool_calls=[{'name': 'social_hist', 'args': {'occupation': 'Data scientist', 'alcohol': False, 'support_system': 'Unknown', 'living_condition': 'Unknown', 'smoke': False, 'drug': False}, 'id': '9e7e59cd-1f82-4509-90fa-0f04e2ae3247', 'type': 'tool_call'}], usage_metadata={'input_tokens': 2307, 'output_tokens': 17, 'total_tokens': 2324, 'input_token_details': {'cache_read': 0}}),\n",
|
148 |
+
" ToolMessage(content='ID\\nsymptom\\npain\\nmedical_hist\\nfamily_hist\\nsocial_hist\\nreview_system\\npain_manage\\nfunctional\\nplan', name='social_hist', id='b5fb4fb9-7a92-4e9b-ae60-f712789d0763', tool_call_id='9e7e59cd-1f82-4509-90fa-0f04e2ae3247'),\n",
|
149 |
+
" AIMessage(content=\"We're almost done. Let's do a quick system review. Have you experienced any recent weight changes? Have you had any fever, chills, or night sweats? How is your sleep? How are your gastrointestinal and urinary functions?\", additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-ad5ad812-ff0f-4df5-8b24-ff8477b846ea-0', usage_metadata={'input_tokens': 2358, 'output_tokens': 53, 'total_tokens': 2411, 'input_token_details': {'cache_read': 0}}),\n",
|
150 |
+
" HumanMessage(content='I sleep well, and no other symptoms.', additional_kwargs={}, response_metadata={}, id='fdae21fe-3b98-4481-8b84-9a37278dbe2e'),\n",
|
151 |
+
" AIMessage(content='', additional_kwargs={'function_call': {'name': 'review_system', 'arguments': '{\"night_sweats\": false, \"urinary\": \"Normal\", \"fever\": false, \"chill\": false, \"weight_change\": \"None\", \"gastrointestinal\": \"Normal\", \"sleep\": \"Well\"}'}}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-5fee7657-9fa1-49e7-8eae-6692fb4c091f-0', tool_calls=[{'name': 'review_system', 'args': {'night_sweats': False, 'urinary': 'Normal', 'fever': False, 'chill': False, 'weight_change': 'None', 'gastrointestinal': 'Normal', 'sleep': 'Well'}, 'id': '8eb97099-d605-4f5f-b68f-09b42c1b57a3', 'type': 'tool_call'}], usage_metadata={'input_tokens': 2419, 'output_tokens': 22, 'total_tokens': 2441, 'input_token_details': {'cache_read': 0}}),\n",
|
152 |
+
" ToolMessage(content='ID\\nsymptom\\npain\\nmedical_hist\\nfamily_hist\\nsocial_hist\\nreview_system\\npain_manage\\nfunctional\\nplan', name='review_system', id='79d367c4-9f55-4bf4-8e57-61a181f04c50', tool_call_id='8eb97099-d605-4f5f-b68f-09b42c1b57a3'),\n",
|
153 |
+
" AIMessage(content=\"Finally, let's talk about your pain management. What pain medications are you currently using? Have you consulted any specialists for your pain? Have you tried any alternative therapies? How effective has your pain management been so far?\", additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-b04ae18f-4886-4f4e-bac0-249fa25a9104-0', usage_metadata={'input_tokens': 2475, 'output_tokens': 46, 'total_tokens': 2521, 'input_token_details': {'cache_read': 0}}),\n",
|
154 |
+
" HumanMessage(content=\"No, I am not taking any other medication, and I haven't tried any alternative therapies. \", additional_kwargs={}, response_metadata={}, id='2f7663f0-bf45-4a88-8166-87296401b484'),\n",
|
155 |
+
" AIMessage(content='', additional_kwargs={'function_call': {'name': 'pain_manage', 'arguments': '{\"other_therapy\": \"No\", \"effectiveness\": \"Unknown\", \"specialist\": false, \"pain_medication\": \"No\"}'}}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-957a0591-60ca-432f-8d58-96b6e320d3f8-0', tool_calls=[{'name': 'pain_manage', 'args': {'other_therapy': 'No', 'effectiveness': 'Unknown', 'specialist': False, 'pain_medication': 'No'}, 'id': '8e3b6362-259c-4761-8afd-8dafdf089d64', 'type': 'tool_call'}], usage_metadata={'input_tokens': 2541, 'output_tokens': 14, 'total_tokens': 2555, 'input_token_details': {'cache_read': 0}}),\n",
|
156 |
+
" ToolMessage(content='ID\\nsymptom\\npain\\nmedical_hist\\nfamily_hist\\nsocial_hist\\nreview_system\\npain_manage\\nfunctional\\nplan', name='pain_manage', id='05176215-7b75-44b0-bf4b-781415e99c92', tool_call_id='8e3b6362-259c-4761-8afd-8dafdf089d64'),\n",
|
157 |
+
" AIMessage(content=\"To conclude, could you please describe how this headache impacts your quality of life, any limitations on your activities, and your current mood? Also, what are your treatment goals and expectations? Are there any alternative treatments you'd consider?\", additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-180eb319-b8ab-4839-9e4a-0dfddc1db7a5-0', usage_metadata={'input_tokens': 2589, 'output_tokens': 49, 'total_tokens': 2638, 'input_token_details': {'cache_read': 0}}),\n",
|
158 |
+
" HumanMessage(content='I am okay on my mood, and my quality of life is also good. I want to fix my headache.', additional_kwargs={}, response_metadata={}, id='8d9d0595-b4c8-4363-8a12-9d25d622df40'),\n",
|
159 |
+
" AIMessage(content='', additional_kwargs={'function_call': {'name': 'plan', 'arguments': '{\"alternative_treatment\": \"None\", \"goal\": \"Fix headache\", \"expectation\": \"Fix headache\"}'}}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-b8aa1b09-e8ca-4b28-975b-b9c236fec8cf-0', tool_calls=[{'name': 'functional', 'args': {'limit_activity': 'None', 'life_quality': 'Good', 'mood': 'Okay'}, 'id': 'a4e3932e-f8f4-4f04-b197-f8a121bc9a83', 'type': 'tool_call'}, {'name': 'plan', 'args': {'alternative_treatment': 'None', 'goal': 'Fix headache', 'expectation': 'Fix headache'}, 'id': '6b547d21-4aa1-4446-bd88-513e89f40a00', 'type': 'tool_call'}], usage_metadata={'input_tokens': 2660, 'output_tokens': 23, 'total_tokens': 2683, 'input_token_details': {'cache_read': 0}}),\n",
|
160 |
+
" ToolMessage(content='ID\\nsymptom\\npain\\nmedical_hist\\nfamily_hist\\nsocial_hist\\nreview_system\\npain_manage\\nfunctional\\nplan', name='functional', id='ac6a0abc-75f5-4166-be1d-0b0380b4be42', tool_call_id='a4e3932e-f8f4-4f04-b197-f8a121bc9a83'),\n",
|
161 |
+
" ToolMessage(content='ID\\nsymptom\\npain\\nmedical_hist\\nfamily_hist\\nsocial_hist\\nreview_system\\npain_manage\\nfunctional\\nplan', name='plan', id='36e5190d-6e92-408e-81cc-a4e4002db458', tool_call_id='6b547d21-4aa1-4446-bd88-513e89f40a00'),\n",
|
162 |
+
" AIMessage(content=\"Before we finalize this record, could you please confirm that all the information we've gathered is accurate?\", additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-418aedcc-36df-4162-88fa-502fe88c92de-0', usage_metadata={'input_tokens': 2746, 'output_tokens': 22, 'total_tokens': 2768, 'input_token_details': {'cache_read': 0}}),\n",
|
163 |
+
" HumanMessage(content='I am okay on my mood, and my quality of life is also good. I want to fix my headache.', additional_kwargs={}, response_metadata={}, id='284f6024-d70b-4465-a9cf-359d9302bc55'),\n",
|
164 |
+
" AIMessage(content='Okay, I will save your information now.', additional_kwargs={'function_call': {'name': 'save_data', 'arguments': '{}'}}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-50382a72-be29-45cb-b883-fa7242e1c717-0', tool_calls=[{'name': 'save_data', 'args': {}, 'id': '4da5513e-f8e6-4b08-a9ff-70e63825b9df', 'type': 'tool_call'}], usage_metadata={'input_tokens': 2790, 'output_tokens': 13, 'total_tokens': 2803, 'input_token_details': {'cache_read': 0}}),\n",
|
165 |
+
" ToolMessage(content='4', name='save_data', id='b332e4a1-52dc-4739-9abc-1d8ff8d973d2', tool_call_id='4da5513e-f8e6-4b08-a9ff-70e63825b9df'),\n",
|
166 |
+
" AIMessage(content='Thank you for providing all the necessary information. Your medical record has been successfully saved. Please let me know if you have any further questions or need additional assistance. Have a good day.', additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'safety_ratings': []}, id='run-63007311-b94d-49c4-8ed1-0c23a32af250-0', usage_metadata={'input_tokens': 2797, 'output_tokens': 40, 'total_tokens': 2837, 'input_token_details': {'cache_read': 0}})],\n",
|
167 |
+
" 'data': {'ID': {'name': 'Frank',\n",
|
168 |
+
" 'DOB': '1986-01-01',\n",
|
169 |
+
" 'gender': 'male',\n",
|
170 |
+
" 'contact': '12345',\n",
|
171 |
+
" 'emergency_contact': 'Zoe, 67890'},\n",
|
172 |
+
" 'symptom': {'main_symptom': 'Headache', 'symptom_length': '2 days'},\n",
|
173 |
+
" 'pain': {'pain_location': 'Right head',\n",
|
174 |
+
" 'pain_side': 'Right',\n",
|
175 |
+
" 'pain_intensity': 2.0,\n",
|
176 |
+
" 'pain_description': 'Sharp',\n",
|
177 |
+
" 'start_time': '2 days ago',\n",
|
178 |
+
" 'radiation': False,\n",
|
179 |
+
" 'triggers': 'Cold',\n",
|
180 |
+
" 'symptom': 'No other symptoms'},\n",
|
181 |
+
" 'medical_hist': {'medical_condition': 'Sinus',\n",
|
182 |
+
" 'first_time': '2001-01-01',\n",
|
183 |
+
" 'surgery_history': 'None',\n",
|
184 |
+
" 'medication': 'Ibprofin',\n",
|
185 |
+
" 'allergy': 'None'},\n",
|
186 |
+
" 'family_hist': {'family_history': 'Mother had lung cancer at 45'},\n",
|
187 |
+
" 'social_hist': {'occupation': 'Data scientist',\n",
|
188 |
+
" 'smoke': False,\n",
|
189 |
+
" 'alcohol': False,\n",
|
190 |
+
" 'drug': False,\n",
|
191 |
+
" 'support_system': 'Unknown',\n",
|
192 |
+
" 'living_condition': 'Unknown'},\n",
|
193 |
+
" 'review_system': {'weight_change': 'None',\n",
|
194 |
+
" 'fever': False,\n",
|
195 |
+
" 'chill': False,\n",
|
196 |
+
" 'night_sweats': False,\n",
|
197 |
+
" 'sleep': 'Well',\n",
|
198 |
+
" 'gastrointestinal': 'Normal',\n",
|
199 |
+
" 'urinary': 'Normal'},\n",
|
200 |
+
" 'pain_manage': {'pain_medication': 'No',\n",
|
201 |
+
" 'specialist': False,\n",
|
202 |
+
" 'other_therapy': 'No',\n",
|
203 |
+
" 'effectiveness': 'Unknown'},\n",
|
204 |
+
" 'functional': {'life_quality': 'Good',\n",
|
205 |
+
" 'limit_activity': 'None',\n",
|
206 |
+
" 'mood': 'Okay'},\n",
|
207 |
+
" 'plan': {'goal': 'Fix headache',\n",
|
208 |
+
" 'expectation': 'Fix headache',\n",
|
209 |
+
" 'alternative_treatment': 'None'}},\n",
|
210 |
+
" 'finished': True}"
|
211 |
+
]
|
212 |
+
},
|
213 |
+
"metadata": {},
|
214 |
+
"output_type": "display_data"
|
215 |
}
|
216 |
],
|
217 |
"source": [
|
|
|
247 |
" 'gender': 'male',\n",
|
248 |
" 'contact': '12345',\n",
|
249 |
" 'emergency_contact': 'Zoe, 67890'},\n",
|
250 |
+
" 'symptom': {'main_symptom': 'Headache', 'symptom_length': '2 days'},\n",
|
251 |
+
" 'pain': {'pain_location': 'Right head',\n",
|
252 |
+
" 'pain_side': 'Right',\n",
|
253 |
+
" 'pain_intensity': 2.0,\n",
|
254 |
+
" 'pain_description': 'Sharp',\n",
|
255 |
+
" 'start_time': '2 days ago',\n",
|
256 |
+
" 'radiation': False,\n",
|
257 |
+
" 'triggers': 'Cold',\n",
|
258 |
+
" 'symptom': 'No other symptoms'},\n",
|
259 |
+
" 'medical_hist': {'medical_condition': 'Sinus',\n",
|
260 |
+
" 'first_time': '2001-01-01',\n",
|
261 |
+
" 'surgery_history': 'None',\n",
|
262 |
+
" 'medication': 'Ibprofin',\n",
|
263 |
+
" 'allergy': 'None'},\n",
|
264 |
+
" 'family_hist': {'family_history': 'Mother had lung cancer at 45'},\n",
|
265 |
+
" 'social_hist': {'occupation': 'Data scientist',\n",
|
266 |
+
" 'smoke': False,\n",
|
267 |
+
" 'alcohol': False,\n",
|
268 |
+
" 'drug': False,\n",
|
269 |
+
" 'support_system': 'Unknown',\n",
|
270 |
+
" 'living_condition': 'Unknown'},\n",
|
271 |
+
" 'review_system': {'weight_change': 'None',\n",
|
272 |
+
" 'fever': False,\n",
|
273 |
+
" 'chill': False,\n",
|
274 |
+
" 'night_sweats': False,\n",
|
275 |
+
" 'sleep': 'Well',\n",
|
276 |
+
" 'gastrointestinal': 'Normal',\n",
|
277 |
+
" 'urinary': 'Normal'},\n",
|
278 |
+
" 'pain_manage': {'pain_medication': 'No',\n",
|
279 |
+
" 'specialist': False,\n",
|
280 |
+
" 'other_therapy': 'No',\n",
|
281 |
+
" 'effectiveness': 'Unknown'},\n",
|
282 |
+
" 'functional': {'life_quality': 'Good',\n",
|
283 |
+
" 'limit_activity': 'None',\n",
|
284 |
+
" 'mood': 'Okay'},\n",
|
285 |
+
" 'plan': {'goal': 'Fix headache',\n",
|
286 |
+
" 'expectation': 'Fix headache',\n",
|
287 |
+
" 'alternative_treatment': 'None'}}"
|
288 |
]
|
289 |
},
|
290 |
+
"execution_count": 4,
|
291 |
"metadata": {},
|
292 |
"output_type": "execute_result"
|
293 |
}
|
294 |
],
|
295 |
"source": [
|
296 |
+
"state[\"data\"]"
|
297 |
]
|
298 |
},
|
299 |
{
|