asthara commited on
Commit
76c1568
·
1 Parent(s): 69de5cf

restructuring

Browse files
.gitignore CHANGED
@@ -9,3 +9,4 @@ wheels/
9
  # Virtual environments
10
  .venv
11
  .gradio/
 
 
9
  # Virtual environments
10
  .venv
11
  .gradio/
12
+ tmp_meta.yml
agents/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ """
2
+ Agents for agent ontology.
3
+ """
agents/query_ontology_db.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import CodeAgent, LiteLLMModel
2
+ from tools.fetch_ontology_tools import search_edam_ontology_by_search_term, get_edam_description_from_ontology_format_class
3
+
4
+ model = LiteLLMModel(
5
+ model_id="ollama/devstral:latest",
6
+ #model_id="ollama/qwen3:0.6b",
7
+ api_base="http://localhost:11434",
8
+ temperature=0.0,
9
+ max_tokens=5000,
10
+ )
11
+
12
+ tool_list = [search_edam_ontology_by_search_term, get_edam_description_from_ontology_format_class]
13
+
14
+ agent = CodeAgent(
15
+ tools=tool_list,
16
+ model=model,
17
+ additional_authorized_imports=["inspect", "json"]
18
+ )
main.py CHANGED
@@ -1,13 +1,10 @@
1
- from smolagents import CodeAgent, LiteLLMModel
2
- from smolagents.tools import ToolCollection
3
  import gradio as gr
4
- import requests
5
  import modal
6
  import sys
7
  import subprocess
8
  import time
9
- from .tools.meta_yml_tools import fetch_meta_yml,get_meta_yml_file, extract_tools_from_meta_json, extract_information_from_meta_json, extract_module_name_description,get_biotools_response
10
-
11
  # Define the custom image
