aiagents4pharma 1.4.0__tar.gz → 1.4.2__tar.gz
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-1.4.0 → aiagents4pharma-1.4.2}/PKG-INFO +1 -1
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/tools/__init__.py +5 -2
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/tools/simulate_model.py +37 -34
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma.egg-info/PKG-INFO +1 -1
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma.egg-info/SOURCES.txt +0 -1
- aiagents4pharma-1.4.2/release_version.txt +1 -0
- aiagents4pharma-1.4.0/aiagents4pharma/talk2biomodels/tools/plot_figure.py +0 -135
- aiagents4pharma-1.4.0/release_version.txt +0 -1
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/LICENSE +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/README.md +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/__init__.py +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/__init__.py +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/models/__init__.py +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/models/basico_model.py +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/models/sys_bio_model.py +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/tools/ask_question.py +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/tools/custom_plotter.py +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/tools/fetch_parameters.py +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/tools/model_description.py +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/tools/search_models.py +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma.egg-info/dependency_links.txt +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma.egg-info/requires.txt +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma.egg-info/top_level.txt +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/pyproject.toml +0 -0
- {aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: aiagents4pharma
|
3
|
-
Version: 1.4.
|
3
|
+
Version: 1.4.2
|
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
|
{aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/tools/__init__.py
RENAMED
@@ -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,13 +4,13 @@
|
|
4
4
|
Tool for simulating a model.
|
5
5
|
"""
|
6
6
|
|
7
|
-
from typing import Type, Union, List, Optional
|
8
|
-
import basico
|
7
|
+
from typing import Type, Union, List, Optional
|
9
8
|
from dataclasses import dataclass
|
9
|
+
import basico
|
10
10
|
from pydantic import BaseModel, Field
|
11
11
|
from langchain_core.tools import BaseTool
|
12
12
|
import streamlit as st
|
13
|
-
import plotly.express as px
|
13
|
+
# import plotly.express as px
|
14
14
|
from ..models.basico_model import BasicoModel
|
15
15
|
|
16
16
|
@dataclass
|
@@ -91,33 +91,36 @@ class SimulateModelTool(BaseTool):
|
|
91
91
|
Returns:
|
92
92
|
str: The result of the simulation.
|
93
93
|
"""
|
94
|
-
st_session_key = self.st_session_key
|
94
|
+
# st_session_key = self.st_session_key
|
95
95
|
# Retrieve the model ID, duration, and interval
|
96
96
|
modelid = model_data.modelid if model_data is not None else None
|
97
|
-
duration = time_data.duration if time_data is not None else 100.0
|
98
|
-
interval = time_data.interval if time_data is not None else 10
|
97
|
+
# duration = time_data.duration if time_data is not None else 100.0
|
98
|
+
# interval = time_data.interval if time_data is not None else 10
|
99
99
|
# Prepare the dictionary of species data
|
100
100
|
# that will be passed to the simulate method
|
101
101
|
# of the BasicoModel class
|
102
|
-
dic_species_data = None
|
103
|
-
if species_data is not None:
|
104
|
-
|
105
|
-
|
102
|
+
# dic_species_data = None
|
103
|
+
# if species_data is not None:
|
104
|
+
# dic_species_data = dict(zip(species_data.species_name,
|
105
|
+
# species_data.species_concentration))
|
106
|
+
dic_species_data = dict(zip(species_data.species_name, \
|
107
|
+
species_data.species_concentration)) \
|
108
|
+
if species_data is not None else None
|
106
109
|
# Retrieve the SBML file path from the Streamlit session state
|
107
110
|
# otherwise retrieve it from the model_data object if the user
|
108
111
|
# has provided it.
|
109
112
|
sbml_file_path = model_data.sbml_file_path if model_data is not None else None
|
110
|
-
if st_session_key:
|
111
|
-
if st_session_key not in st.session_state:
|
112
|
-
return f"Session key {st_session_key} not found in Streamlit session state."
|
113
|
+
if self.st_session_key:
|
114
|
+
if self.st_session_key not in st.session_state:
|
115
|
+
return f"Session key {self.st_session_key} not found in Streamlit session state."
|
113
116
|
if 'sbml_file_path' in st.session_state:
|
114
117
|
sbml_file_path = st.session_state.sbml_file_path
|
115
118
|
# Check if both modelid and sbml_file_path are None
|
116
119
|
if modelid is None and sbml_file_path is None:
|
117
120
|
# Then load the model from the Streamlit session state
|
118
121
|
# if the streamlit session exists
|
119
|
-
if st_session_key:
|
120
|
-
model_object = st.session_state[st_session_key]
|
122
|
+
if self.st_session_key:
|
123
|
+
model_object = st.session_state[self.st_session_key]
|
121
124
|
# If this model object is None, then return an error message
|
122
125
|
if model_object is None:
|
123
126
|
return "Please provide a BioModels ID or an SBML file path for simulation."
|
@@ -131,13 +134,13 @@ class SimulateModelTool(BaseTool):
|
|
131
134
|
# model_object = BasicoModel(model_id=modelid)
|
132
135
|
model_object = BasicoModel(model_id=modelid)
|
133
136
|
# Save the model object in the Streamlit session state
|
134
|
-
st.session_state[st_session_key] = model_object
|
137
|
+
st.session_state[self.st_session_key] = model_object
|
135
138
|
elif sbml_file_path:
|
136
139
|
# Create a BasicoModel object with the SBML file path
|
137
140
|
model_object = BasicoModel(sbml_file_path=sbml_file_path)
|
138
141
|
modelid = model_object.model_id
|
139
142
|
# Save the model object in the Streamlit session state
|
140
|
-
st.session_state[st_session_key] = model_object
|
143
|
+
st.session_state[self.st_session_key] = model_object
|
141
144
|
# Add recurring events (if any) to the model
|
142
145
|
if recurring_data is not None:
|
143
146
|
for row in recurring_data.data:
|
@@ -149,29 +152,30 @@ class SimulateModelTool(BaseTool):
|
|
149
152
|
# print (f'Added event {sn}_{tp} at time {tp} \
|
150
153
|
# for species {sn} with concentration {sc}')
|
151
154
|
# Simulate the model
|
152
|
-
df = model_object.simulate(
|
153
|
-
|
154
|
-
|
155
|
+
df = model_object.simulate(
|
156
|
+
parameters=dic_species_data,
|
157
|
+
duration=time_data.duration if time_data is not None else 100.0,
|
158
|
+
interval=time_data.interval if time_data is not None else 10)
|
155
159
|
# Convert the DataFrame to long format for plotting
|
156
160
|
# and ignore the index column
|
157
161
|
df = df.melt(id_vars='Time',
|
158
162
|
var_name='Species',
|
159
163
|
value_name='Concentration')
|
160
164
|
# Plot the simulation results using Plotly
|
161
|
-
fig = px.line(df,
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
)
|
165
|
+
# fig = px.line(df,
|
166
|
+
# x='Time',
|
167
|
+
# y='Concentration',
|
168
|
+
# color='Species',
|
169
|
+
# title=f"Concentration of Species over Time in the model {modelid}",
|
170
|
+
# height=600,
|
171
|
+
# width=800
|
172
|
+
# )
|
169
173
|
# Display the plot in Streamlit
|
170
174
|
# st.plotly_chart(fig, use_container_width = False)
|
171
|
-
if modelid is None:
|
172
|
-
|
173
|
-
|
174
|
-
return
|
175
|
+
# if modelid is None:
|
176
|
+
# modelid = "internal"
|
177
|
+
# return f"Simulation results for the model {modelid}."
|
178
|
+
return "Simulation results for the model."
|
175
179
|
|
176
180
|
def get_metadata(self):
|
177
181
|
"""
|
@@ -182,6 +186,5 @@ class SimulateModelTool(BaseTool):
|
|
182
186
|
"""
|
183
187
|
return {
|
184
188
|
"name": self.name,
|
185
|
-
"description": self.description
|
186
|
-
"return_direct": self.return_direct,
|
189
|
+
"description": self.description
|
187
190
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: aiagents4pharma
|
3
|
-
Version: 1.4.
|
3
|
+
Version: 1.4.2
|
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
|
@@ -17,6 +17,5 @@ aiagents4pharma/talk2biomodels/tools/ask_question.py
|
|
17
17
|
aiagents4pharma/talk2biomodels/tools/custom_plotter.py
|
18
18
|
aiagents4pharma/talk2biomodels/tools/fetch_parameters.py
|
19
19
|
aiagents4pharma/talk2biomodels/tools/model_description.py
|
20
|
-
aiagents4pharma/talk2biomodels/tools/plot_figure.py
|
21
20
|
aiagents4pharma/talk2biomodels/tools/search_models.py
|
22
21
|
aiagents4pharma/talk2biomodels/tools/simulate_model.py
|
@@ -0,0 +1 @@
|
|
1
|
+
v1.4.2
|
@@ -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
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
v1.4.0
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/models/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma/talk2biomodels/tools/ask_question.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{aiagents4pharma-1.4.0 → aiagents4pharma-1.4.2}/aiagents4pharma.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|