aiagents4pharma 1.9.0__py3-none-any.whl → 1.15.0__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.
Files changed (66) hide show
  1. aiagents4pharma/__init__.py +9 -6
  2. aiagents4pharma/configs/config.yaml +2 -1
  3. aiagents4pharma/configs/talk2biomodels/__init__.py +1 -0
  4. aiagents4pharma/configs/talk2biomodels/agents/t2b_agent/default.yaml +9 -3
  5. aiagents4pharma/configs/talk2biomodels/tools/__init__.py +4 -0
  6. aiagents4pharma/configs/talk2biomodels/tools/ask_question/__init__.py +3 -0
  7. aiagents4pharma/talk2biomodels/__init__.py +1 -0
  8. aiagents4pharma/talk2biomodels/agents/t2b_agent.py +14 -11
  9. aiagents4pharma/talk2biomodels/api/__init__.py +6 -0
  10. aiagents4pharma/talk2biomodels/api/kegg.py +83 -0
  11. aiagents4pharma/talk2biomodels/api/ols.py +72 -0
  12. aiagents4pharma/talk2biomodels/api/uniprot.py +35 -0
  13. aiagents4pharma/talk2biomodels/models/basico_model.py +29 -32
  14. aiagents4pharma/talk2biomodels/models/sys_bio_model.py +9 -6
  15. aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py +24 -7
  16. aiagents4pharma/talk2biomodels/tests/test_api.py +57 -0
  17. aiagents4pharma/talk2biomodels/tests/test_ask_question.py +44 -0
  18. aiagents4pharma/talk2biomodels/tests/test_basico_model.py +7 -8
  19. aiagents4pharma/talk2biomodels/tests/test_get_annotation.py +171 -0
  20. aiagents4pharma/talk2biomodels/tests/test_getmodelinfo.py +26 -0
  21. aiagents4pharma/talk2biomodels/tests/test_integration.py +126 -0
  22. aiagents4pharma/talk2biomodels/tests/test_param_scan.py +68 -0
  23. aiagents4pharma/talk2biomodels/tests/test_query_article.py +76 -0
  24. aiagents4pharma/talk2biomodels/tests/test_search_models.py +28 -0
  25. aiagents4pharma/talk2biomodels/tests/test_simulate_model.py +39 -0
  26. aiagents4pharma/talk2biomodels/tests/test_steady_state.py +90 -0
  27. aiagents4pharma/talk2biomodels/tests/test_sys_bio_model.py +13 -7
  28. aiagents4pharma/talk2biomodels/tools/__init__.py +4 -0
  29. aiagents4pharma/talk2biomodels/tools/ask_question.py +59 -25
  30. aiagents4pharma/talk2biomodels/tools/get_annotation.py +304 -0
  31. aiagents4pharma/talk2biomodels/tools/get_modelinfo.py +5 -3
  32. aiagents4pharma/talk2biomodels/tools/load_arguments.py +114 -0
  33. aiagents4pharma/talk2biomodels/tools/parameter_scan.py +287 -0
  34. aiagents4pharma/talk2biomodels/tools/query_article.py +59 -0
  35. aiagents4pharma/talk2biomodels/tools/simulate_model.py +20 -89
  36. aiagents4pharma/talk2biomodels/tools/steady_state.py +167 -0
  37. aiagents4pharma/talk2competitors/__init__.py +5 -0
  38. aiagents4pharma/talk2competitors/agents/__init__.py +6 -0
  39. aiagents4pharma/talk2competitors/agents/main_agent.py +130 -0
  40. aiagents4pharma/talk2competitors/agents/s2_agent.py +75 -0
  41. aiagents4pharma/talk2competitors/config/__init__.py +5 -0
  42. aiagents4pharma/talk2competitors/config/config.py +110 -0
  43. aiagents4pharma/talk2competitors/state/__init__.py +5 -0
  44. aiagents4pharma/talk2competitors/state/state_talk2competitors.py +32 -0
  45. aiagents4pharma/talk2competitors/tests/__init__.py +3 -0
  46. aiagents4pharma/talk2competitors/tests/test_langgraph.py +274 -0
  47. aiagents4pharma/talk2competitors/tools/__init__.py +7 -0
  48. aiagents4pharma/talk2competitors/tools/s2/__init__.py +8 -0
  49. aiagents4pharma/talk2competitors/tools/s2/display_results.py +25 -0
  50. aiagents4pharma/talk2competitors/tools/s2/multi_paper_rec.py +132 -0
  51. aiagents4pharma/talk2competitors/tools/s2/search.py +119 -0
  52. aiagents4pharma/talk2competitors/tools/s2/single_paper_rec.py +141 -0
  53. aiagents4pharma/talk2knowledgegraphs/__init__.py +2 -1
  54. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_enrichments.py +39 -0
  55. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_ollama.py +117 -0
  56. aiagents4pharma/talk2knowledgegraphs/utils/__init__.py +5 -0
  57. aiagents4pharma/talk2knowledgegraphs/utils/enrichments/__init__.py +5 -0
  58. aiagents4pharma/talk2knowledgegraphs/utils/enrichments/enrichments.py +36 -0
  59. aiagents4pharma/talk2knowledgegraphs/utils/enrichments/ollama.py +123 -0
  60. {aiagents4pharma-1.9.0.dist-info → aiagents4pharma-1.15.0.dist-info}/METADATA +42 -23
  61. aiagents4pharma-1.15.0.dist-info/RECORD +102 -0
  62. aiagents4pharma/talk2biomodels/tests/test_langgraph.py +0 -240
  63. aiagents4pharma-1.9.0.dist-info/RECORD +0 -62
  64. {aiagents4pharma-1.9.0.dist-info → aiagents4pharma-1.15.0.dist-info}/LICENSE +0 -0
  65. {aiagents4pharma-1.9.0.dist-info → aiagents4pharma-1.15.0.dist-info}/WHEEL +0 -0
  66. {aiagents4pharma-1.9.0.dist-info → aiagents4pharma-1.15.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,171 @@
1
+ '''
2
+ Test cases for Talk2Biomodels get_annotation tool.
3
+ '''
4
+
5
+ import random
6
+ import pytest
7
+ from langchain_core.messages import HumanMessage, ToolMessage
8
+ from ..agents.t2b_agent import get_app
9
+ from ..tools.get_annotation import prepare_content_msg
10
+
11
+ @pytest.fixture(name="make_graph")
12
+ def make_graph_fixture():
13
+ '''
14
+ Create an instance of the talk2biomodels agent.
15
+ '''
16
+ unique_id = random.randint(1000, 9999)
17
+ graph = get_app(unique_id)
18
+ config = {"configurable": {"thread_id": unique_id}}
19
+ return graph, config
20
+
21
+ def test_no_model_provided(make_graph):
22
+ '''
23
+ Test the tool by not specifying any model.
24
+ We are testing a condition where the user
25
+ asks for annotations of all species without
26
+ specifying a model.
27
+ '''
28
+ app, config = make_graph
29
+ prompt = "Extract annotations of all species. Call the tool get_annotation."
30
+ app.invoke({"messages": [HumanMessage(content=prompt)]},
31
+ config=config
32
+ )
33
+ current_state = app.get_state(config)
34
+ # Assert that the state key model_id is empty.
35
+ assert current_state.values["model_id"] == []
36
+
37
+ def test_specific_species_provided(make_graph):
38
+ '''
39
+ Test the tool by providing a specific species name.
40
+ We are testing a condition where the user asks for annotations
41
+ of a specific species in a specific model.
42
+ '''
43
+ # Test with a valid species name
44
+ app, config = make_graph
45
+ prompt = "Extract annotations of species IL6 in model 537."
46
+ app.invoke(
47
+ {"messages": [HumanMessage(content=prompt)]},
48
+ config=config
49
+ )
50
+ current_state = app.get_state(config)
51
+ # print (current_state.values["dic_annotations_data"])
52
+ dic_annotations_data = current_state.values["dic_annotations_data"]
53
+
54
+ # The assert statement checks if IL6 is present in the returned annotations.
55
+ assert dic_annotations_data[0]['data']["Species Name"][0] == "IL6"
56
+
57
+ # Test with an invalid species name
58
+ app, config = make_graph
59
+ prompt = "Extract annotations of species NADH in model 537."
60
+ app.invoke(
61
+ {"messages": [HumanMessage(content=prompt)]},
62
+ config=config
63
+ )
64
+ current_state = app.get_state(config)
65
+ reversed_messages = current_state.values["messages"][::-1]
66
+ # Loop through the reversed messages until a
67
+ # ToolMessage is found.
68
+
69
+ test_condition = False
70
+ for msg in reversed_messages:
71
+ # Assert that the one of the messages is a ToolMessage
72
+ # and its artifact is None.
73
+ if isinstance(msg, ToolMessage) and msg.name == "get_annotation":
74
+ #If a ToolMessage exists and artifact is None (meaning no valid annotation was found)
75
+ #and the rejected species (NADH) is mentioned, the test passes.
76
+ if msg.artifact is None and 'NADH' in msg.content:
77
+ #If artifact is None, it means no annotation was found
78
+ # (likely due to an invalid species).
79
+ #If artifact contains data, the tool successfully retrieved annotations.
80
+ test_condition = True
81
+ break
82
+ # assert test_condition
83
+ assert test_condition, "Expected rejection message for NADH but did not find it."
84
+
85
+ # Test with an invalid species name and a valid species name
86
+ app, config = make_graph
87
+ prompt = "Extract annotations of species NADH, NAD, and IL7 in model 64."
88
+ app.invoke(
89
+ {"messages": [HumanMessage(content=prompt)]},
90
+ config=config
91
+ )
92
+ current_state = app.get_state(config)
93
+ # dic_annotations_data = current_state.values["dic_annotations_data"]
94
+ reversed_messages = current_state.values["messages"][::-1]
95
+ # Loop through the reversed messages until a
96
+ # ToolMessage is found.
97
+ artifact_was_none = False
98
+ for msg in reversed_messages:
99
+ # Assert that the one of the messages is a ToolMessage
100
+ # and its artifact is None.
101
+ if isinstance(msg, ToolMessage) and msg.name == "get_annotation":
102
+ # print (msg.artifact, msg.content)
103
+
104
+ if msg.artifact is True and 'IL7' in msg.content:
105
+ artifact_was_none = True
106
+ break
107
+ assert artifact_was_none
108
+
109
+ def test_all_species_annotations(make_graph):
110
+ '''
111
+ Test the tool by asking for annotations of all species is specific models.
112
+ Here, we test the tool with three models since they have different use cases:
113
+ - model 12 contains a species with no URL provided.
114
+ - model 20 contains a species without description.
115
+ - model 56 contains a species with database outside of KEGG, UniProt, and OLS.
116
+
117
+ We are testing a condition where the user asks for annotations
118
+ of all species in a specific model.
119
+ '''
120
+ # Loop through the models and test the tool
121
+ # for each model's unique use case.
122
+ for model_id in [12, 20, 56]:
123
+ app, config = make_graph
124
+ prompt = f"Extract annotations of all species model {model_id}."
125
+ # Test the tool get_modelinfo
126
+ app.invoke({"messages": [HumanMessage(content=prompt)]},
127
+ config=config
128
+ )
129
+ current_state = app.get_state(config)
130
+
131
+ reversed_messages = current_state.values["messages"][::-1]
132
+ # Coveres all of the use cases for the expecetd sting on all the species
133
+ test_condition = False
134
+ for msg in reversed_messages:
135
+ # Skip messages that are not ToolMessages and those that are not
136
+ # from the get_annotation tool.
137
+ if not isinstance(msg, ToolMessage) or msg.name != "get_annotation":
138
+ continue
139
+ if model_id == 12:
140
+ # Extact the first and second description of the LacI protein
141
+ # We already know that the first or second description is missing ('-')
142
+ dic_annotations_data = current_state.values["dic_annotations_data"][0]
143
+ first_descp_laci_protein = dic_annotations_data['data']['Description'][0]
144
+ second_descp_laci_protein = dic_annotations_data['data']['Description'][1]
145
+
146
+ # Expect a successful extraction (artifact is True) and that the content
147
+ # matches what is returned by prepare_content_msg for species.
148
+ # And that the first or second description of the LacI protein is missing.
149
+ if (msg.artifact is True and msg.content == prepare_content_msg([],[])
150
+ and msg.status=="success" and (first_descp_laci_protein == '-' or
151
+ second_descp_laci_protein == '-')):
152
+ test_condition = True
153
+ break
154
+
155
+ if model_id == 20:
156
+ # Expect an error message containing a note
157
+ # that species extraction failed.
158
+ if ("Unable to extract species from the model"
159
+ in msg.content and msg.status == "error"):
160
+ test_condition = True
161
+ break
162
+
163
+ if model_id == 56:
164
+ # Expect a successful extraction (artifact is True) and that the content
165
+ # matches for for missing description ['ORI'].
166
+ if (msg.artifact is True and
167
+ msg.content == prepare_content_msg([],['ORI'])
168
+ and msg.status == "success"):
169
+ test_condition = True
170
+ break
171
+ assert test_condition # Expected output is validated
@@ -0,0 +1,26 @@
1
+ '''
2
+ Test cases for Talk2Biomodels get_modelinfo tool.
3
+ '''
4
+
5
+ from langchain_core.messages import HumanMessage
6
+ from ..agents.t2b_agent import get_app
7
+
8
+ def test_get_modelinfo_tool():
9
+ '''
10
+ Test the get_modelinfo tool.
11
+ '''
12
+ unique_id = 12345
13
+ app = get_app(unique_id)
14
+ config = {"configurable": {"thread_id": unique_id}}
15
+ # Update state
16
+ app.update_state(config,
17
+ {"sbml_file_path": ["aiagents4pharma/talk2biomodels/tests/BIOMD0000000449_url.xml"]})
18
+ prompt = "Extract all relevant information from the uploaded model."
19
+ # Test the tool get_modelinfo
20
+ response = app.invoke(
21
+ {"messages": [HumanMessage(content=prompt)]},
22
+ config=config
23
+ )
24
+ assistant_msg = response["messages"][-1].content
25
+ # Check if the assistant message is a string
26
+ assert isinstance(assistant_msg, str)
@@ -0,0 +1,126 @@
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_integration():
10
+ '''
11
+ Test the integration of the tools.
12
+ '''
13
+ unique_id = 1234567
14
+ app = get_app(unique_id)
15
+ config = {"configurable": {"thread_id": unique_id}}
16
+ app.update_state(config, {"llm_model": "gpt-4o-mini"})
17
+ # ##########################################
18
+ # ## Test simulate_model tool
19
+ # ##########################################
20
+ prompt = '''Simulate the model 537 for 100 hours and intervals
21
+ 100 with an initial concentration of `DoseQ2W`
22
+ set to 300 and `Dose` set to 0. Reset the concentration
23
+ of `Ab{serum}` to 100 every 25 hours.'''
24
+ # Test the tool get_modelinfo
25
+ response = app.invoke(
26
+ {"messages": [HumanMessage(content=prompt)]},
27
+ config=config
28
+ )
29
+ assistant_msg = response["messages"][-1].content
30
+ print (assistant_msg)
31
+ # Check if the assistant message is a string
32
+ assert isinstance(assistant_msg, str)
33
+ ##########################################
34
+ # Test ask_question tool when simulation
35
+ # results are available
36
+ ##########################################
37
+ # Update state
38
+ app.update_state(config, {"llm_model": "gpt-4o-mini"})
39
+ prompt = """What is the concentration of CRP in serum after 100 hours?
40
+ Round off the value to 2 decimal places."""
41
+ # Test the tool get_modelinfo
42
+ response = app.invoke(
43
+ {"messages": [HumanMessage(content=prompt)]},
44
+ config=config
45
+ )
46
+ assistant_msg = response["messages"][-1].content
47
+ # print (assistant_msg)
48
+ # Check if the assistant message is a string
49
+ assert '211' in assistant_msg
50
+
51
+ ##########################################
52
+ # Test custom_plotter tool when the
53
+ # simulation results are available
54
+ ##########################################
55
+ prompt = "Plot only CRP related species."
56
+
57
+ # Update state
58
+ app.update_state(config, {"llm_model": "gpt-4o-mini"}
59
+ )
60
+ # Test the tool get_modelinfo
61
+ response = app.invoke(
62
+ {"messages": [HumanMessage(content=prompt)]},
63
+ config=config
64
+ )
65
+ assistant_msg = response["messages"][-1].content
66
+ current_state = app.get_state(config)
67
+ # Get the messages from the current state
68
+ # and reverse the order
69
+ reversed_messages = current_state.values["messages"][::-1]
70
+ # Loop through the reversed messages
71
+ # until a ToolMessage is found.
72
+ expected_header = ['Time', 'CRP{serum}', 'CRPExtracellular']
73
+ expected_header += ['CRP Suppression (%)', 'CRP (% of baseline)']
74
+ expected_header += ['CRP{liver}']
75
+ predicted_artifact = []
76
+ for msg in reversed_messages:
77
+ if isinstance(msg, ToolMessage):
78
+ # Work on the message if it is a ToolMessage
79
+ # These may contain additional visuals that
80
+ # need to be displayed to the user.
81
+ if msg.name == "custom_plotter":
82
+ predicted_artifact = msg.artifact
83
+ break
84
+ # Convert the artifact into a pandas dataframe
85
+ # for easy comparison
86
+ df = pd.DataFrame(predicted_artifact)
87
+ # Extract the headers from the dataframe
88
+ predicted_header = df.columns.tolist()
89
+ # Check if the header is in the expected_header
90
+ # assert expected_header in predicted_artifact
91
+ assert set(expected_header).issubset(set(predicted_header))
92
+ ##########################################
93
+ # Test custom_plotter tool when the
94
+ # simulation results are available but
95
+ # the species is not available
96
+ ##########################################
97
+ prompt = """Make a custom plot showing the
98
+ concentration of the species `TP53` over
99
+ time. Do not show any other species."""
100
+ # Update state
101
+ app.update_state(config, {"llm_model": "gpt-4o-mini"}
102
+ )
103
+ # Test the tool get_modelinfo
104
+ response = app.invoke(
105
+ {"messages": [HumanMessage(content=prompt)]},
106
+ config=config
107
+ )
108
+ assistant_msg = response["messages"][-1].content
109
+ # print (response["messages"])
110
+ current_state = app.get_state(config)
111
+ # Get the messages from the current state
112
+ # and reverse the order
113
+ reversed_messages = current_state.values["messages"][::-1]
114
+ # Loop through the reversed messages until a
115
+ # ToolMessage is found.
116
+ predicted_artifact = []
117
+ for msg in reversed_messages:
118
+ if isinstance(msg, ToolMessage):
119
+ # Work on the message if it is a ToolMessage
120
+ # These may contain additional visuals that
121
+ # need to be displayed to the user.
122
+ if msg.name == "custom_plotter":
123
+ predicted_artifact = msg.artifact
124
+ break
125
+ # Check if the the predicted artifact is `None`
126
+ assert predicted_artifact is None
@@ -0,0 +1,68 @@
1
+ '''
2
+ Test cases for Talk2Biomodels parameter scan tool.
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_param_scan_tool():
10
+ '''
11
+ In this test, we will test the parameter_scan tool.
12
+ We will prompt it to scan the parameter `kIL6RBind`
13
+ from 1 to 100 in steps of 10, record the changes
14
+ in the concentration of the species `Ab{serum}` in
15
+ model 537.
16
+
17
+ We will pass the inaccuarate parameter (`KIL6Rbind`)
18
+ and species names (just `Ab`) to the tool to test
19
+ if it can deal with it.
20
+
21
+ We expect the agent to first invoke the parameter_scan
22
+ tool and raise an error. It will then invoke another
23
+ tool get_modelinfo to get the correct parameter
24
+ and species names. Finally, the agent will reinvoke
25
+ the parameter_scan tool with the correct parameter
26
+ and species names.
27
+
28
+ '''
29
+ unique_id = 1234
30
+ app = get_app(unique_id)
31
+ config = {"configurable": {"thread_id": unique_id}}
32
+ app.update_state(config, {"llm_model": "gpt-4o-mini"})
33
+ prompt = """How will the value of Ab in serum in model 537 change
34
+ if the param kIL6Rbind is varied from 1 to 100 in steps of 10?
35
+ Set the initial `DoseQ2W` concentration to 300. Assume
36
+ that the model is simulated for 2016 hours with an interval of 50."""
37
+ # Invoke the agent
38
+ app.invoke(
39
+ {"messages": [HumanMessage(content=prompt)]},
40
+ config=config
41
+ )
42
+ current_state = app.get_state(config)
43
+ reversed_messages = current_state.values["messages"][::-1]
44
+ # Loop through the reversed messages until a
45
+ # ToolMessage is found.
46
+ df = pd.DataFrame(columns=['name', 'status', 'content'])
47
+ names = []
48
+ statuses = []
49
+ contents = []
50
+ for msg in reversed_messages:
51
+ # Assert that the message is a ToolMessage
52
+ # and its status is "error"
53
+ if not isinstance(msg, ToolMessage):
54
+ continue
55
+ names.append(msg.name)
56
+ statuses.append(msg.status)
57
+ contents.append(msg.content)
58
+ df = pd.DataFrame({'name': names, 'status': statuses, 'content': contents})
59
+ # print (df)
60
+ assert any((df["status"] == "error") &
61
+ (df["name"] == "parameter_scan") &
62
+ (df["content"].str.startswith(
63
+ "Error: ValueError('Invalid species or parameter name:")))
64
+ assert any((df["status"] == "success") &
65
+ (df["name"] == "parameter_scan") &
66
+ (df["content"].str.startswith("Parameter scan results of")))
67
+ assert any((df["status"] == "success") &
68
+ (df["name"] == "get_modelinfo"))
@@ -0,0 +1,76 @@
1
+ '''
2
+ Test cases for Talk2Biomodels query_article tool.
3
+ '''
4
+
5
+ from pydantic import BaseModel, Field
6
+ from langchain_core.messages import HumanMessage, ToolMessage
7
+ from langchain_openai import ChatOpenAI
8
+ from ..agents.t2b_agent import get_app
9
+
10
+ class Article(BaseModel):
11
+ '''
12
+ Article schema.
13
+ '''
14
+ title: str = Field(description="Title of the article.")
15
+
16
+ def test_query_article_with_an_article():
17
+ '''
18
+ Test the query_article tool by providing an article.
19
+ '''
20
+ unique_id = 12345
21
+ app = get_app(unique_id)
22
+ config = {"configurable": {"thread_id": unique_id}}
23
+ # Update state by providing the pdf file name
24
+ app.update_state(config,
25
+ {"pdf_file_name": "aiagents4pharma/talk2biomodels/tests/article_on_model_537.pdf"})
26
+ prompt = "What is the title of the article?"
27
+ # Test the tool query_article
28
+ response = app.invoke(
29
+ {"messages": [HumanMessage(content=prompt)]},
30
+ config=config
31
+ )
32
+ # Get the response from the tool
33
+ assistant_msg = response["messages"][-1].content
34
+ # Prepare a LLM that can be used as a judge
35
+ llm = ChatOpenAI(model='gpt-4o-mini', temperature=0)
36
+ # Make it return a structured output
37
+ structured_llm = llm.with_structured_output(Article)
38
+ # Prepare a prompt for the judge
39
+ prompt = "Given the text below, what is the title of the article?"
40
+ prompt += f"\n\n{assistant_msg}"
41
+ # Get the structured output
42
+ article = structured_llm.invoke(prompt)
43
+ # Check if the article title is correct
44
+ expected_title = "A Multiscale Model of IL-6–Mediated "
45
+ expected_title += "Immune Regulation in Crohn’s Disease"
46
+ # Check if the article title is correct
47
+ assert article.title == expected_title
48
+
49
+ def test_query_article_without_an_article():
50
+ '''
51
+ Test the query_article tool without providing an article.
52
+ The status of the tool should be error.
53
+ '''
54
+ unique_id = 12345
55
+ app = get_app(unique_id)
56
+ config = {"configurable": {"thread_id": unique_id}}
57
+ prompt = "What is the title of the uploaded article?"
58
+ # Test the tool query_article
59
+ app.invoke(
60
+ {"messages": [HumanMessage(content=prompt)]},
61
+ config=config
62
+ )
63
+ current_state = app.get_state(config)
64
+ # Get the messages from the current state
65
+ # and reverse the order
66
+ reversed_messages = current_state.values["messages"][::-1]
67
+ # Loop through the reversed messages
68
+ # until a ToolMessage is found.
69
+ tool_status_is_error = False
70
+ for msg in reversed_messages:
71
+ if isinstance(msg, ToolMessage):
72
+ # Skip until it finds a ToolMessage
73
+ if msg.name == "query_article" and msg.status == "error":
74
+ tool_status_is_error = True
75
+ break
76
+ assert tool_status_is_error
@@ -0,0 +1,28 @@
1
+ '''
2
+ Test cases for Talk2Biomodels search models tool.
3
+ '''
4
+
5
+ from langchain_core.messages import HumanMessage
6
+ from ..agents.t2b_agent import get_app
7
+
8
+ def test_search_models_tool():
9
+ '''
10
+ Test the search_models tool.
11
+ '''
12
+ unique_id = 12345
13
+ app = get_app(unique_id)
14
+ config = {"configurable": {"thread_id": unique_id}}
15
+ # Update state
16
+ app.update_state(config, {"llm_model": "gpt-4o-mini"})
17
+ prompt = "Search for models on Crohn's disease."
18
+ # Test the tool get_modelinfo
19
+ response = app.invoke(
20
+ {"messages": [HumanMessage(content=prompt)]},
21
+ config=config
22
+ )
23
+ assistant_msg = response["messages"][-1].content
24
+ # Check if the assistant message is a string
25
+ assert isinstance(assistant_msg, str)
26
+ # Check if the assistant message contains the
27
+ # biomodel id BIO0000000537
28
+ assert "BIOMD0000000537" in assistant_msg
@@ -0,0 +1,39 @@
1
+ '''
2
+ Test cases for Talk2Biomodels.
3
+ '''
4
+
5
+ from langchain_core.messages import HumanMessage
6
+ from ..agents.t2b_agent import get_app
7
+
8
+ def test_simulate_model_tool():
9
+ '''
10
+ Test the simulate_model tool when simulating
11
+ multiple models.
12
+ '''
13
+ unique_id = 123
14
+ app = get_app(unique_id)
15
+ config = {"configurable": {"thread_id": unique_id}}
16
+ app.update_state(config, {"llm_model": "gpt-4o-mini"})
17
+ # Upload a model to the state
18
+ app.update_state(config,
19
+ {"sbml_file_path": ["aiagents4pharma/talk2biomodels/tests/BIOMD0000000449_url.xml"]})
20
+ prompt = "Simulate model 64 and the uploaded model"
21
+ # Invoke the agent
22
+ app.invoke(
23
+ {"messages": [HumanMessage(content=prompt)]},
24
+ config=config
25
+ )
26
+ current_state = app.get_state(config)
27
+ dic_simulated_data = current_state.values["dic_simulated_data"]
28
+ # Check if the dic_simulated_data is a list
29
+ assert isinstance(dic_simulated_data, list)
30
+ # Check if the length of the dic_simulated_data is 2
31
+ assert len(dic_simulated_data) == 2
32
+ # Check if the source of the first model is 64
33
+ assert dic_simulated_data[0]['source'] == 64
34
+ # Check if the source of the second model is upload
35
+ assert dic_simulated_data[1]['source'] == "upload"
36
+ # Check if the data of the first model contains
37
+ assert '1,3-bisphosphoglycerate' in dic_simulated_data[0]['data']
38
+ # Check if the data of the second model contains
39
+ assert 'mTORC2' in dic_simulated_data[1]['data']
@@ -0,0 +1,90 @@
1
+ '''
2
+ Test cases for Talk2Biomodels steady state tool.
3
+ '''
4
+
5
+ from langchain_core.messages import HumanMessage, ToolMessage
6
+ from ..agents.t2b_agent import get_app
7
+
8
+ def test_steady_state_tool():
9
+ '''
10
+ Test the steady_state tool.
11
+ '''
12
+ unique_id = 123
13
+ app = get_app(unique_id)
14
+ config = {"configurable": {"thread_id": unique_id}}
15
+ app.update_state(config, {"llm_model": "gpt-4o-mini"})
16
+ #########################################################
17
+ # In this case, we will test if the tool returns an error
18
+ # when the model does not achieve a steady state. The tool
19
+ # status should be "error".
20
+ prompt = """Run a steady state analysis of model 537."""
21
+ # Invoke the agent
22
+ app.invoke(
23
+ {"messages": [HumanMessage(content=prompt)]},
24
+ config=config
25
+ )
26
+ current_state = app.get_state(config)
27
+ reversed_messages = current_state.values["messages"][::-1]
28
+ tool_msg_status = None
29
+ for msg in reversed_messages:
30
+ # Assert that the status of the
31
+ # ToolMessage is "error"
32
+ if isinstance(msg, ToolMessage):
33
+ # print (msg)
34
+ tool_msg_status = msg.status
35
+ break
36
+ assert tool_msg_status == "error"
37
+ #########################################################
38
+ # In this case, we will test if the tool is indeed invoked
39
+ # successfully
40
+ prompt = """Run a steady state analysis of model 64.
41
+ Set the initial concentration of `Pyruvate` to 0.2. The
42
+ concentration of `NAD` resets to 100 every 2 time units."""
43
+ # Invoke the agent
44
+ app.invoke(
45
+ {"messages": [HumanMessage(content=prompt)]},
46
+ config=config
47
+ )
48
+ # Loop through the reversed messages until a
49
+ # ToolMessage is found.
50
+ current_state = app.get_state(config)
51
+ reversed_messages = current_state.values["messages"][::-1]
52
+ steady_state_invoked = False
53
+ for msg in reversed_messages:
54
+ # Assert that the message is a ToolMessage
55
+ # and its status is "error"
56
+ if isinstance(msg, ToolMessage):
57
+ print (msg)
58
+ if msg.name == "steady_state" and msg.status != "error":
59
+ steady_state_invoked = True
60
+ break
61
+ assert steady_state_invoked
62
+ #########################################################
63
+ # In this case, we will test if the `ask_question` tool is
64
+ # invoked upon asking a question about the already generated
65
+ # steady state results
66
+ prompt = """What is the Phosphoenolpyruvate concentration
67
+ at the steady state? Show only the concentration, rounded
68
+ to 2 decimal places. For example, if the concentration is
69
+ 0.123456, your response should be `0.12`. Do not return
70
+ any other information."""
71
+ # Invoke the agent
72
+ response = app.invoke(
73
+ {"messages": [HumanMessage(content=prompt)]},
74
+ config=config
75
+ )
76
+ assistant_msg = response["messages"][-1].content
77
+ current_state = app.get_state(config)
78
+ reversed_messages = current_state.values["messages"][::-1]
79
+ # Loop through the reversed messages until a
80
+ # ToolMessage is found.
81
+ ask_questool_invoked = False
82
+ for msg in reversed_messages:
83
+ # Assert that the message is a ToolMessage
84
+ # and its status is "error"
85
+ if isinstance(msg, ToolMessage):
86
+ if msg.name == "ask_question":
87
+ ask_questool_invoked = True
88
+ break
89
+ assert ask_questool_invoked
90
+ assert "0.06" in assistant_msg
@@ -16,6 +16,8 @@ class TestBioModel(SysBioModel):
16
16
  sbml_file_path: Optional[str] = Field(None, description="Path to an SBML file")
17
17
  name: Optional[str] = Field(..., description="Name of the model")
18
18
  description: Optional[str] = Field("", description="Description of the model")
19
+ param1: Optional[float] = Field(0.0, description="Parameter 1")
20
+ param2: Optional[float] = Field(0.0, description="Parameter 2")
19
21
 
20
22
  def get_model_metadata(self) -> Dict[str, Union[str, int]]:
21
23
  '''
@@ -23,15 +25,18 @@ class TestBioModel(SysBioModel):
23
25
  '''
24
26
  return self.biomodel_id
25
27
 
26
- def simulate(self,
27
- parameters: Dict[str, Union[float, int]],
28
- duration: Union[int, float]) -> List[float]:
28
+ def update_parameters(self, parameters):
29
+ '''
30
+ Update the model parameters.
31
+ '''
32
+ self.param1 = parameters.get('param1', 0.0)
33
+ self.param2 = parameters.get('param2', 0.0)
34
+
35
+ def simulate(self, duration: Union[int, float]) -> List[float]:
29
36
  '''
30
37
  Simulate the model.
31
38
  '''
32
- param1 = parameters.get('param1', 0.0)
33
- param2 = parameters.get('param2', 0.0)
34
- return [param1 + param2 * t for t in range(int(duration))]
39
+ return [self.param1 + self.param2 * t for t in range(int(duration))]
35
40
 
36
41
  def test_get_model_metadata():
37
42
  '''
@@ -53,5 +58,6 @@ def test_simulate():
53
58
  Test the simulate method of the BioModel class.
54
59
  '''
55
60
  model = TestBioModel(biomodel_id=123, name="Test Model", description="A test model")
56
- results = model.simulate(parameters={'param1': 1.0, 'param2': 2.0}, duration=4.0)
61
+ model.update_parameters({'param1': 1.0, 'param2': 2.0})
62
+ results = model.simulate(duration=4.0)
57
63
  assert results == [1.0, 3.0, 5.0, 7.0]
@@ -6,4 +6,8 @@ from . import simulate_model
6
6
  from . import ask_question
7
7
  from . import custom_plotter
8
8
  from . import get_modelinfo
9
+ from . import parameter_scan
10
+ from . import steady_state
9
11
  from . import load_biomodel
12
+ from . import get_annotation
13
+ from . import query_article