[3af7d7]: / aiagents4pharma / talk2biomodels / tests / test_search_models.py

Download this file

40 lines (36 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'''
Test cases for Talk2Biomodels search models tool.
'''
from langchain_core.messages import HumanMessage, ToolMessage
from langchain_openai import ChatOpenAI
from ..agents.t2b_agent import get_app
LLM_MODEL = ChatOpenAI(model='gpt-4o-mini', temperature=0)
def test_search_models_tool():
'''
Test the search_models tool.
'''
unique_id = 12345
app = get_app(unique_id, llm_model=LLM_MODEL)
config = {"configurable": {"thread_id": unique_id}}
prompt = "Search for models on Crohn's disease."
app.update_state(
config,
{"llm_model": LLM_MODEL}
)
# Test the tool get_modelinfo
response = app.invoke(
{"messages": [HumanMessage(content=prompt)]},
config=config
)
# Extract the assistant artifact which contains
# all the search results
found_model_537 = False
for msg in response["messages"]:
if isinstance(msg, ToolMessage) and msg.name == "search_models":
msg_artifact = msg.artifact
for model in msg_artifact["dic_data"]:
if model["id"] == "BIOMD0000000537":
found_model_537 = True
break
# Check if the model BIOMD0000000537 is found
assert found_model_537