Skip to content

Commit

Permalink
Remove unnecessary dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kanesoban committed Dec 5, 2024
1 parent 5153c00 commit 9a77d37
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 91 deletions.
2 changes: 1 addition & 1 deletion swarm_copy/tools/bluenaas_memodel_getall.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class InputMEModelGetAll(BaseModel):
page_size: int = Field(
default=20, description="Number of results returned by the API."
)
simulation_type: Literal["single-neuron-simulation", "synaptome-simulation"] = (
memodel_type: Literal["single-neuron-simulation", "synaptome-simulation"] = (
Field(
default="single-neuron-simulation",
description="Type of simulation to retrieve.",
Expand Down
4 changes: 2 additions & 2 deletions swarm_copy/tools/bluenaas_memodel_getone.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MEModelGetOneMetadata(BaseMetadata):
class InputMEModelGetOne(BaseModel):
"""Inputs for the BlueNaaS single-neuron simulation."""

simulation_id: str = Field(
memodel_id: str = Field(
description="ID of the model to retrieve. Should be an https link."
)

Expand All @@ -45,7 +45,7 @@ async def arun(self) -> MEModelResponse:
)

response = await self.metadata.httpx_client.get(
url=f"{self.metadata.bluenaas_url}/neuron-model/{self.metadata.vlab_id}/{self.metadata.project_id}/{quote_plus(self.input_schema.simulation_id)}",
url=f"{self.metadata.bluenaas_url}/neuron-model/{self.metadata.vlab_id}/{self.metadata.project_id}/{quote_plus(self.input_schema.memodel_id)}",
headers={"Authorization": f"Bearer {self.metadata.token}"},
)

Expand Down
92 changes: 4 additions & 88 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
import pytest_asyncio
from fastapi.testclient import TestClient
from httpx import AsyncClient
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage
from sqlalchemy import MetaData
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine

from neuroagent.app.config import Settings
from neuroagent.app.dependencies import get_kg_token, get_settings
from neuroagent.app.main import app
from neuroagent.tools import GetMorphoTool
from swarm_copy.app.config import Settings
from swarm_copy.app.dependencies import get_kg_token, get_settings
from swarm_copy.app.main import app
from swarm_copy.tools import GetMorphoTool


@pytest.fixture(name="app_client")
Expand Down Expand Up @@ -105,85 +103,3 @@ def get_resolve_query_output():
def brain_region_json_path():
br_path = Path(__file__).parent / "data" / "brainregion_hierarchy.json"
return br_path


@pytest.fixture
async def fake_llm_with_tools(brain_region_json_path):
class FakeFuntionChatModel(GenericFakeChatModel):
def bind_tools(self, functions: list):
return self

def bind_functions(self, **kwargs):
return self

# If you need another fake response to use different tools,
# you can do in your test
# ```python
# llm, _ = await anext(fake_llm_with_tools)
# llm.responses = my_fake_responses
# ```
# and simply bind the corresponding tools
fake_responses = [
AIMessage(
content="",
additional_kwargs={
"tool_calls": [
{
"index": 0,
"id": "call_zHhwfNLSvGGHXMoILdIYtDVI",
"function": {
"arguments": '{"brain_region_id":"http://api.brain-map.org/api/v2/data/Structure/549"}',
"name": "get-morpho-tool",
},
"type": "function",
}
]
},
response_metadata={"finish_reason": "tool_calls"},
id="run-3828644d-197b-401b-8634-e6ecf01c2e7c-0",
tool_calls=[
{
"name": "get-morpho-tool",
"args": {
"brain_region_id": (
"http://api.brain-map.org/api/v2/data/Structure/549"
)
},
"id": "call_zHhwfNLSvGGHXMoILdIYtDVI",
}
],
),
AIMessage(
content="Great answer",
response_metadata={"finish_reason": "stop"},
id="run-42768b30-044a-4263-8c5c-da61429aa9da-0",
),
]

# If you use this tool in your test, DO NOT FORGET to mock the url response with the following snippet:
#
# ```python
# json_path = Path(__file__).resolve().parent.parent / "data" / "knowledge_graph.json"
# with open(json_path) as f:
# knowledge_graph_response = json.load(f)

# httpx_mock.add_response(
# url="http://fake_url",
# json=knowledge_graph_response,
# )
# ```
# The http call is not mocked here because one might want to change the responses
# and the tools used.
async_client = AsyncClient()
tool = GetMorphoTool(
metadata={
"url": "http://fake_url",
"search_size": 2,
"httpx_client": async_client,
"token": "fake_token",
"brainregion_path": brain_region_json_path,
}
)

yield FakeFuntionChatModel(messages=iter(fake_responses)), [tool], fake_responses
await async_client.aclose()

0 comments on commit 9a77d37

Please sign in to comment.