aiagents4pharma 1.13.1__py3-none-any.whl → 1.14.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aiagents4pharma/configs/config.yaml +2 -1
- aiagents4pharma/configs/talk2biomodels/__init__.py +1 -0
- aiagents4pharma/configs/talk2biomodels/agents/t2b_agent/default.yaml +2 -3
- aiagents4pharma/configs/talk2biomodels/tools/__init__.py +4 -0
- aiagents4pharma/configs/talk2biomodels/tools/ask_question/__init__.py +3 -0
- aiagents4pharma/talk2biomodels/__init__.py +1 -0
- aiagents4pharma/talk2biomodels/agents/t2b_agent.py +4 -2
- aiagents4pharma/talk2biomodels/api/__init__.py +6 -0
- aiagents4pharma/talk2biomodels/api/kegg.py +83 -0
- aiagents4pharma/talk2biomodels/api/ols.py +72 -0
- aiagents4pharma/talk2biomodels/api/uniprot.py +35 -0
- aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py +21 -6
- aiagents4pharma/talk2biomodels/tests/test_api.py +57 -0
- aiagents4pharma/talk2biomodels/tests/test_ask_question.py +44 -0
- aiagents4pharma/talk2biomodels/tests/test_get_annotation.py +171 -0
- aiagents4pharma/talk2biomodels/tests/test_getmodelinfo.py +26 -0
- aiagents4pharma/talk2biomodels/tests/test_integration.py +126 -0
- aiagents4pharma/talk2biomodels/tests/test_param_scan.py +68 -0
- aiagents4pharma/talk2biomodels/tests/test_search_models.py +28 -0
- aiagents4pharma/talk2biomodels/tests/test_simulate_model.py +39 -0
- aiagents4pharma/talk2biomodels/tests/test_steady_state.py +90 -0
- aiagents4pharma/talk2biomodels/tools/__init__.py +1 -0
- aiagents4pharma/talk2biomodels/tools/ask_question.py +29 -8
- aiagents4pharma/talk2biomodels/tools/get_annotation.py +304 -0
- aiagents4pharma/talk2biomodels/tools/load_arguments.py +114 -0
- aiagents4pharma/talk2biomodels/tools/parameter_scan.py +91 -96
- aiagents4pharma/talk2biomodels/tools/simulate_model.py +14 -81
- aiagents4pharma/talk2biomodels/tools/steady_state.py +48 -89
- {aiagents4pharma-1.13.1.dist-info → aiagents4pharma-1.14.1.dist-info}/METADATA +1 -1
- {aiagents4pharma-1.13.1.dist-info → aiagents4pharma-1.14.1.dist-info}/RECORD +33 -17
- aiagents4pharma/talk2biomodels/tests/test_langgraph.py +0 -384
- {aiagents4pharma-1.13.1.dist-info → aiagents4pharma-1.14.1.dist-info}/LICENSE +0 -0
- {aiagents4pharma-1.13.1.dist-info → aiagents4pharma-1.14.1.dist-info}/WHEEL +0 -0
- {aiagents4pharma-1.13.1.dist-info → aiagents4pharma-1.14.1.dist-info}/top_level.txt +0 -0
@@ -1,31 +1,47 @@
|
|
1
1
|
aiagents4pharma/__init__.py,sha256=5muWWIg89VHPybfxonO_5xOMJPasKNsGdQRhozDaEmk,177
|
2
2
|
aiagents4pharma/configs/__init__.py,sha256=hNkSrXw1Ix1HhkGn_aaidr2coBYySfM0Hm_pMeRcX7k,76
|
3
|
-
aiagents4pharma/configs/config.yaml,sha256=
|
4
|
-
aiagents4pharma/configs/talk2biomodels/__init__.py,sha256=
|
3
|
+
aiagents4pharma/configs/config.yaml,sha256=4t7obD0gOSfqnDDZZBB53ZC7zsmk7QDcM7T_1Hf1wIQ,112
|
4
|
+
aiagents4pharma/configs/talk2biomodels/__init__.py,sha256=safyFKhkd5Wlirl9dMZIHWDLTpY2oLw9wjIM7ZtLIHk,88
|
5
5
|
aiagents4pharma/configs/talk2biomodels/agents/__init__.py,sha256=_ZoG8snICK2bidWtc2KOGs738LWg9_r66V9mOMnEb-E,71
|
6
6
|
aiagents4pharma/configs/talk2biomodels/agents/t2b_agent/__init__.py,sha256=-fAORvyFmG2iSvFOFDixmt9OTQRR58y89uhhu2EgbA8,46
|
7
|
-
aiagents4pharma/configs/talk2biomodels/agents/t2b_agent/default.yaml,sha256=
|
8
|
-
aiagents4pharma/talk2biomodels/__init__.py,sha256=
|
7
|
+
aiagents4pharma/configs/talk2biomodels/agents/t2b_agent/default.yaml,sha256=w0ES09GSuY61x7C9FSx9auwhoGc6xVeG51roe6tT4Bk,317
|
8
|
+
aiagents4pharma/configs/talk2biomodels/tools/__init__.py,sha256=WxK7h5n39l-NSMvjLZyxDqzwWlVA6mQ69gzsbJ17vEk,72
|
9
|
+
aiagents4pharma/configs/talk2biomodels/tools/ask_question/__init__.py,sha256=-fAORvyFmG2iSvFOFDixmt9OTQRR58y89uhhu2EgbA8,46
|
10
|
+
aiagents4pharma/talk2biomodels/__init__.py,sha256=2ICwVh1u07SZv31Jd2DKHobauOxWNWY29_Gqq3kOnNQ,159
|
9
11
|
aiagents4pharma/talk2biomodels/agents/__init__.py,sha256=sn5-fREjMdEvb-OUan3iOqrgYGjplNx3J8hYOaW0Po8,128
|
10
|
-
aiagents4pharma/talk2biomodels/agents/t2b_agent.py,sha256=
|
12
|
+
aiagents4pharma/talk2biomodels/agents/t2b_agent.py,sha256=13aSlBZBWtjXOLq7c99u33c923fi2Ab0VW--eX5gF-o,3366
|
13
|
+
aiagents4pharma/talk2biomodels/api/__init__.py,sha256=_GmDQqDLYpsUPUeE1nBNlT5AI9oTXIcqgOfNfvmonqA,123
|
14
|
+
aiagents4pharma/talk2biomodels/api/kegg.py,sha256=QzYDAfJ16E7tbHGxP8ZNWRizMkMRS_HJuucueXEC1Gg,2943
|
15
|
+
aiagents4pharma/talk2biomodels/api/ols.py,sha256=qq0Qy-gJDxanQW-HfCChDsTQsY1M41ua8hMlTnfuzrA,2202
|
16
|
+
aiagents4pharma/talk2biomodels/api/uniprot.py,sha256=aPUAVBR7UYXDuuhDpKezAK2aTMzo-NxFYFq6C0W5u6U,1175
|
11
17
|
aiagents4pharma/talk2biomodels/models/__init__.py,sha256=5fTHHm3PVloYPNKXbgNlcPgv3-u28ZquxGydFYDfhJA,122
|
12
18
|
aiagents4pharma/talk2biomodels/models/basico_model.py,sha256=PH25FTOuUjsmw_UUxoRb-4kptOYpicEn4GqS0phS3nk,4807
|
13
19
|
aiagents4pharma/talk2biomodels/models/sys_bio_model.py,sha256=JeoiGQAvQABHnG0wKR2XBmmxqQdtgO6kxaLDUTUmr1s,2001
|
14
20
|
aiagents4pharma/talk2biomodels/states/__init__.py,sha256=YLg1-N0D9qyRRLRqwqfLCLAqZYDtMVZTfI8Y0b_4tbA,139
|
15
|
-
aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py,sha256=
|
21
|
+
aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py,sha256=WriIk_MH9XyUD-WAcIFVjHZMegwrh2-zQpXleTzpHEU,1332
|
16
22
|
aiagents4pharma/talk2biomodels/tests/__init__.py,sha256=Jbw5tJxSrjGoaK5IX3pJWDCNzhrVQ10lkYq2oQ_KQD8,45
|
23
|
+
aiagents4pharma/talk2biomodels/tests/test_api.py,sha256=7Kz2r5F5tjmn3F0LoM33oP-21W633936YHiyf5toGg0,1716
|
24
|
+
aiagents4pharma/talk2biomodels/tests/test_ask_question.py,sha256=yRkKK9HLB1bGGWm_WwOckwaUmmRfRAD9z2NFFGLIGTY,1560
|
17
25
|
aiagents4pharma/talk2biomodels/tests/test_basico_model.py,sha256=y82fpTJMPHwtXxlle1cGQ_2Bewwpxi0aJSVrVAYLhN0,2060
|
18
|
-
aiagents4pharma/talk2biomodels/tests/
|
26
|
+
aiagents4pharma/talk2biomodels/tests/test_get_annotation.py,sha256=mKOacH28OB6xpFPygAlhBUQS93gnI5j-jAfSGu6uQMI,7465
|
27
|
+
aiagents4pharma/talk2biomodels/tests/test_getmodelinfo.py,sha256=6kChSc_MCnzXlDao_R8pKdhIELlg3MZrUa7hg8piJ4E,883
|
28
|
+
aiagents4pharma/talk2biomodels/tests/test_integration.py,sha256=ZsBXWSFLIcdzrO8obLJx8Ib2f9AAW3BI7H9Eqjdc5to,5057
|
29
|
+
aiagents4pharma/talk2biomodels/tests/test_param_scan.py,sha256=vRbnn4uVWFbfZbU4gVCjHi5WDCUrErut8ElzAPE5y84,2648
|
30
|
+
aiagents4pharma/talk2biomodels/tests/test_search_models.py,sha256=8ODFubLxWYD3I3KQWuUnJ2GZRzMjFpXInFBLxKxG_ME,929
|
31
|
+
aiagents4pharma/talk2biomodels/tests/test_simulate_model.py,sha256=GjLE1DZpcKUAFSmoHD86vkfK0b5LJPM8a4WYyraazig,1487
|
32
|
+
aiagents4pharma/talk2biomodels/tests/test_steady_state.py,sha256=zt15KQoQku6jyzvpJXwINGTyhEnQl8wX81ueHlxnUCA,3467
|
19
33
|
aiagents4pharma/talk2biomodels/tests/test_sys_bio_model.py,sha256=HSmBBViMi0jYf4gWX21IbppAfDzG0nr_S3KtKS9fZVQ,2165
|
20
|
-
aiagents4pharma/talk2biomodels/tools/__init__.py,sha256
|
21
|
-
aiagents4pharma/talk2biomodels/tools/ask_question.py,sha256=
|
34
|
+
aiagents4pharma/talk2biomodels/tools/__init__.py,sha256=ZiOdSFaeHW6y3hdtBfsKf0vSb3MuCLuy9MDyjARggb4,322
|
35
|
+
aiagents4pharma/talk2biomodels/tools/ask_question.py,sha256=hWXg7o0sTMDWH1ZnxtashTALvXpvNoaomfcniEhw-Bw,4684
|
22
36
|
aiagents4pharma/talk2biomodels/tools/custom_plotter.py,sha256=HWwKTX3o4dk0GcRVTO2hPrFSu98mtJ4TKC_hbHXOe1c,4018
|
37
|
+
aiagents4pharma/talk2biomodels/tools/get_annotation.py,sha256=jCGkidvafuk1YzAH9GFwaVUF35maXTjg6XqBg_zLk44,12475
|
23
38
|
aiagents4pharma/talk2biomodels/tools/get_modelinfo.py,sha256=qA-4FOI-O728Nmn7s8JJ8HKwxvA9MZbst7NkPKTAMV4,5391
|
39
|
+
aiagents4pharma/talk2biomodels/tools/load_arguments.py,sha256=bffNIlBDTCSFYiZprA73yi8Jbb8z3Oh2decVNh1UnZc,4162
|
24
40
|
aiagents4pharma/talk2biomodels/tools/load_biomodel.py,sha256=pyVzLQoMnuJYEwsjeOlqcUrbU1F1Z-pNlgkhFaoKpy0,689
|
25
|
-
aiagents4pharma/talk2biomodels/tools/parameter_scan.py,sha256=
|
41
|
+
aiagents4pharma/talk2biomodels/tools/parameter_scan.py,sha256=aNh94LgBgVXBIczuNkbSsOZ9j54YVEdZWmZbZr7Nk8k,12465
|
26
42
|
aiagents4pharma/talk2biomodels/tools/search_models.py,sha256=Iq2ddofOOfZYtAurCISq3bAq5rbwB3l_rL1lgEFyFCI,2653
|
27
|
-
aiagents4pharma/talk2biomodels/tools/simulate_model.py,sha256=
|
28
|
-
aiagents4pharma/talk2biomodels/tools/steady_state.py,sha256=
|
43
|
+
aiagents4pharma/talk2biomodels/tools/simulate_model.py,sha256=qXs9lg9XgA7EaRiX3wBS8w_ug8tI-G3pzhcRg6dTRio,5060
|
44
|
+
aiagents4pharma/talk2biomodels/tools/steady_state.py,sha256=j3ckuNlUtv7lT922MbN0JhT9H0JpWAdx2mLPwao6uu8,7123
|
29
45
|
aiagents4pharma/talk2cells/__init__.py,sha256=zmOP5RAhabgKIQP-W4P4qKME2tG3fhAXM3MeO5_H8kE,120
|
30
46
|
aiagents4pharma/talk2cells/agents/__init__.py,sha256=38nK2a_lEFRjO3qD6Fo9a3983ZCYat6hmJKWY61y2Mo,128
|
31
47
|
aiagents4pharma/talk2cells/agents/scp_agent.py,sha256=gDMfhUNWHa_XWOqm1Ql6yLAdI_7bnIk5sRYn43H2sYk,3090
|
@@ -77,8 +93,8 @@ aiagents4pharma/talk2knowledgegraphs/utils/embeddings/sentence_transformer.py,sh
|
|
77
93
|
aiagents4pharma/talk2knowledgegraphs/utils/enrichments/__init__.py,sha256=tW426knki2DBIHcWyF_K04iMMdbpIn_e_TpPmTgz2dI,113
|
78
94
|
aiagents4pharma/talk2knowledgegraphs/utils/enrichments/enrichments.py,sha256=Bx8x6zzk5614ApWB90N_iv4_Y_Uq0-KwUeBwYSdQMU4,924
|
79
95
|
aiagents4pharma/talk2knowledgegraphs/utils/enrichments/ollama.py,sha256=8eoxR-VHo0G7ReQIwje7xEhE-SJlHdef7_wJRpnvFIc,4116
|
80
|
-
aiagents4pharma-1.
|
81
|
-
aiagents4pharma-1.
|
82
|
-
aiagents4pharma-1.
|
83
|
-
aiagents4pharma-1.
|
84
|
-
aiagents4pharma-1.
|
96
|
+
aiagents4pharma-1.14.1.dist-info/LICENSE,sha256=IcIbyB1Hyk5ZDah03VNQvJkbNk2hkBCDqQ8qtnCvB4Q,1077
|
97
|
+
aiagents4pharma-1.14.1.dist-info/METADATA,sha256=zwewL1DN0qEv3L7l901tNdc6PaX1wrKvRIkZ0dFIqHU,8609
|
98
|
+
aiagents4pharma-1.14.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
99
|
+
aiagents4pharma-1.14.1.dist-info/top_level.txt,sha256=-AH8rMmrSnJtq7HaAObS78UU-cTCwvX660dSxeM7a0A,16
|
100
|
+
aiagents4pharma-1.14.1.dist-info/RECORD,,
|
@@ -1,384 +0,0 @@
|
|
1
|
-
'''
|
2
|
-
Test cases for Talk2Biomodels.
|
3
|
-
'''
|
4
|
-
|
5
|
-
import pandas as pd
|
6
|
-
from langchain_core.messages import HumanMessage, ToolMessage
|
7
|
-
from ..agents.t2b_agent import get_app
|
8
|
-
|
9
|
-
def test_get_modelinfo_tool():
|
10
|
-
'''
|
11
|
-
Test the get_modelinfo tool.
|
12
|
-
'''
|
13
|
-
unique_id = 12345
|
14
|
-
app = get_app(unique_id)
|
15
|
-
config = {"configurable": {"thread_id": unique_id}}
|
16
|
-
# Update state
|
17
|
-
app.update_state(config,
|
18
|
-
{"sbml_file_path": ["aiagents4pharma/talk2biomodels/tests/BIOMD0000000449_url.xml"]})
|
19
|
-
prompt = "Extract all relevant information from the uploaded model."
|
20
|
-
# Test the tool get_modelinfo
|
21
|
-
response = app.invoke(
|
22
|
-
{"messages": [HumanMessage(content=prompt)]},
|
23
|
-
config=config
|
24
|
-
)
|
25
|
-
assistant_msg = response["messages"][-1].content
|
26
|
-
# Check if the assistant message is a string
|
27
|
-
assert isinstance(assistant_msg, str)
|
28
|
-
|
29
|
-
def test_search_models_tool():
|
30
|
-
'''
|
31
|
-
Test the search_models tool.
|
32
|
-
'''
|
33
|
-
unique_id = 12345
|
34
|
-
app = get_app(unique_id)
|
35
|
-
config = {"configurable": {"thread_id": unique_id}}
|
36
|
-
# Update state
|
37
|
-
app.update_state(config, {"llm_model": "gpt-4o-mini"})
|
38
|
-
prompt = "Search for models on Crohn's disease."
|
39
|
-
# Test the tool get_modelinfo
|
40
|
-
response = app.invoke(
|
41
|
-
{"messages": [HumanMessage(content=prompt)]},
|
42
|
-
config=config
|
43
|
-
)
|
44
|
-
assistant_msg = response["messages"][-1].content
|
45
|
-
# Check if the assistant message is a string
|
46
|
-
assert isinstance(assistant_msg, str)
|
47
|
-
# Check if the assistant message contains the
|
48
|
-
# biomodel id BIO0000000537
|
49
|
-
assert "BIOMD0000000537" in assistant_msg
|
50
|
-
|
51
|
-
def test_ask_question_tool():
|
52
|
-
'''
|
53
|
-
Test the ask_question tool without the simulation results.
|
54
|
-
'''
|
55
|
-
unique_id = 12345
|
56
|
-
app = get_app(unique_id, llm_model='gpt-4o-mini')
|
57
|
-
config = {"configurable": {"thread_id": unique_id}}
|
58
|
-
|
59
|
-
##########################################
|
60
|
-
# Test ask_question tool when simulation
|
61
|
-
# results are not available i.e. the
|
62
|
-
# simulation has not been run. In this
|
63
|
-
# case, the tool should return an error
|
64
|
-
##########################################
|
65
|
-
# Update state
|
66
|
-
app.update_state(config, {"llm_model": "gpt-4o-mini"})
|
67
|
-
# Define the prompt
|
68
|
-
prompt = "Call the ask_question tool to answer the "
|
69
|
-
prompt += "question: What is the concentration of CRP "
|
70
|
-
prompt += "in serum at 1000 hours? The simulation name "
|
71
|
-
prompt += "is `simulation_name`."
|
72
|
-
# Invoke the tool
|
73
|
-
app.invoke(
|
74
|
-
{"messages": [HumanMessage(content=prompt)]},
|
75
|
-
config=config
|
76
|
-
)
|
77
|
-
# Get the messages from the current state
|
78
|
-
# and reverse the order
|
79
|
-
current_state = app.get_state(config)
|
80
|
-
reversed_messages = current_state.values["messages"][::-1]
|
81
|
-
# Loop through the reversed messages until a
|
82
|
-
# ToolMessage is found.
|
83
|
-
for msg in reversed_messages:
|
84
|
-
# Assert that the message is a ToolMessage
|
85
|
-
# and its status is "error"
|
86
|
-
if isinstance(msg, ToolMessage):
|
87
|
-
assert msg.status == "error"
|
88
|
-
|
89
|
-
def test_simulate_model_tool():
|
90
|
-
'''
|
91
|
-
Test the simulate_model tool when simulating
|
92
|
-
multiple models.
|
93
|
-
'''
|
94
|
-
unique_id = 123
|
95
|
-
app = get_app(unique_id)
|
96
|
-
config = {"configurable": {"thread_id": unique_id}}
|
97
|
-
app.update_state(config, {"llm_model": "gpt-4o-mini"})
|
98
|
-
# Upload a model to the state
|
99
|
-
app.update_state(config,
|
100
|
-
{"sbml_file_path": ["aiagents4pharma/talk2biomodels/tests/BIOMD0000000449_url.xml"]})
|
101
|
-
prompt = "Simulate model 64 and the uploaded model"
|
102
|
-
# Invoke the agent
|
103
|
-
app.invoke(
|
104
|
-
{"messages": [HumanMessage(content=prompt)]},
|
105
|
-
config=config
|
106
|
-
)
|
107
|
-
current_state = app.get_state(config)
|
108
|
-
dic_simulated_data = current_state.values["dic_simulated_data"]
|
109
|
-
# Check if the dic_simulated_data is a list
|
110
|
-
assert isinstance(dic_simulated_data, list)
|
111
|
-
# Check if the length of the dic_simulated_data is 2
|
112
|
-
assert len(dic_simulated_data) == 2
|
113
|
-
# Check if the source of the first model is 64
|
114
|
-
assert dic_simulated_data[0]['source'] == 64
|
115
|
-
# Check if the source of the second model is upload
|
116
|
-
assert dic_simulated_data[1]['source'] == "upload"
|
117
|
-
# Check if the data of the first model contains
|
118
|
-
assert '1,3-bisphosphoglycerate' in dic_simulated_data[0]['data']
|
119
|
-
# Check if the data of the second model contains
|
120
|
-
assert 'mTORC2' in dic_simulated_data[1]['data']
|
121
|
-
|
122
|
-
def test_param_scan_tool():
|
123
|
-
'''
|
124
|
-
In this test, we will test the parameter_scan tool.
|
125
|
-
We will prompt it to scan the parameter `kIL6RBind`
|
126
|
-
from 1 to 100 in steps of 10, record the changes
|
127
|
-
in the concentration of the species `Ab{serum}` in
|
128
|
-
model 537.
|
129
|
-
|
130
|
-
We will pass the inaccuarate parameter (`KIL6Rbind`)
|
131
|
-
and species names (just `Ab`) to the tool to test
|
132
|
-
if it can deal with it.
|
133
|
-
|
134
|
-
We expect the agent to first invoke the parameter_scan
|
135
|
-
tool and raise an error. It will then invoke another
|
136
|
-
tool get_modelinfo to get the correct parameter
|
137
|
-
and species names. Finally, the agent will reinvoke
|
138
|
-
the parameter_scan tool with the correct parameter
|
139
|
-
and species names.
|
140
|
-
|
141
|
-
'''
|
142
|
-
unique_id = 123
|
143
|
-
app = get_app(unique_id)
|
144
|
-
config = {"configurable": {"thread_id": unique_id}}
|
145
|
-
app.update_state(config, {"llm_model": "gpt-4o-mini"})
|
146
|
-
prompt = """How will the value of Ab in model 537 change
|
147
|
-
if the param kIL6Rbind is varied from 1 to 100 in steps of 10?
|
148
|
-
Set the initial `DoseQ2W` concentration to 300. Also, reset
|
149
|
-
the IL6{serum} concentration to 100 every 500 hours and assume
|
150
|
-
that the model is simulated for 2016 hours with an interval of 2016."""
|
151
|
-
# Invoke the agent
|
152
|
-
app.invoke(
|
153
|
-
{"messages": [HumanMessage(content=prompt)]},
|
154
|
-
config=config
|
155
|
-
)
|
156
|
-
current_state = app.get_state(config)
|
157
|
-
reversed_messages = current_state.values["messages"][::-1]
|
158
|
-
# Loop through the reversed messages until a
|
159
|
-
# ToolMessage is found.
|
160
|
-
df = pd.DataFrame(columns=['name', 'status', 'content'])
|
161
|
-
names = []
|
162
|
-
statuses = []
|
163
|
-
contents = []
|
164
|
-
for msg in reversed_messages:
|
165
|
-
# Assert that the message is a ToolMessage
|
166
|
-
# and its status is "error"
|
167
|
-
if not isinstance(msg, ToolMessage):
|
168
|
-
continue
|
169
|
-
names.append(msg.name)
|
170
|
-
statuses.append(msg.status)
|
171
|
-
contents.append(msg.content)
|
172
|
-
df = pd.DataFrame({'name': names, 'status': statuses, 'content': contents})
|
173
|
-
# print (df)
|
174
|
-
assert any((df["status"] == "error") &
|
175
|
-
(df["name"] == "parameter_scan") &
|
176
|
-
(df["content"].str.startswith("Error: ValueError('Invalid parameter name:")))
|
177
|
-
assert any((df["status"] == "success") &
|
178
|
-
(df["name"] == "parameter_scan") &
|
179
|
-
(df["content"].str.startswith("Parameter scan results of")))
|
180
|
-
assert any((df["status"] == "success") &
|
181
|
-
(df["name"] == "get_modelinfo"))
|
182
|
-
|
183
|
-
def test_steady_state_tool():
|
184
|
-
'''
|
185
|
-
Test the steady_state tool.
|
186
|
-
'''
|
187
|
-
unique_id = 123
|
188
|
-
app = get_app(unique_id)
|
189
|
-
config = {"configurable": {"thread_id": unique_id}}
|
190
|
-
app.update_state(config, {"llm_model": "gpt-4o-mini"})
|
191
|
-
#########################################################
|
192
|
-
# In this case, we will test if the tool returns an error
|
193
|
-
# when the model does not achieve a steady state. The tool
|
194
|
-
# status should be "error".
|
195
|
-
prompt = """Run a steady state analysis of model 537."""
|
196
|
-
# Invoke the agent
|
197
|
-
app.invoke(
|
198
|
-
{"messages": [HumanMessage(content=prompt)]},
|
199
|
-
config=config
|
200
|
-
)
|
201
|
-
current_state = app.get_state(config)
|
202
|
-
reversed_messages = current_state.values["messages"][::-1]
|
203
|
-
tool_msg_status = None
|
204
|
-
for msg in reversed_messages:
|
205
|
-
# Assert that the status of the
|
206
|
-
# ToolMessage is "error"
|
207
|
-
if isinstance(msg, ToolMessage):
|
208
|
-
# print (msg)
|
209
|
-
tool_msg_status = msg.status
|
210
|
-
break
|
211
|
-
assert tool_msg_status == "error"
|
212
|
-
#########################################################
|
213
|
-
# In this case, we will test if the tool is indeed invoked
|
214
|
-
# successfully
|
215
|
-
prompt = """Run a steady state analysis of model 64.
|
216
|
-
Set the initial concentration of `Pyruvate` to 0.2. The
|
217
|
-
concentration of `NAD` resets to 100 every 2 time units."""
|
218
|
-
# Invoke the agent
|
219
|
-
app.invoke(
|
220
|
-
{"messages": [HumanMessage(content=prompt)]},
|
221
|
-
config=config
|
222
|
-
)
|
223
|
-
# Loop through the reversed messages until a
|
224
|
-
# ToolMessage is found.
|
225
|
-
current_state = app.get_state(config)
|
226
|
-
reversed_messages = current_state.values["messages"][::-1]
|
227
|
-
steady_state_invoked = False
|
228
|
-
for msg in reversed_messages:
|
229
|
-
# Assert that the message is a ToolMessage
|
230
|
-
# and its status is "error"
|
231
|
-
if isinstance(msg, ToolMessage):
|
232
|
-
print (msg)
|
233
|
-
if msg.name == "steady_state" and msg.status != "error":
|
234
|
-
steady_state_invoked = True
|
235
|
-
break
|
236
|
-
assert steady_state_invoked
|
237
|
-
#########################################################
|
238
|
-
# In this case, we will test if the `ask_question` tool is
|
239
|
-
# invoked upon asking a question about the already generated
|
240
|
-
# steady state results
|
241
|
-
prompt = """What is the Phosphoenolpyruvate concentration
|
242
|
-
at the steady state? Show onlyconcentration, rounded to
|
243
|
-
2 decimal places. For example, if the concentration is
|
244
|
-
0.123456, your response should be `0.12`. Do not return
|
245
|
-
any other information."""
|
246
|
-
# Invoke the agent
|
247
|
-
response = app.invoke(
|
248
|
-
{"messages": [HumanMessage(content=prompt)]},
|
249
|
-
config=config
|
250
|
-
)
|
251
|
-
assistant_msg = response["messages"][-1].content
|
252
|
-
current_state = app.get_state(config)
|
253
|
-
reversed_messages = current_state.values["messages"][::-1]
|
254
|
-
# Loop through the reversed messages until a
|
255
|
-
# ToolMessage is found.
|
256
|
-
ask_questool_invoked = False
|
257
|
-
for msg in reversed_messages:
|
258
|
-
# Assert that the message is a ToolMessage
|
259
|
-
# and its status is "error"
|
260
|
-
if isinstance(msg, ToolMessage):
|
261
|
-
if msg.name == "ask_question":
|
262
|
-
ask_questool_invoked = True
|
263
|
-
break
|
264
|
-
assert ask_questool_invoked
|
265
|
-
assert "0.06" in assistant_msg
|
266
|
-
|
267
|
-
def test_integration():
|
268
|
-
'''
|
269
|
-
Test the integration of the tools.
|
270
|
-
'''
|
271
|
-
unique_id = 1234567
|
272
|
-
app = get_app(unique_id)
|
273
|
-
config = {"configurable": {"thread_id": unique_id}}
|
274
|
-
app.update_state(config, {"llm_model": "gpt-4o-mini"})
|
275
|
-
# ##########################################
|
276
|
-
# ## Test simulate_model tool
|
277
|
-
# ##########################################
|
278
|
-
prompt = "Simulate the model 537 for 2016 hours and intervals"
|
279
|
-
prompt += " 2016 with an initial concentration of `DoseQ2W` "
|
280
|
-
prompt += "set to 300 and `Dose` set to 0. Reset the concentration"
|
281
|
-
prompt += " of `NAD` to 100 every 500 hours."
|
282
|
-
# Test the tool get_modelinfo
|
283
|
-
response = app.invoke(
|
284
|
-
{"messages": [HumanMessage(content=prompt)]},
|
285
|
-
config=config
|
286
|
-
)
|
287
|
-
assistant_msg = response["messages"][-1].content
|
288
|
-
print (assistant_msg)
|
289
|
-
# Check if the assistant message is a string
|
290
|
-
assert isinstance(assistant_msg, str)
|
291
|
-
##########################################
|
292
|
-
# Test ask_question tool when simulation
|
293
|
-
# results are available
|
294
|
-
##########################################
|
295
|
-
# Update state
|
296
|
-
app.update_state(config, {"llm_model": "gpt-4o-mini"})
|
297
|
-
prompt = """What is the concentration of CRP
|
298
|
-
in serum after 1000 time points?"""
|
299
|
-
# Test the tool get_modelinfo
|
300
|
-
response = app.invoke(
|
301
|
-
{"messages": [HumanMessage(content=prompt)]},
|
302
|
-
config=config
|
303
|
-
)
|
304
|
-
assistant_msg = response["messages"][-1].content
|
305
|
-
# print (assistant_msg)
|
306
|
-
# Check if the assistant message is a string
|
307
|
-
assert "1.7" in assistant_msg
|
308
|
-
|
309
|
-
##########################################
|
310
|
-
# Test custom_plotter tool when the
|
311
|
-
# simulation results are available
|
312
|
-
##########################################
|
313
|
-
prompt = "Plot only CRP related species."
|
314
|
-
|
315
|
-
# Update state
|
316
|
-
app.update_state(config, {"llm_model": "gpt-4o-mini"}
|
317
|
-
)
|
318
|
-
# Test the tool get_modelinfo
|
319
|
-
response = app.invoke(
|
320
|
-
{"messages": [HumanMessage(content=prompt)]},
|
321
|
-
config=config
|
322
|
-
)
|
323
|
-
assistant_msg = response["messages"][-1].content
|
324
|
-
current_state = app.get_state(config)
|
325
|
-
# Get the messages from the current state
|
326
|
-
# and reverse the order
|
327
|
-
reversed_messages = current_state.values["messages"][::-1]
|
328
|
-
# Loop through the reversed messages
|
329
|
-
# until a ToolMessage is found.
|
330
|
-
expected_header = ['Time', 'CRP{serum}', 'CRPExtracellular']
|
331
|
-
expected_header += ['CRP Suppression (%)', 'CRP (% of baseline)']
|
332
|
-
expected_header += ['CRP{liver}']
|
333
|
-
predicted_artifact = []
|
334
|
-
for msg in reversed_messages:
|
335
|
-
if isinstance(msg, ToolMessage):
|
336
|
-
# Work on the message if it is a ToolMessage
|
337
|
-
# These may contain additional visuals that
|
338
|
-
# need to be displayed to the user.
|
339
|
-
if msg.name == "custom_plotter":
|
340
|
-
predicted_artifact = msg.artifact
|
341
|
-
break
|
342
|
-
# Convert the artifact into a pandas dataframe
|
343
|
-
# for easy comparison
|
344
|
-
df = pd.DataFrame(predicted_artifact)
|
345
|
-
# Extract the headers from the dataframe
|
346
|
-
predicted_header = df.columns.tolist()
|
347
|
-
# Check if the header is in the expected_header
|
348
|
-
# assert expected_header in predicted_artifact
|
349
|
-
assert set(expected_header).issubset(set(predicted_header))
|
350
|
-
##########################################
|
351
|
-
# Test custom_plotter tool when the
|
352
|
-
# simulation results are available but
|
353
|
-
# the species is not available
|
354
|
-
##########################################
|
355
|
-
prompt = """Make a custom plot showing the
|
356
|
-
concentration of the species `TP53` over
|
357
|
-
time. Do not show any other species."""
|
358
|
-
# Update state
|
359
|
-
app.update_state(config, {"llm_model": "gpt-4o-mini"}
|
360
|
-
)
|
361
|
-
# Test the tool get_modelinfo
|
362
|
-
response = app.invoke(
|
363
|
-
{"messages": [HumanMessage(content=prompt)]},
|
364
|
-
config=config
|
365
|
-
)
|
366
|
-
assistant_msg = response["messages"][-1].content
|
367
|
-
# print (response["messages"])
|
368
|
-
current_state = app.get_state(config)
|
369
|
-
# Get the messages from the current state
|
370
|
-
# and reverse the order
|
371
|
-
reversed_messages = current_state.values["messages"][::-1]
|
372
|
-
# Loop through the reversed messages until a
|
373
|
-
# ToolMessage is found.
|
374
|
-
predicted_artifact = []
|
375
|
-
for msg in reversed_messages:
|
376
|
-
if isinstance(msg, ToolMessage):
|
377
|
-
# Work on the message if it is a ToolMessage
|
378
|
-
# These may contain additional visuals that
|
379
|
-
# need to be displayed to the user.
|
380
|
-
if msg.name == "custom_plotter":
|
381
|
-
predicted_artifact = msg.artifact
|
382
|
-
break
|
383
|
-
# Check if the the predicted artifact is `None`
|
384
|
-
assert predicted_artifact is None
|
File without changes
|
File without changes
|
File without changes
|