Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kanesoban committed Dec 11, 2024
1 parent d7c13c8 commit 8d8e93e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 94 deletions.
1 change: 0 additions & 1 deletion swarm_copy/app/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ async def get_vlab_and_project(
}
else:
thread_id = request.path_params.get("thread_id")
logging.error(f"*** Thread id: {thread_id}, User id: {user_id} ***")
thread_result = await session.execute(
select(Threads).where(
Threads.user_id == user_id, Threads.thread_id == thread_id
Expand Down
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 @@ -55,7 +55,7 @@ async def arun(self) -> PaginatedResponseUnionMEModelResponseSynaptomeModelRespo
response = await self.metadata.httpx_client.get(
url=f"{self.metadata.bluenaas_url}/neuron-model/{self.metadata.vlab_id}/{self.metadata.project_id}/me-models",
params={
"simulation_type": self.input_schema.memodel_type,
"model_type": self.input_schema.memodel_type,
"offset": self.input_schema.offset,
"page_size": self.input_schema.page_size,
},
Expand Down
2 changes: 0 additions & 2 deletions swarm_copy_tests/app/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ async def test_get_vlab_and_project(
)
session.add(new_thread)
await session.commit()
await session.refresh(new_thread)

try:
# Test with info in headers.
Expand Down Expand Up @@ -265,7 +264,6 @@ async def test_get_vlab_and_project_no_info_in_headers(
)
session.add(new_thread)
await session.commit()
await session.refresh(new_thread)

try:
# Test with no infos in headers.
Expand Down
4 changes: 2 additions & 2 deletions swarm_copy_tests/app/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from fastapi.testclient import TestClient

from neuroagent.app.dependencies import get_settings
from neuroagent.app.main import app
from swarm_copy.app.dependencies import get_settings
from swarm_copy.app.main import app


def test_settings_endpoint(app_client, dont_look_at_env_file, settings):
Expand Down
92 changes: 4 additions & 88 deletions swarm_copy_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="settings")
Expand Down Expand Up @@ -126,85 +124,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 8d8e93e

Please sign in to comment.