-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluenaas tool #15
Open
KeremKurban
wants to merge
35
commits into
main
Choose a base branch
from
bluenaas_tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Bluenaas tool #15
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
96f009b
me model tool addition
7ebab6f
add changelog, fix mypy and lint errors
64bdfe5
rm breakpoint
8d58c2a
ruff
5e5c244
ruff format
ee2e677
ruff bump version
16ead42
rename protected namespace : model_ field
cb37988
rename protected namespace for others
f662684
merge main into me_model
d2b41aa
update changelog
d9d2182
add dependencies, and config
706e666
update tool
40a5a02
implement kwargs in structured manner
af28eb5
running first example
73ce910
add cADpyr to accepted etypes in traces tool
325da59
untrack unnecessary file
05b31a3
updates on tool
ae17f31
cell types hierarchy updated
4a2b5eb
test createdBy works
2f1cd5d
remove comma from createdby elastic search query
09bdd39
update gitignore
3cdb503
add sim agent
f8148a8
handle user interruption
ce6a0c7
add hierarchical multiagent, incomplete
4ff3e1e
hierarchical chat multi agent
21e0ed4
improve multi chat agent
f475770
improve astream
949c511
untraack bluenass agent, fix errors
abb1f54
update .env.example , remove unnecessary tools from sim agent, refact…
bfde01a
make agent_node async
36c6e9f
encode http from me model
d1fe1cb
reset tests
e1af54f
update changelog
c24c6fd
untrack src/neuroagent/app/data/
58be908
clean
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,15 +25,17 @@ | |
from neuroagent.agents.base_agent import AsyncSqliteSaverWithPrefix | ||
from neuroagent.app.config import Settings | ||
from neuroagent.cell_types import CellTypesMeta | ||
from neuroagent.multi_agents import BaseMultiAgent, SupervisorMultiAgent | ||
from neuroagent.multi_agents import BaseMultiAgent, SupervisorMultiAgent, HierarchicalTeamAgent | ||
from neuroagent.tools import ( | ||
ElectrophysFeatureTool, | ||
GetMEModelTool, | ||
GetMorphoTool, | ||
GetTracesTool, | ||
KGMorphoFeatureTool, | ||
LiteratureSearchTool, | ||
MorphologyFeatureTool, | ||
ResolveBrainRegionTool, | ||
BlueNaaSTool, | ||
) | ||
from neuroagent.utils import RegionMeta, get_file_from_KG | ||
|
||
|
@@ -304,6 +306,44 @@ def get_morphology_feature_tool( | |
return tool | ||
|
||
|
||
def get_me_model_tool( | ||
settings: Annotated[Settings, Depends(get_settings)], | ||
token: Annotated[str, Depends(get_kg_token)], | ||
httpx_client: Annotated[AsyncClient, Depends(get_httpx_client)], | ||
) -> GetMEModelTool: | ||
"""Load get ME model tool.""" | ||
tool = GetMEModelTool( | ||
metadata={ | ||
"url": settings.knowledge_graph.url, | ||
"token": token, | ||
"httpx_client": httpx_client, | ||
"search_size": settings.tools.me_model.search_size, | ||
"brainregion_path": settings.knowledge_graph.br_saving_path, | ||
"celltypes_path": settings.knowledge_graph.ct_saving_path, | ||
} | ||
) | ||
return tool | ||
|
||
async def run_single_cell_sim_tool( | ||
settings: Annotated[Settings, Depends(get_settings)], | ||
token: Annotated[str, Depends(get_kg_token)], | ||
httpx_client: Annotated[AsyncClient, Depends(get_httpx_client)], | ||
) -> BlueNaaSTool: | ||
"""Load BlueNaaS tool.""" | ||
# Run GetMEModelTool to fetch me_model_id | ||
# Create BlueNaaSTool with the fetched me_model_id | ||
tool = BlueNaaSTool( | ||
metadata={ | ||
"url": settings.tools.bluenaas.url, | ||
"token": token, | ||
"httpx_client": httpx_client, | ||
} | ||
) | ||
return tool | ||
|
||
def get_project_id(): | ||
pass | ||
|
||
def get_language_model( | ||
settings: Annotated[Settings, Depends(get_settings)], | ||
) -> ChatOpenAI: | ||
|
@@ -315,7 +355,7 @@ def get_language_model( | |
openai_api_key=settings.openai.token.get_secret_value(), # type: ignore | ||
max_tokens=settings.openai.max_tokens, | ||
seed=78, | ||
streaming=True, | ||
streaming=False, | ||
) | ||
|
||
|
||
|
@@ -369,11 +409,15 @@ def get_agent( | |
ElectrophysFeatureTool, Depends(get_electrophys_feature_tool) | ||
], | ||
traces_tool: Annotated[GetTracesTool, Depends(get_traces_tool)], | ||
me_model_tool: Annotated[GetMEModelTool, Depends(get_me_model_tool)], | ||
bluenaas_tool: Annotated[BlueNaaSTool, Depends(run_single_cell_sim_tool)], | ||
# bluenaas_sim_agent: Annotated[BluenaasSimAgent, Depends(get_bluenaas_sim_agent)], # Include BluenaasSimAgent | ||
|
||
settings: Annotated[Settings, Depends(get_settings)], | ||
) -> BaseAgent | BaseMultiAgent: | ||
"""Get the generative question answering service.""" | ||
if settings.agent.model == "multi": | ||
logger.info("Load multi-agent chat") | ||
if settings.agent.model == "multi-supervisor": | ||
logger.info("Load multi-agent (flat) chat") | ||
tools_list = [ | ||
("literature", [literature_tool]), | ||
( | ||
|
@@ -383,11 +427,32 @@ def get_agent( | |
morpho_tool, | ||
morphology_feature_tool, | ||
kg_morpho_feature_tool, | ||
literature_tool, | ||
electrophys_feature_tool, | ||
traces_tool, | ||
me_model_tool, | ||
bluenaas_tool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. havent tested this with flat supervisor in practice yet |
||
], | ||
), | ||
("traces", [br_resolver_tool, electrophys_feature_tool, traces_tool]), | ||
] | ||
return SupervisorMultiAgent(llm=llm, agents=tools_list) # type: ignore | ||
|
||
elif settings.agent.model == "multi-hierarchical": | ||
logger.info("Load multi-agent (hierarchical teams) chat") | ||
tools_list = [ | ||
br_resolver_tool, | ||
morpho_tool, | ||
morphology_feature_tool, | ||
kg_morpho_feature_tool, | ||
literature_tool, | ||
electrophys_feature_tool, | ||
traces_tool, | ||
me_model_tool, | ||
bluenaas_tool, | ||
] | ||
return HierarchicalTeamAgent(llm=llm, agents=tools_list) # type: ignore | ||
|
||
else: | ||
tools = [ | ||
literature_tool, | ||
|
@@ -397,6 +462,9 @@ def get_agent( | |
kg_morpho_feature_tool, | ||
electrophys_feature_tool, | ||
traces_tool, | ||
me_model_tool, | ||
bluenaas_tool, | ||
# bluenaas_sim_agent, | ||
] | ||
logger.info("Load simple agent") | ||
return SimpleAgent(llm=llm, tools=tools) # type: ignore | ||
|
@@ -420,20 +488,45 @@ def get_chat_agent( | |
ElectrophysFeatureTool, Depends(get_electrophys_feature_tool) | ||
], | ||
traces_tool: Annotated[GetTracesTool, Depends(get_traces_tool)], | ||
me_model_tool: Annotated[GetMEModelTool, Depends(get_me_model_tool)], | ||
bluenaas_tool: Annotated[BlueNaaSTool, Depends(run_single_cell_sim_tool)], | ||
# bluenaas_sim_agent: Annotated[BluenaasSimAgent, Depends(get_bluenaas_sim_agent)], | ||
settings: Annotated[Settings, Depends(get_settings)], | ||
|
||
) -> BaseAgent: | ||
"""Get the generative question answering service.""" | ||
logger.info("Load simple chat") | ||
tools = [ | ||
literature_tool, | ||
br_resolver_tool, | ||
morpho_tool, | ||
morphology_feature_tool, | ||
kg_morpho_feature_tool, | ||
electrophys_feature_tool, | ||
traces_tool, | ||
] | ||
return SimpleChatAgent(llm=llm, tools=tools, memory=memory) # type: ignore | ||
|
||
if settings.agent.model == "multi-hierarchical": | ||
logger.info("Load multi-agent (hierarchical teams) chat") | ||
tools = { | ||
"br_resolver_tool": br_resolver_tool, | ||
"morpho_tool": morpho_tool, | ||
"morphology_feature_tool": morphology_feature_tool, | ||
"kg_morpho_feature_tool": kg_morpho_feature_tool, | ||
"literature_tool": literature_tool, | ||
"electrophys_feature_tool": electrophys_feature_tool, | ||
"traces_tool": traces_tool, | ||
"me_model_tool": me_model_tool, | ||
"bluenaas_tool": bluenaas_tool, | ||
} | ||
return HierarchicalTeamAgent(llm=llm, tools=tools, memory=memory) # type: ignore | ||
elif settings.agent.model == "simple": | ||
logger.info("Load simple chat") | ||
tools = [ | ||
literature_tool, | ||
br_resolver_tool, | ||
morpho_tool, | ||
morphology_feature_tool, | ||
kg_morpho_feature_tool, | ||
electrophys_feature_tool, | ||
traces_tool, | ||
me_model_tool, | ||
bluenaas_tool, | ||
] | ||
return SimpleChatAgent(llm=llm, tools=tools, memory=memory) # type: ignore | ||
|
||
else: | ||
logger.error("Invalid agent model for chat agent.") | ||
|
||
async def get_update_kg_hierarchy( | ||
token: Annotated[str, Depends(get_kg_token)], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
streaming doesnt work yet