Skip to content

Commit d5fcab1

Browse files
committed
fix tests
1 parent 07ac60e commit d5fcab1

12 files changed

+65
-2018
lines changed

backend/src/neuroagent/app/config.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,6 @@ class SettingsKGMorpho(BaseModel):
9999
model_config = ConfigDict(frozen=True)
100100

101101

102-
class SettingsGetMorpho(BaseModel):
103-
"""Get Morpho settings."""
104-
105-
search_size: int = 10
106-
107-
model_config = ConfigDict(frozen=True)
108-
109-
110102
class SettingsGetMEModel(BaseModel):
111103
"""Get ME Model settings."""
112104

@@ -163,7 +155,6 @@ class SettingsTools(BaseModel):
163155
obi_one: SettingsObiOne = SettingsObiOne()
164156
bluenaas: SettingsBlueNaaS = SettingsBlueNaaS()
165157
entitycore: SettingsEntityCore = SettingsEntityCore()
166-
morpho: SettingsGetMorpho = SettingsGetMorpho()
167158
trace: SettingsTrace = SettingsTrace()
168159
kg_morpho_features: SettingsKGMorpho = SettingsKGMorpho()
169160
me_model: SettingsGetMEModel = SettingsGetMEModel()

backend/src/neuroagent/app/dependencies.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
MorphoMetricsTool,
3636
PlotGeneratorTool,
3737
ResolveBrainRegionTool,
38-
ResolveETypeTool,
3938
ResolveMtypeTool,
4039
SCSGetAllTool,
4140
SCSGetOneTool,
@@ -181,7 +180,6 @@ def get_tool_list() -> list[type[BaseTool]]:
181180
KGMorphoFeatureTool,
182181
ResolveBrainRegionTool,
183182
ResolveMtypeTool,
184-
ResolveETypeTool,
185183
MorphoMetricsTool,
186184
GetTracesTool,
187185
PlotGeneratorTool,
@@ -320,15 +318,14 @@ def get_context_variables(
320318
"knowledge_graph_url": settings.knowledge_graph.url,
321319
"literature_search_url": settings.tools.literature.url,
322320
"me_model_search_size": settings.tools.me_model.search_size,
323-
"morpho_search_size": settings.tools.morpho.search_size,
324321
"obi_one_url": settings.tools.obi_one.url,
325322
"openai_client": openai_client,
326323
"project_id": thread.project_id,
327324
"retriever_k": settings.tools.literature.retriever_k,
328325
"s3_client": s3_client,
329326
"starting_agent": starting_agent,
330-
"thread_id": thread.thread_id,
331327
"tavily_api_key": settings.tools.web_search.tavily_api_key,
328+
"thread_id": thread.thread_id,
332329
"token": token,
333330
"trace_search_size": settings.tools.trace.search_size,
334331
"use_reranker": settings.tools.literature.use_reranker,
@@ -348,12 +345,12 @@ def get_healthcheck_variables(
348345
correct service.
349346
"""
350347
return {
348+
"bluenaas_url": settings.tools.bluenaas.url.rstrip("/") + "/",
349+
"entitycore_url": settings.tools.entitycore.url.rstrip("/") + "/",
351350
"httpx_client": httpx_client,
352-
"literature_search_url": settings.tools.literature.url.rstrip("/") + "/",
353351
"knowledge_graph_url": settings.knowledge_graph.base_url.rstrip("/") + "/",
354-
"bluenaas_url": settings.tools.bluenaas.url.rstrip("/") + "/",
352+
"literature_search_url": settings.tools.literature.url.rstrip("/") + "/",
355353
"obi_one_url": settings.tools.obi_one.url.rstrip("/") + "/",
356-
"entitycore_url": settings.tools.entitycore.url.rstrip("/") + "/",
357354
}
358355

359356

backend/src/neuroagent/tools/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from neuroagent.tools.morphology_viewer import MorphologyViewerTool
2020
from neuroagent.tools.now import NowTool
2121
from neuroagent.tools.resolve_brain_region_tool import ResolveBrainRegionTool
22-
from neuroagent.tools.resolve_etypes_tool import ResolveETypeTool
2322
from neuroagent.tools.resolve_mtypes_tool import ResolveMtypeTool
2423
from neuroagent.tools.traces_tool import GetTracesTool
2524
from neuroagent.tools.weather import WeatherTool
@@ -45,7 +44,6 @@
4544
"RandomPlotGeneratorTool",
4645
"ResolveBrainRegionTool",
4746
"ResolveMtypeTool",
48-
"ResolveETypeTool",
4947
"WeatherTool",
5048
"WebSearchTool",
5149
]

backend/src/neuroagent/tools/get_morpho_tool.py

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
"""Get Morpho tool."""
22

33
import logging
4-
from typing import Any, ClassVar
4+
from typing import ClassVar
55

66
from httpx import AsyncClient
77
from pydantic import BaseModel, Field
88

9+
from neuroagent.tools.autogenerated_types.entitycore.models import (
10+
ListResponseReconstructionMorphologyRead,
11+
)
912
from neuroagent.tools.base_tool import BaseMetadata, BaseTool
1013

1114
logger = logging.getLogger(__name__)
@@ -15,12 +18,13 @@ class GetMorphoInput(BaseModel):
1518
"""Inputs of the knowledge graph API."""
1619

1720
brain_region_id: str = Field(
18-
description="ID of the brain region of interest in UUID format. To find the ID use the resolve-entity-tool first."
21+
description="ID of the brain region of interest in UUID format. To find the ID use the resolve-brain-region-tool first."
1922
)
23+
page_size: int = Field(default=10, description="Number of results per page.")
2024
page: int = Field(default=1, description="Page number for pagination.")
2125
mtype_id: str | None = Field(
2226
default=None,
23-
description="ID of the M-type of interest. To find the ID use the resolve-entity-tool first.",
27+
description="ID of the M-type of interest. To find the ID use the resolve-mtype-tool first.",
2428
)
2529

2630

@@ -29,7 +33,8 @@ class GetMorphoMetadata(BaseMetadata):
2933

3034
entitycore_url: str
3135
token: str
32-
morpho_search_size: int
36+
vlab_id: str | None
37+
project_id: str | None
3338

3439

3540
class MtypeOutput(BaseModel):
@@ -40,29 +45,6 @@ class MtypeOutput(BaseModel):
4045
alt_label: str | None
4146

4247

43-
class MorphologieOutput(BaseModel):
44-
"""Output schema for the knowledge graph API."""
45-
46-
morphology_id: str
47-
morphology_name: str | None
48-
morphology_description: str | None
49-
mtype: list[MtypeOutput] | None
50-
51-
brain_region_id: str
52-
brain_region_name: str | None
53-
54-
subject_species_name: str | None
55-
56-
57-
class GetMorphoToolOutput(BaseModel):
58-
"""Output schema for the Morpho tool."""
59-
60-
morphologies: list[MorphologieOutput]
61-
current_page: int
62-
page_size: int
63-
total_items_found: int
64-
65-
6648
class GetMorphoTool(BaseTool):
6749
"""Class defining the Get Morpho logic."""
6850

@@ -92,7 +74,7 @@ class GetMorphoTool(BaseTool):
9274
metadata: GetMorphoMetadata
9375
input_schema: GetMorphoInput
9476

95-
async def arun(self) -> GetMorphoToolOutput:
77+
async def arun(self) -> ListResponseReconstructionMorphologyRead:
9678
"""From a brain region ID, extract morphologies.
9779
9880
Returns
@@ -105,9 +87,22 @@ async def arun(self) -> GetMorphoToolOutput:
10587

10688
response = await self.metadata.httpx_client.get(
10789
url=self.metadata.entitycore_url + "/reconstruction-morphology",
108-
headers={"Authorization": f"Bearer {self.metadata.token}"},
90+
headers={
91+
"Authorization": f"Bearer {self.metadata.token}",
92+
**(
93+
{"virtual-lab-id": self.metadata.vlab_id}
94+
if self.metadata.vlab_id is not None
95+
else {}
96+
),
97+
**(
98+
{"project-id": self.metadata.project_id}
99+
if self.metadata.project_id is not None
100+
else {}
101+
),
102+
},
109103
params={
110-
"page_size": self.metadata.morpho_search_size,
104+
"page_size": self.input_schema.page_size,
105+
"page": self.input_schema.page,
111106
"within_brain_region_hierachy_id": "e3e70682-c209-4cac-a29f-6fbed82c07cd", # TEMP for mouse brain
112107
"within_brain_region_brain_region_id": self.input_schema.brain_region_id,
113108
"within_brain_region_ascendants": False,
@@ -118,48 +113,11 @@ async def arun(self) -> GetMorphoToolOutput:
118113
),
119114
},
120115
)
121-
122-
return self._process_output(response.json())
123-
124-
@staticmethod
125-
def _process_output(output: Any) -> GetMorphoToolOutput:
126-
"""Process output to fit the KnowledgeGraphOutput pydantic class defined above.
127-
128-
Parameters
129-
----------
130-
output
131-
Raw output of the arun method, which comes from the KG
132-
133-
Returns
134-
-------
135-
list of KGMorphoFeatureOutput to describe the morphology and its metadata.
136-
"""
137-
formatted_output = [
138-
MorphologieOutput(
139-
morphology_id=res["id"],
140-
morphology_name=res.get("name"),
141-
morphology_description=res.get("description"),
142-
mtype=[
143-
MtypeOutput(
144-
mtype_id=mtype["id"],
145-
pref_label=mtype.get("pref_label"),
146-
alt_label=mtype.get("alt_label"),
147-
)
148-
for mtype in res.get("mtypes")
149-
],
150-
brain_region_id=res["brain_region"]["id"],
151-
brain_region_name=res["brain_region"].get("Name"),
152-
subject_species_name=res["species"].get("name"),
116+
if response.status_code != 200:
117+
raise ValueError(
118+
f"The morphology endpoint returned a non 200 response code. Error: {response.text}"
153119
)
154-
for res in output["data"]
155-
]
156-
pagination_data = output["pagination"]
157-
return GetMorphoToolOutput(
158-
morphologies=formatted_output,
159-
current_page=pagination_data["page"],
160-
page_size=pagination_data["page_size"],
161-
total_items_found=pagination_data["total_items"],
162-
)
120+
return ListResponseReconstructionMorphologyRead(**response.json())
163121

164122
@classmethod
165123
async def is_online(cls, *, httpx_client: AsyncClient, entitycore_url: str) -> bool:

backend/src/neuroagent/tools/resolve_brain_region_tool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ async def arun(
6868
url=self.metadata.entitycore_url + "/brain-region",
6969
headers={"Authorization": f"Bearer {self.metadata.token}"},
7070
params={
71+
"hierarchy_id": "e3e70682-c209-4cac-a29f-6fbed82c07cd",
7172
"page_size": 500,
7273
"name__ilike": self.input_schema.brain_region,
7374
},

backend/src/neuroagent/tools/resolve_etypes_tool.py

Lines changed: 0 additions & 78 deletions
This file was deleted.

backend/src/neuroagent/tools/resolve_mtypes_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def arun(
6969
url=self.metadata.entitycore_url + "/mtype",
7070
headers={"Authorization": f"Bearer {self.metadata.token}"},
7171
params={
72-
"page_size": 100,
72+
"page_size": 1,
7373
"pref_label": self.input_schema.mtype,
7474
},
7575
)

backend/tests/app/test_config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ def test_no_settings():
2929

3030
def test_setup_tools(monkeypatch, patch_required_env):
3131
monkeypatch.setenv("NEUROAGENT_TOOLS__TRACE__SEARCH_SIZE", "20")
32-
monkeypatch.setenv("NEUROAGENT_TOOLS__MORPHO__SEARCH_SIZE", "20")
3332
monkeypatch.setenv("NEUROAGENT_TOOLS__KG_MORPHO_FEATURES__SEARCH_SIZE", "20")
3433

3534
settings = Settings()
3635

37-
assert settings.tools.morpho.search_size == 20
3836
assert settings.tools.trace.search_size == 20
3937
assert settings.tools.kg_morpho_features.search_size == 20

0 commit comments

Comments
 (0)