aiagents4pharma 1.4.1__py3-none-any.whl → 1.4.3__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/models/basico_model.py +13 -1
- aiagents4pharma/talk2biomodels/tools/__init__.py +5 -2
- aiagents4pharma/talk2biomodels/tools/fetch_parameters.py +26 -2
- aiagents4pharma/talk2biomodels/tools/search_models.py +13 -1
- {aiagents4pharma-1.4.1.dist-info → aiagents4pharma-1.4.3.dist-info}/METADATA +3 -3
- {aiagents4pharma-1.4.1.dist-info → aiagents4pharma-1.4.3.dist-info}/RECORD +9 -10
- {aiagents4pharma-1.4.1.dist-info → aiagents4pharma-1.4.3.dist-info}/WHEEL +1 -1
- aiagents4pharma/talk2biomodels/tools/plot_figure.py +0 -135
- {aiagents4pharma-1.4.1.dist-info → aiagents4pharma-1.4.3.dist-info}/LICENSE +0 -0
- {aiagents4pharma-1.4.1.dist-info → aiagents4pharma-1.4.3.dist-info}/top_level.txt +0 -0
@@ -6,6 +6,8 @@ using the basico package.
|
|
6
6
|
"""
|
7
7
|
|
8
8
|
from typing import Optional, Dict, Union
|
9
|
+
from time import sleep
|
10
|
+
from urllib.error import URLError
|
9
11
|
from pydantic import Field, model_validator
|
10
12
|
import pandas as pd
|
11
13
|
import basico
|
@@ -33,7 +35,17 @@ class BasicoModel(SysBioModel):
|
|
33
35
|
if not self.model_id and not self.sbml_file_path:
|
34
36
|
raise ValueError("Either model_id or sbml_file_path must be provided.")
|
35
37
|
if self.model_id:
|
36
|
-
|
38
|
+
attempts = 0
|
39
|
+
max_retries = 5
|
40
|
+
while attempts < max_retries:
|
41
|
+
try:
|
42
|
+
self.copasi_model = basico.load_biomodel(self.model_id)
|
43
|
+
break
|
44
|
+
except URLError as e:
|
45
|
+
attempts += 1
|
46
|
+
sleep(10*attempts)
|
47
|
+
if attempts >= max_retries:
|
48
|
+
raise e
|
37
49
|
self.description = basico.biomodels.get_model_info(self.model_id)["description"]
|
38
50
|
elif self.sbml_file_path:
|
39
51
|
self.copasi_model = basico.load_model(self.sbml_file_path)
|
@@ -1,7 +1,10 @@
|
|
1
1
|
'''
|
2
2
|
This file is used to import all the modules in the package.
|
3
3
|
'''
|
4
|
+
# import everything from the module
|
5
|
+
from . import ask_question
|
4
6
|
from . import simulate_model
|
7
|
+
from . import custom_plotter
|
8
|
+
from . import fetch_parameters
|
5
9
|
from . import model_description
|
6
|
-
from . import
|
7
|
-
from . import plot_figure
|
10
|
+
from . import search_models
|
@@ -4,6 +4,8 @@
|
|
4
4
|
Tool for fetching species and parameters from the model.
|
5
5
|
"""
|
6
6
|
|
7
|
+
from urllib.error import URLError
|
8
|
+
from time import sleep
|
7
9
|
from typing import Type
|
8
10
|
import basico
|
9
11
|
from pydantic import BaseModel, Field
|
@@ -47,14 +49,36 @@ class FetchParametersTool(BaseTool):
|
|
47
49
|
# Extract species from the model
|
48
50
|
species = []
|
49
51
|
if fetch_species:
|
50
|
-
df_species =
|
52
|
+
df_species = self.get_species_and_parameters(model_obj, fetch_species=True)
|
51
53
|
species = df_species.index.tolist()
|
52
54
|
species = ','.join(species)
|
53
55
|
|
54
56
|
# Extract parameters from the model
|
55
57
|
parameters = []
|
56
58
|
if fetch_parameters:
|
57
|
-
df_parameters =
|
59
|
+
df_parameters = self.get_species_and_parameters(model_obj, fetch_species=False)
|
58
60
|
parameters = df_parameters.index.tolist()
|
59
61
|
parameters = ','.join(parameters)
|
60
62
|
return {'Species': species, 'Parameters': parameters}
|
63
|
+
|
64
|
+
def get_species_and_parameters(self,
|
65
|
+
model_obj,
|
66
|
+
fetch_species: bool):
|
67
|
+
"""
|
68
|
+
Get the species from the model.
|
69
|
+
"""
|
70
|
+
attempts = 0
|
71
|
+
max_retries = 3
|
72
|
+
while attempts < max_retries:
|
73
|
+
try:
|
74
|
+
if fetch_species:
|
75
|
+
df = basico.model_info.get_species(model=model_obj.copasi_model)
|
76
|
+
else:
|
77
|
+
df = basico.model_info.get_parameters(model=model_obj.copasi_model)
|
78
|
+
break
|
79
|
+
except URLError as e:
|
80
|
+
attempts += 1
|
81
|
+
sleep(10)
|
82
|
+
if attempts >= max_retries:
|
83
|
+
raise e
|
84
|
+
return df
|
@@ -4,6 +4,8 @@
|
|
4
4
|
Tool for searching models based on search query.
|
5
5
|
"""
|
6
6
|
|
7
|
+
from urllib.error import URLError
|
8
|
+
from time import sleep
|
7
9
|
from typing import Type
|
8
10
|
from pydantic import BaseModel, Field
|
9
11
|
from basico import biomodels
|
@@ -39,7 +41,17 @@ class SearchModelsTool(BaseTool):
|
|
39
41
|
Returns:
|
40
42
|
str: The answer to the question.
|
41
43
|
"""
|
42
|
-
|
44
|
+
attempts = 0
|
45
|
+
max_retries = 3
|
46
|
+
while attempts < max_retries:
|
47
|
+
try:
|
48
|
+
search_results = biomodels.search_for_model(query)
|
49
|
+
break
|
50
|
+
except URLError as e:
|
51
|
+
attempts += 1
|
52
|
+
sleep(10)
|
53
|
+
if attempts >= max_retries:
|
54
|
+
raise e
|
43
55
|
llm = ChatOpenAI(model="gpt-4o-mini")
|
44
56
|
# Check if run_manager's metadata has the key 'prompt_content'
|
45
57
|
prompt_content = f'''
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: aiagents4pharma
|
3
|
-
Version: 1.4.
|
3
|
+
Version: 1.4.3
|
4
4
|
Summary: AI Agents for drug discovery, drug development, and other pharmaceutical R&D
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
@@ -90,7 +90,7 @@ Check out the tutorials on each agent for detailed instrcutions.
|
|
90
90
|
|
91
91
|
2. **Install dependencies:**
|
92
92
|
```bash
|
93
|
-
pip install
|
93
|
+
pip install .
|
94
94
|
```
|
95
95
|
|
96
96
|
3. **Initialize OPENAI_API_KEY**
|
@@ -1,18 +1,17 @@
|
|
1
1
|
aiagents4pharma/__init__.py,sha256=OF-rmtiLauF4NIlzEvMrWhNiX-mo5NJ4vrUtQbcLwts,93
|
2
2
|
aiagents4pharma/talk2biomodels/__init__.py,sha256=MueXwbnuiQyiju7mW6NepFUiZJdodMzmUK3TkQT7iPk,99
|
3
3
|
aiagents4pharma/talk2biomodels/models/__init__.py,sha256=5fTHHm3PVloYPNKXbgNlcPgv3-u28ZquxGydFYDfhJA,122
|
4
|
-
aiagents4pharma/talk2biomodels/models/basico_model.py,sha256=
|
4
|
+
aiagents4pharma/talk2biomodels/models/basico_model.py,sha256=UzTj6EUS7GiaNJogRUY5LkEYv-mUw2kO10v1NW89nPw,4597
|
5
5
|
aiagents4pharma/talk2biomodels/models/sys_bio_model.py,sha256=xN-ZXCpIxNkEXuDIvi_AW6LpCyPqXReGyhLPyJIXNqs,1980
|
6
|
-
aiagents4pharma/talk2biomodels/tools/__init__.py,sha256=
|
6
|
+
aiagents4pharma/talk2biomodels/tools/__init__.py,sha256=qO3MYCJmXpoUlZYtSW3VxTXdt-yUNHyH-Ua578pdyhg,280
|
7
7
|
aiagents4pharma/talk2biomodels/tools/ask_question.py,sha256=o9ae4s3wsDFr_pGBU1cSxKhJ7E2yjybIzG1Y4z6957Y,4534
|
8
8
|
aiagents4pharma/talk2biomodels/tools/custom_plotter.py,sha256=CdgJjlHAkdyjnwPD6nHARsJXnx_CE0MWg5VOz4oBjY0,2910
|
9
|
-
aiagents4pharma/talk2biomodels/tools/fetch_parameters.py,sha256=
|
9
|
+
aiagents4pharma/talk2biomodels/tools/fetch_parameters.py,sha256=WdLGPdJi4DwGwYMoReByGE9O1Msv68jkVd02F8L2liM,2864
|
10
10
|
aiagents4pharma/talk2biomodels/tools/model_description.py,sha256=lcVKVvh50wJ4BmB7xMnTZOtWjCmQUnkh6TQJsX-IjGw,5338
|
11
|
-
aiagents4pharma/talk2biomodels/tools/
|
12
|
-
aiagents4pharma/talk2biomodels/tools/search_models.py,sha256=5qmgQcwlICYAFG11y-aEhBSeYYT6Lu6AKGL2V-p1ggQ,2685
|
11
|
+
aiagents4pharma/talk2biomodels/tools/search_models.py,sha256=cqsK_ApjrAyjEiXWsXTebDpuvEnA5nb6WYiUGayRkW4,3034
|
13
12
|
aiagents4pharma/talk2biomodels/tools/simulate_model.py,sha256=MxlAy62SuonBbEbKmoUz0HcdfTWvk-x9WMSo17dBU9U,7552
|
14
|
-
aiagents4pharma-1.4.
|
15
|
-
aiagents4pharma-1.4.
|
16
|
-
aiagents4pharma-1.4.
|
17
|
-
aiagents4pharma-1.4.
|
18
|
-
aiagents4pharma-1.4.
|
13
|
+
aiagents4pharma-1.4.3.dist-info/LICENSE,sha256=IcIbyB1Hyk5ZDah03VNQvJkbNk2hkBCDqQ8qtnCvB4Q,1077
|
14
|
+
aiagents4pharma-1.4.3.dist-info/METADATA,sha256=i7KyLyZ8Lkp38BuHOt2eQ44uHqWtLr1xZ83u0HuzCOo,6622
|
15
|
+
aiagents4pharma-1.4.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
16
|
+
aiagents4pharma-1.4.3.dist-info/top_level.txt,sha256=-AH8rMmrSnJtq7HaAObS78UU-cTCwvX660dSxeM7a0A,16
|
17
|
+
aiagents4pharma-1.4.3.dist-info/RECORD,,
|
@@ -1,135 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
|
3
|
-
"""
|
4
|
-
Tool for plotting a figure.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from typing import Type, Optional
|
8
|
-
from dataclasses import dataclass
|
9
|
-
import matplotlib.pyplot as plt
|
10
|
-
from pydantic import BaseModel, Field
|
11
|
-
import streamlit as st
|
12
|
-
from langchain_openai import ChatOpenAI
|
13
|
-
from langchain_core.tools import BaseTool
|
14
|
-
from langchain_core.prompts import ChatPromptTemplate
|
15
|
-
from langchain_core.output_parsers.openai_tools import JsonOutputKeyToolsParser
|
16
|
-
from langchain_experimental.tools import PythonAstREPLTool
|
17
|
-
from ..models.basico_model import BasicoModel
|
18
|
-
|
19
|
-
@dataclass
|
20
|
-
class ModelData:
|
21
|
-
"""
|
22
|
-
Dataclass for storing the model data.
|
23
|
-
"""
|
24
|
-
modelid: Optional[int] = None
|
25
|
-
sbml_file_path: Optional[str] = None
|
26
|
-
model_object: Optional[BasicoModel] = None
|
27
|
-
|
28
|
-
class PlotImageInput(BaseModel):
|
29
|
-
"""
|
30
|
-
Input schema for the PlotImage tool.
|
31
|
-
"""
|
32
|
-
question: str = Field(description="Description of the plot")
|
33
|
-
sys_bio_model: ModelData = Field(description="model data", default=None)
|
34
|
-
|
35
|
-
# Note: It's important that every field has type hints. BaseTool is a
|
36
|
-
# Pydantic class and not having type hints can lead to unexpected behavior.
|
37
|
-
class PlotImageTool(BaseTool):
|
38
|
-
"""
|
39
|
-
Tool for plotting a figure.
|
40
|
-
"""
|
41
|
-
name: str = "plot_figure"
|
42
|
-
description: str = "A tool to plot or visualize the simulation results."
|
43
|
-
args_schema: Type[BaseModel] = PlotImageInput
|
44
|
-
st_session_key: str = None
|
45
|
-
|
46
|
-
def _run(self,
|
47
|
-
question: str,
|
48
|
-
sys_bio_model: ModelData = ModelData()) -> str:
|
49
|
-
"""
|
50
|
-
Run the tool.
|
51
|
-
|
52
|
-
Args:
|
53
|
-
question (str): The question to ask about the model description.
|
54
|
-
sys_bio_model (ModelData): The model data.
|
55
|
-
|
56
|
-
Returns:
|
57
|
-
str: The answer to the question
|
58
|
-
"""
|
59
|
-
st_session_key = self.st_session_key
|
60
|
-
# Check if sys_bio_model is provided
|
61
|
-
if sys_bio_model.modelid or sys_bio_model.sbml_file_path or sys_bio_model.model_object:
|
62
|
-
if sys_bio_model.modelid:
|
63
|
-
model_object = BasicoModel(model_id=sys_bio_model.modelid)
|
64
|
-
elif sys_bio_model.sbml_file_path:
|
65
|
-
model_object = BasicoModel(sbml_file_path=sys_bio_model.sbml_file_path)
|
66
|
-
else:
|
67
|
-
model_object = sys_bio_model.model_object
|
68
|
-
if st_session_key:
|
69
|
-
st.session_state[st_session_key] = model_object
|
70
|
-
else:
|
71
|
-
# If the model_object is not provided,
|
72
|
-
# get it from the Streamlit session state
|
73
|
-
if st_session_key:
|
74
|
-
if st_session_key not in st.session_state:
|
75
|
-
return f"Session key {st_session_key} not found in Streamlit session state."
|
76
|
-
model_object = st.session_state[st_session_key]
|
77
|
-
else:
|
78
|
-
return "Please provide a valid model object or \
|
79
|
-
Streamlit session key that contains the model object."
|
80
|
-
if model_object is None:
|
81
|
-
return "Please run the simulation first before plotting the figure."
|
82
|
-
if model_object.simulation_results is None:
|
83
|
-
model_object.simulate()
|
84
|
-
df = model_object.simulation_results
|
85
|
-
tool = PythonAstREPLTool(locals={"df": df})
|
86
|
-
llm = ChatOpenAI(model="gpt-3.5-turbo")
|
87
|
-
llm_with_tools = llm.bind_tools([tool], tool_choice=tool.name)
|
88
|
-
system = f"""
|
89
|
-
You have access to a pandas dataframe `df`.
|
90
|
-
Here is the output of `df.head().to_markdown()`:
|
91
|
-
{df.head().to_markdown()}
|
92
|
-
Given a user question, write the Python code to
|
93
|
-
plot a figure of the answer using matplolib.
|
94
|
-
Return ONLY the valid Python code and nothing else.
|
95
|
-
The firgure size should be equal or smaller than (2, 2).
|
96
|
-
Show the grid and legend. The font size of the legend should be 6.
|
97
|
-
Also write a suitable title for the figure. The font size of the title should be 8.
|
98
|
-
The font size of the x-axis and y-axis labels should be 8.
|
99
|
-
The font size of the x-axis and y-axis ticks should be 6.
|
100
|
-
Make sure that the x-axis has at least 10 tick marks.
|
101
|
-
Use color-blind friendly colors. The figure must be of high quality.
|
102
|
-
Don't assume you have access to any libraries other
|
103
|
-
than built-in Python ones, pandas, streamlit and matplotlib.
|
104
|
-
"""
|
105
|
-
prompt = ChatPromptTemplate.from_messages([("system", system), ("human", "{question}")])
|
106
|
-
parser = JsonOutputKeyToolsParser(key_name=tool.name, first_tool_only=True)
|
107
|
-
code_chain = prompt | llm_with_tools | parser
|
108
|
-
response = code_chain.invoke({"question": question})
|
109
|
-
exec(response['query'], globals(), {"df": df, "plt": plt})
|
110
|
-
# load for plotly
|
111
|
-
fig = plt.gcf()
|
112
|
-
if st_session_key:
|
113
|
-
st.pyplot(fig, use_container_width=False)
|
114
|
-
st.dataframe(df)
|
115
|
-
return "Figure plotted successfully"
|
116
|
-
|
117
|
-
def call_run(self,
|
118
|
-
question: str,
|
119
|
-
sys_bio_model: ModelData = ModelData(),
|
120
|
-
st_session_key: str = None) -> str:
|
121
|
-
"""
|
122
|
-
Run the tool.
|
123
|
-
"""
|
124
|
-
return self._run(question=question,
|
125
|
-
sys_bio_model=sys_bio_model,
|
126
|
-
st_session_key=st_session_key)
|
127
|
-
|
128
|
-
def get_metadata(self):
|
129
|
-
"""
|
130
|
-
Get metadata for the tool.
|
131
|
-
"""
|
132
|
-
return {
|
133
|
-
"name": self.name,
|
134
|
-
"description": self.description
|
135
|
-
}
|
File without changes
|
File without changes
|