aiagents4pharma 1.46.5__py3-none-any.whl → 1.47.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.
- aiagents4pharma/talk2biomodels/agents/t2b_agent.py +2 -0
- aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py +1 -0
- aiagents4pharma/talk2biomodels/tests/test_save_model.py +47 -0
- aiagents4pharma/talk2biomodels/tests/test_simulate_model.py +2 -0
- aiagents4pharma/talk2biomodels/tools/__init__.py +1 -0
- aiagents4pharma/talk2biomodels/tools/save_model.py +98 -0
- aiagents4pharma/talk2biomodels/tools/simulate_model.py +2 -0
- {aiagents4pharma-1.46.5.dist-info → aiagents4pharma-1.47.0.dist-info}/METADATA +1 -1
- {aiagents4pharma-1.46.5.dist-info → aiagents4pharma-1.47.0.dist-info}/RECORD +11 -9
- {aiagents4pharma-1.46.5.dist-info → aiagents4pharma-1.47.0.dist-info}/WHEEL +0 -0
- {aiagents4pharma-1.46.5.dist-info → aiagents4pharma-1.47.0.dist-info}/licenses/LICENSE +0 -0
@@ -20,6 +20,7 @@ from ..tools.get_annotation import GetAnnotationTool
|
|
20
20
|
from ..tools.get_modelinfo import GetModelInfoTool
|
21
21
|
from ..tools.parameter_scan import ParameterScanTool
|
22
22
|
from ..tools.query_article import QueryArticle
|
23
|
+
from ..tools.save_model import SaveModelTool
|
23
24
|
from ..tools.search_models import SearchModelsTool
|
24
25
|
from ..tools.simulate_model import SimulateModelTool
|
25
26
|
from ..tools.steady_state import SteadyStateTool
|
@@ -54,6 +55,7 @@ def get_app(uniq_id, llm_model: BaseChatModel):
|
|
54
55
|
ParameterScanTool(),
|
55
56
|
GetAnnotationTool(),
|
56
57
|
QueryArticle(),
|
58
|
+
SaveModelTool(),
|
57
59
|
]
|
58
60
|
)
|
59
61
|
|
@@ -42,6 +42,7 @@ class Talk2Biomodels(AgentState):
|
|
42
42
|
# https://langchain-ai.github.io/langgraph/troubleshooting/errors/INVALID_CONCURRENT_GRAPH_UPDATE/
|
43
43
|
model_id: Annotated[list, operator.add]
|
44
44
|
sbml_file_path: Annotated[list, operator.add]
|
45
|
+
model_as_string: Annotated[list, operator.add]
|
45
46
|
dic_simulated_data: Annotated[list[dict], add_data]
|
46
47
|
dic_scanned_data: Annotated[list[dict], add_data]
|
47
48
|
dic_steady_state_data: Annotated[list[dict], add_data]
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"""
|
2
|
+
Test cases for Talk2Biomodels.
|
3
|
+
"""
|
4
|
+
|
5
|
+
import tempfile
|
6
|
+
|
7
|
+
from langchain_core.messages import HumanMessage
|
8
|
+
from langchain_openai import ChatOpenAI
|
9
|
+
|
10
|
+
from ..agents.t2b_agent import get_app
|
11
|
+
|
12
|
+
LLM_MODEL = ChatOpenAI(model="gpt-4o-mini", temperature=0)
|
13
|
+
|
14
|
+
|
15
|
+
def test_save_model_tool():
|
16
|
+
"""
|
17
|
+
Test the save_model tool.
|
18
|
+
"""
|
19
|
+
unique_id = 123
|
20
|
+
app = get_app(unique_id, llm_model=LLM_MODEL)
|
21
|
+
config = {"configurable": {"thread_id": unique_id}}
|
22
|
+
# Simulate a model
|
23
|
+
prompt = "Simulate model 64"
|
24
|
+
# Invoke the agent
|
25
|
+
app.invoke({"messages": [HumanMessage(content=prompt)]}, config=config)
|
26
|
+
current_state = app.get_state(config)
|
27
|
+
assert current_state.values["model_as_string"][-1] is not None
|
28
|
+
# Save a model without simulating
|
29
|
+
prompt = "Save the model"
|
30
|
+
# Invoke the agent
|
31
|
+
app.invoke({"messages": [HumanMessage(content=prompt)]}, config=config)
|
32
|
+
current_state = app.get_state(config)
|
33
|
+
assert current_state.values["model_as_string"][-1] is not None
|
34
|
+
# Create a temporary directory to save the model
|
35
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
36
|
+
# Save a model to the temporary directory
|
37
|
+
prompt = f"Simulate model 64 and save it model at {temp_dir}"
|
38
|
+
# Invoke the agent
|
39
|
+
app.invoke({"messages": [HumanMessage(content=prompt)]}, config=config)
|
40
|
+
current_state = app.get_state(config)
|
41
|
+
assert current_state.values["model_as_string"][-1] is not None
|
42
|
+
# Simulate and save a model in non-existing path
|
43
|
+
prompt = "Simulate model 64 and then save the model at /xyz/"
|
44
|
+
# Invoke the agent
|
45
|
+
app.invoke({"messages": [HumanMessage(content=prompt)]}, config=config)
|
46
|
+
current_state = app.get_state(config)
|
47
|
+
assert current_state.values["model_as_string"][-1] is not None
|
@@ -40,3 +40,5 @@ def test_simulate_model_tool():
|
|
40
40
|
assert "1,3-bisphosphoglycerate" in dic_simulated_data[0]["data"]
|
41
41
|
# Check if the data of the second model contains
|
42
42
|
assert "mTORC2" in dic_simulated_data[1]["data"]
|
43
|
+
# Check if the model_as_string is not None
|
44
|
+
assert current_state.values["model_as_string"][-1] is not None
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
|
3
|
+
"""
|
4
|
+
Tool for saving models.
|
5
|
+
"""
|
6
|
+
|
7
|
+
import logging
|
8
|
+
import os
|
9
|
+
from typing import Annotated
|
10
|
+
|
11
|
+
from langchain_core.messages import ToolMessage
|
12
|
+
from langchain_core.tools import BaseTool
|
13
|
+
from langchain_core.tools.base import InjectedToolCallId
|
14
|
+
from langgraph.prebuilt import InjectedState
|
15
|
+
from langgraph.types import Command
|
16
|
+
from pydantic import BaseModel, Field
|
17
|
+
|
18
|
+
# Initialize logger
|
19
|
+
logging.basicConfig(level=logging.INFO)
|
20
|
+
logger = logging.getLogger(__name__)
|
21
|
+
|
22
|
+
|
23
|
+
class SaveModelInput(BaseModel):
|
24
|
+
"""
|
25
|
+
Input schema for the save model tool.
|
26
|
+
"""
|
27
|
+
|
28
|
+
path_to_folder: str = Field(
|
29
|
+
description="Path to folder to save the model. Keep it to . if not provided.", default="."
|
30
|
+
)
|
31
|
+
output_filename: str = Field(
|
32
|
+
description="Filename to save the model as. Default is 'saved_model.xml'.",
|
33
|
+
default="saved_model.xml",
|
34
|
+
)
|
35
|
+
tool_call_id: Annotated[str, InjectedToolCallId]
|
36
|
+
state: Annotated[dict, InjectedState]
|
37
|
+
|
38
|
+
|
39
|
+
# Note: It's important that every field has type hints. BaseTool is a
|
40
|
+
# Pydantic class and not having type hints can lead to unexpected behavior.
|
41
|
+
class SaveModelTool(BaseTool):
|
42
|
+
"""
|
43
|
+
Tool for saving a model.
|
44
|
+
"""
|
45
|
+
|
46
|
+
name: str = "save_model"
|
47
|
+
description: str = "A tool to save the current biomodel to a \
|
48
|
+
user specified path with the default filename\
|
49
|
+
'saved_model.xml'"
|
50
|
+
args_schema: type[BaseModel] = SaveModelInput
|
51
|
+
return_direct: bool = False
|
52
|
+
|
53
|
+
def _run(
|
54
|
+
self,
|
55
|
+
tool_call_id: Annotated[str, InjectedToolCallId],
|
56
|
+
state: Annotated[dict, InjectedState],
|
57
|
+
path_to_folder: str = ".",
|
58
|
+
output_filename: str = "saved_model.xml",
|
59
|
+
) -> Command:
|
60
|
+
"""
|
61
|
+
Run the tool.
|
62
|
+
|
63
|
+
Args:
|
64
|
+
path (str): The path to save the model.
|
65
|
+
tool_call_id (str): The tool call ID.
|
66
|
+
|
67
|
+
Returns:
|
68
|
+
|
69
|
+
"""
|
70
|
+
logger.log(
|
71
|
+
logging.INFO,
|
72
|
+
"Saving model to path: %s with filename: %s",
|
73
|
+
path_to_folder,
|
74
|
+
output_filename,
|
75
|
+
)
|
76
|
+
# Check if path does not exist
|
77
|
+
if not os.path.exists(path_to_folder):
|
78
|
+
content = f"Error: Path {path_to_folder} does not exist."
|
79
|
+
logger.error(content)
|
80
|
+
else:
|
81
|
+
logger.info("Saving now")
|
82
|
+
# Save the model to the specified path
|
83
|
+
with open(os.path.join(path_to_folder, output_filename), "w", encoding="utf-8") as f:
|
84
|
+
f.write(state["model_as_string"][-1])
|
85
|
+
content = f"Model saved successfully to {path_to_folder}/{output_filename}."
|
86
|
+
logger.info(content)
|
87
|
+
# Return the updated state of the tool
|
88
|
+
return Command(
|
89
|
+
update={
|
90
|
+
# update the message history
|
91
|
+
"messages": [
|
92
|
+
ToolMessage(
|
93
|
+
content=content,
|
94
|
+
tool_call_id=tool_call_id,
|
95
|
+
)
|
96
|
+
],
|
97
|
+
}
|
98
|
+
)
|
@@ -7,6 +7,7 @@ Tool for simulating a model.
|
|
7
7
|
import logging
|
8
8
|
from typing import Annotated
|
9
9
|
|
10
|
+
import basico
|
10
11
|
from langchain_core.messages import ToolMessage
|
11
12
|
from langchain_core.tools import BaseTool
|
12
13
|
from langchain_core.tools.base import InjectedToolCallId
|
@@ -116,6 +117,7 @@ class SimulateModelTool(BaseTool):
|
|
116
117
|
"model_id": [sys_bio_model.biomodel_id],
|
117
118
|
"sbml_file_path": [sbml_file_path],
|
118
119
|
"dic_simulated_data": [dic_simulated_data],
|
120
|
+
"model_as_string": [basico.model_io.save_model_to_string()],
|
119
121
|
}.items():
|
120
122
|
if value:
|
121
123
|
dic_updated_state_for_model[key] = value
|
@@ -27,7 +27,7 @@ aiagents4pharma/talk2biomodels/README.md,sha256=0eGxj7jxi_LrCvX-4I4KrQv-7T2ivo3p
|
|
27
27
|
aiagents4pharma/talk2biomodels/__init__.py,sha256=DxARZJu91m4WHW4PBSZvlMb1MCbjvkZg1YUnYJXMBSA,117
|
28
28
|
aiagents4pharma/talk2biomodels/install.md,sha256=9YAEeW_vG5hv7WiMnNEzgKQIgVyHnpk1IIWXg_jhLxE,1520
|
29
29
|
aiagents4pharma/talk2biomodels/agents/__init__.py,sha256=4wPy6hWRJksX6z8qX1cVjFctZLpsja8JMngKHqn49N4,129
|
30
|
-
aiagents4pharma/talk2biomodels/agents/t2b_agent.py,sha256=
|
30
|
+
aiagents4pharma/talk2biomodels/agents/t2b_agent.py,sha256=hf-JTzcaOQIMG97qJb7EKe-jehghGiyXbbd9qSHFVIk,3341
|
31
31
|
aiagents4pharma/talk2biomodels/api/__init__.py,sha256=KGok9mCa6RT8whDj3jT3kcpFO1yHxk5vVD8IExsI5Bc,92
|
32
32
|
aiagents4pharma/talk2biomodels/api/ols.py,sha256=QSvbsD0V07-w0OU-wPQ4EypXi9bn_xl0NyliZQxRvCU,2173
|
33
33
|
aiagents4pharma/talk2biomodels/api/uniprot.py,sha256=jXoyd7BhIQA9JNaGMVPzORpQ5k1Ix9iYYduMv6YG7hw,1147
|
@@ -50,7 +50,7 @@ aiagents4pharma/talk2biomodels/models/__init__.py,sha256=ykurWrvOAkx4ooknggsu6Ri
|
|
50
50
|
aiagents4pharma/talk2biomodels/models/basico_model.py,sha256=M9KVnLDNAWfM0MAxSDpAJKIq1R8ezjDW1C3C9oLsRNU,4998
|
51
51
|
aiagents4pharma/talk2biomodels/models/sys_bio_model.py,sha256=dwoBK_g7aXVv7B97CqILTvsxGEbNH_iPLWQ1SoPg4cg,1928
|
52
52
|
aiagents4pharma/talk2biomodels/states/__init__.py,sha256=Rxe64WLgcNKnKaEIPv3rXmwBUUrl1SP-B6F4Unf723w,140
|
53
|
-
aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py,sha256=
|
53
|
+
aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py,sha256=NLbkXS9857KqKdjZeZA_RMeulRhL4PG-nSjVOIzYD8c,1562
|
54
54
|
aiagents4pharma/talk2biomodels/tests/BIOMD0000000449_url.xml,sha256=RkWbstfLrT1mAfOtZf7JsBz6poyWg6-5G7H_IdVXEXg,72630
|
55
55
|
aiagents4pharma/talk2biomodels/tests/__init__.py,sha256=U3PsTiUZaUBD1IZanFGkDIOdFieDVJtGKQ5-woYUo8c,45
|
56
56
|
aiagents4pharma/talk2biomodels/tests/article_on_model_537.pdf,sha256=rfBnG9XSGRZodq-NQsouQQ3dvm4JKcrAqEkoAQJmuDc,470738
|
@@ -63,11 +63,12 @@ aiagents4pharma/talk2biomodels/tests/test_integration.py,sha256=t8jR45pX7hKBGOjX
|
|
63
63
|
aiagents4pharma/talk2biomodels/tests/test_load_biomodel.py,sha256=8nVSDa8_z85dyvxa8aYGQR0YGZDtpzLF5HhBmifCk6w,895
|
64
64
|
aiagents4pharma/talk2biomodels/tests/test_param_scan.py,sha256=OFUeGlnEFAcSR3JODH0Yl2MVUBjiPqUNltcH-ICfSsE,2655
|
65
65
|
aiagents4pharma/talk2biomodels/tests/test_query_article.py,sha256=IZ0oDRPmVxD-g6vQ-uGSiYaJ1hf_rTcnda5u_J3rE2Y,6929
|
66
|
+
aiagents4pharma/talk2biomodels/tests/test_save_model.py,sha256=XgKYTNFbWQmKgF5mseTg5HrJhmN-Hg20v0hxkmwWh9U,1764
|
66
67
|
aiagents4pharma/talk2biomodels/tests/test_search_models.py,sha256=JuNvBz2i3a82c1SVwxKBlEIm98p91zzbnpnjMmWOg9g,1201
|
67
|
-
aiagents4pharma/talk2biomodels/tests/test_simulate_model.py,sha256=
|
68
|
+
aiagents4pharma/talk2biomodels/tests/test_simulate_model.py,sha256=JmE28fBdl4I37AX6x8lK8PK3rNdvj5ohJn7u95gG11M,1658
|
68
69
|
aiagents4pharma/talk2biomodels/tests/test_steady_state.py,sha256=5G3ug0mZDxQR8gCl3Xv6z3P1hfzUtXmyigYcVG9BfXE,3512
|
69
70
|
aiagents4pharma/talk2biomodels/tests/test_sys_bio_model.py,sha256=poMxOsKhg8USnptHPUjr6DptsO_HBZgV0G0C0lqF57s,2093
|
70
|
-
aiagents4pharma/talk2biomodels/tools/__init__.py,sha256=
|
71
|
+
aiagents4pharma/talk2biomodels/tools/__init__.py,sha256=viqx475FR5-gP10lmVg7u8wAWUZSHXe3bbQzF5N9oMk,295
|
71
72
|
aiagents4pharma/talk2biomodels/tools/ask_question.py,sha256=IbolM6zbYKHd_UCfLMa8bawt9fJH59cCUtkLB_wtxKI,4495
|
72
73
|
aiagents4pharma/talk2biomodels/tools/custom_plotter.py,sha256=dk5HUmPwSTIRp2sbd8Q8__fwSE8m13UseonvcpyDs00,6636
|
73
74
|
aiagents4pharma/talk2biomodels/tools/get_annotation.py,sha256=oHERHdY4KinQFg9udufEgJP3tE3x0gtoWWy4Kna9H78,12854
|
@@ -76,8 +77,9 @@ aiagents4pharma/talk2biomodels/tools/load_arguments.py,sha256=LZQNkAikXhG0AKRnfL
|
|
76
77
|
aiagents4pharma/talk2biomodels/tools/load_biomodel.py,sha256=025-E5qo2uiJVvHIhyeDh1tfmXTeIguSgS0KIY0LiyY,1208
|
77
78
|
aiagents4pharma/talk2biomodels/tools/parameter_scan.py,sha256=Hvq4igK0XBQ45YxhZpVNkVHWmaum7V3HGtIaaW8P_S0,11962
|
78
79
|
aiagents4pharma/talk2biomodels/tools/query_article.py,sha256=f2KMhKuWXqs8MidZO367JEsXHIK8NsOm_YUszH6qwpM,2152
|
80
|
+
aiagents4pharma/talk2biomodels/tools/save_model.py,sha256=2TEnzbt5z98qjL9eRZnXbS05iGuC7QylM-51HMfrjNE,2994
|
79
81
|
aiagents4pharma/talk2biomodels/tools/search_models.py,sha256=DWC4bHDnOiKBp534MNMN_AJ1rc21dXt768SvMRL6mrU,3133
|
80
|
-
aiagents4pharma/talk2biomodels/tools/simulate_model.py,sha256=
|
82
|
+
aiagents4pharma/talk2biomodels/tools/simulate_model.py,sha256=4QU03Xp-AU_va0QXGQZN7btn_Dh-ALrZA3K1JqDXH_4,5185
|
81
83
|
aiagents4pharma/talk2biomodels/tools/steady_state.py,sha256=zNbSDOITw9oomEqGSRqI224jZGsMw8LBka-2rG3moxs,7033
|
82
84
|
aiagents4pharma/talk2biomodels/tools/utils.py,sha256=bpVtS-5_oDGdgjbsLeIVcOo1BJvS_pyg8PDg9z2dG5Q,521
|
83
85
|
aiagents4pharma/talk2cells/README.md,sha256=0eGxj7jxi_LrCvX-4I4KrQv-7T2ivo3pqLslG7suaCk,74
|
@@ -328,7 +330,7 @@ aiagents4pharma/talk2scholars/tools/zotero/utils/review_helper.py,sha256=-q-UuzP
|
|
328
330
|
aiagents4pharma/talk2scholars/tools/zotero/utils/write_helper.py,sha256=K1EatPfC-riGyFmkOAS3ReNBaGPY-znne1KqOnFahkI,7339
|
329
331
|
aiagents4pharma/talk2scholars/tools/zotero/utils/zotero_path.py,sha256=sKkfJu3u4LKSZjfoQRfeqz26IESHRwBtcSDzLMLlJMo,6311
|
330
332
|
aiagents4pharma/talk2scholars/tools/zotero/utils/zotero_pdf_downloader.py,sha256=DBrF5IiF7VRP58hUK8T9LST3lQWLFixLUfnpMSTccoQ,4614
|
331
|
-
aiagents4pharma-1.
|
332
|
-
aiagents4pharma-1.
|
333
|
-
aiagents4pharma-1.
|
334
|
-
aiagents4pharma-1.
|
333
|
+
aiagents4pharma-1.47.0.dist-info/METADATA,sha256=Y7cHyuKy8HAGhEa-9SoqF6XxouOfe0RQxDDDCaqRdQI,17035
|
334
|
+
aiagents4pharma-1.47.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
335
|
+
aiagents4pharma-1.47.0.dist-info/licenses/LICENSE,sha256=IcIbyB1Hyk5ZDah03VNQvJkbNk2hkBCDqQ8qtnCvB4Q,1077
|
336
|
+
aiagents4pharma-1.47.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|