12
  ollama_image = (
13
  modal.Image.debian_slim()
@@ -33,41 +30,6 @@ ollama_image = (
33
 
34
  # Initialize the Modal app with the custom image
35
  app = modal.App("agent-ontology", image=ollama_image)
36
-
37
- def chat_with_agent(message, history):
38
- """ Function to handle chat messages and interact with the agent.
39
- This function creates a new MCP connection for each request, allowing the agent to use tools from the MCP server.
40
- """
41
- try:
42
- with ToolCollection.from_mcp(
43
- {"url": "https://notredameslab-nf-ontology.hf.space/gradio_api/mcp/sse", "transport": "sse"},
44
- trust_remote_code=True # Acknowledge that we trust this remote MCP server
45
- ) as tool_collection:
46
-
47
-
48
- model = LiteLLMModel(
49
- model_id="ollama/devstral:latest",
50
- api_base="http://localhost:11434",
51
- )
52
-
53
- agent = CodeAgent(
54
- tools=tool_collection.tools,
55
- model=model,
56
- additional_authorized_imports=["inspect", "json"]
57
- )
58
-
59
- additional_instructions = """
60
- ADDITIONAL IMPORTANT INSTRUCTIONS:
61
- use the tool "final_answer" in the code block to provide the answer to the user. Prints are only for debugging purposes. So, to give your results concatenate everything you want to print in a single "final_answer" call as such : final_answer(f"your answer here").
62
- """
63
-
64
- agent.system_prompt += additional_instructions
65
-
66
- result = agent.run(message)
67
- return str(result)
68
-
69
- except Exception as e:
70
- return f"❌ Error: {e}\nType: {type(e).__name__}"
71
 
72
  def run_multi_agent(module_name):
73
  meta_yml = get_meta_yml_file(module_name=module_name)
@@ -83,7 +45,17 @@ def run_multi_agent(module_name):
83
  """
84
  tool_name = "fastqc" # this would be the answer of the first agent
85
  meta_info = extract_information_from_meta_json(meta_file=meta_yml, tool_name=tool_name)
86
- return(meta_info)
 
 
 
 
 
 
 
 
 
 
87
 
88
  def run_interface():
89
  """ Function to run the agent with a Gradio interface.
 
 
 
1
  import gradio as gr
 
2
  import modal
3
  import sys
4
  import subprocess
5
  import time
6
+ from tools.meta_yml_tools import get_meta_yml_file, extract_tools_from_meta_json, extract_information_from_meta_json, extract_module_name_description, get_biotools_response
7
+ from agents.query_ontology_db import agent
8
  # Define the custom image
9
  ollama_image = (
10
  modal.Image.debian_slim()
 
30
 
31
  # Initialize the Modal app with the custom image
32
  app = modal.App("agent-ontology", image=ollama_image)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  def run_multi_agent(module_name):
35
  meta_yml = get_meta_yml_file(module_name=module_name)
 
45
  """
46
  tool_name = "fastqc" # this would be the answer of the first agent
47
  meta_info = extract_information_from_meta_json(meta_file=meta_yml, tool_name=tool_name)
48
+ for input_tool in module_info["inputs"]:
49
+ for key, value in input_tool.items():
50
+ if key == "file":
51
+ result = agent.run(f"you are presentend with a file format for the type {key}, which is a {value['type']} and is described by the following description: '{value['description']}', search for the single best match out of possible matches in the edam ontology (formated as format_XXXX), and return the answer (a single ontology class) in a final_answer call such as final_answer(f'format_XXXX')")
52
+ print(result)
53
+
54
+ # TODO: placeholder
55
+ # This is returning the original meta.yml, but it should return the modified one with the ontologies added
56
+ with open("tmp_meta.yml", "w") as fh:
57
+ fh.write(meta_info)
58
+ return meta_info, "tmp_meta.yml" # TODO: placeholder
59
 
60
  def run_interface():
61
  """ Function to run the agent with a Gradio interface.
pyproject.toml CHANGED
@@ -14,4 +14,6 @@ dependencies = [
14
  "requests",
15
  "smolagents[litellm,mcp]>=1.17.0",
16
  "textblob>=0.19.0",
 
 
17
  ]
 
14
  "requests",
15
  "smolagents[litellm,mcp]>=1.17.0",
16
  "textblob>=0.19.0",
17
+ "aiohttp>=3.8.0",
18
+ "modal>=0.57.0",
19
  ]
tools/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ """
2
+ Local tools for agent ontology.
3
+ """
fetch_ontology_from_input.py → tools/fetch_ontology_tools.py RENAMED
@@ -1,48 +1,5 @@
1
- from smolagents import CodeAgent, LiteLLMModel, tool
2
- from smolagents.tools import ToolCollection
3
- import gradio as gr
4
- import requests
5
- import yaml
6
- from owlready2 import get_ontology, default_world
7
- import logging
8
-
9
- def get_fastqc_meta_yaml():
10
- """
11
- Fetches the content of the FastQC meta.yml file from nf-core modules repository.
12
-
13
- Returns:
14
- str: The content of the YAML file as a string
15
- """
16
- # Use the raw GitHub URL to get the file content directly
17
- url = "https://raw.githubusercontent.com/nf-core/modules/master/modules/nf-core/fastqc/meta.yml"
18
-
19
- try:
20
- response = requests.get(url)
21
- response.raise_for_status() # Raises an HTTPError for bad responses
22
- return response.text
23
- except requests.exceptions.RequestException as e:
24
- print(f"Error fetching YAML file: {e}")
25
- return None
26
-
27
- def get_fastqc_input_yaml():
28
- """
29
- Fetches the content of the FastQC input.yml file from nf-core modules repository.
30
-
31
- Returns:
32
- str: The content of the YAML file as a dictionary
33
- """
34
-
35
- yaml_content = get_fastqc_meta_yaml()
36
- if yaml_content:
37
- try:
38
- # Parse the YAML content
39
- return yaml.safe_load(yaml_content)["input"]
40
- except yaml.YAMLError as e:
41
- print(f"Error parsing YAML: {e}")
42
- return None
43
- else:
44
- print("Failed to fetch the YAML file, returning None.")
45
- return None
46
 
47
 
48
  def load_edam_ontology():
@@ -151,29 +108,3 @@ def get_edam_description_from_ontology_format_class(term_id: str) -> str:
151
 
152
  except AttributeError:
153
  return f"Term {term_id} not found in EDAM ontology"
154
-
155
- # Example usage:
156
- if __name__ == "__main__":
157
- tool_list = [search_edam_ontology_by_search_term, get_edam_description_from_ontology_format_class]
158
-
159
- model = LiteLLMModel(
160
- model_id="ollama/devstral:latest",
161
- #model_id="ollama/qwen3:0.6b",
162
- api_base="http://localhost:11434",
163
- temperature=0.0,
164
- max_tokens=5000,
165
- )
166
-
167
- agent = CodeAgent(
168
- tools=tool_list,
169
- model=model,
170
- additional_authorized_imports=["inspect", "json"]
171
- )
172
-
173
- print(agent.tools)
174
- input_yaml = get_fastqc_input_yaml()
175
- for input_tool in input_yaml[0]:
176
- for key, value in input_tool.items():
177
- if key != "meta":
178
- result = agent.run(f"you are presentend with a file format for the type {key}, which is a {value['type']} and is described by the following description: '{value['description']}', search for the single best match out of possible matches in the edam ontology (formated as format_XXXX), and return the answer (a single ontology class) in a final_answer call such as final_answer(f'format_XXXX')")
179
- print(result)
 
1
+ from smolagents import tool
2
+ from owlready2 import get_ontology
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
 
5
  def load_edam_ontology():
 
108
 
109
  except AttributeError:
110
  return f"Term {term_id} not found in EDAM ontology"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tools/meta_yml_tools.py CHANGED
@@ -2,22 +2,6 @@ import requests
2
  import json
3
  import yaml
4
 
5
- # TODO: placeholder function
6
- def fetch_meta_yml(module_name):
7
- # Adjust the URL or path to your actual source of nf-core modules
8
- base_url = f"https://raw.githubusercontent.com/nf-core/modules/refs/heads/master/modules/nf-core/{module_name}/meta.yml"
9
- try:
10
- response = requests.get(base_url)
11
- response.raise_for_status()
12
- content = response.text
13
-
14
- # Save for download
15
- with open("meta.yml", "w") as f:
16
- f.write(content)
17
-
18
- return content, "meta.yml"
19
- except Exception as e:
20
- return f"Error: Could not retrieve meta.yml for module '{module_name}'\n{e}", None
21
 
22
  def get_meta_yml_file(module_name: str) -> dict:
23
  """
 
2
  import json
3
  import yaml
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  def get_meta_yml_file(module_name: str) -> dict:
7
  """
uv.lock CHANGED
The diff for this file is too large to render. See raw diff