cyberosa commited on
Commit
ca302c3
·
1 Parent(s): 623a0f6

trying new model and new search tool

Browse files
Files changed (3) hide show
  1. agents.py +18 -5
  2. app.py +1 -1
  3. tools.py +77 -0
agents.py CHANGED
@@ -7,15 +7,18 @@ from smolagents import (
7
  WikipediaSearchTool,
8
  DuckDuckGoSearchTool,
9
  SpeechToTextTool,
 
10
  )
11
  import os
 
12
  from typing import Optional
 
13
 
14
 
15
  gemini_api_key = os.environ.get("GEMINI_API_KEY", None)
16
  open_router_api_key = os.environ.get("OPENROUTER_API_KEY", None)
17
  gemini_model = LiteLLMModel(
18
- model_id="gemini/gemini-2.0-flash-lite",
19
  api_key=gemini_api_key,
20
  )
21
  # alternative model
@@ -29,6 +32,9 @@ model = OpenAIServerModel(
29
  search_tool = DuckDuckGoSearchTool()
30
  speech_tool = SpeechToTextTool()
31
  wiki_tool = WikipediaSearchTool()
 
 
 
32
 
33
 
34
  class SkynetMultiAgent:
@@ -58,7 +64,9 @@ class SkynetMultiAgent:
58
  print(f"Processing question with file: {file_path}")
59
  else:
60
  eval_question = question
61
- fixed_answer = self.agent.run(eval_question, max_steps=10)
 
 
62
  print(f"Agent returning fixed answer: {fixed_answer}")
63
  return fixed_answer
64
 
@@ -66,11 +74,15 @@ class SkynetMultiAgent:
66
  class SkynetSingleAgent:
67
  def __init__(self):
68
  self.agent = CodeAgent(
69
- tools=[speech_tool, wiki_tool],
 
 
 
 
 
 
70
  model=gemini_model,
71
  name="skynet_agent",
72
- add_base_tools=True,
73
- planning_interval=5,
74
  max_steps=5,
75
  description="Agent to answer questions and run code",
76
  additional_authorized_imports=["time", "numpy", "pandas"],
@@ -84,6 +96,7 @@ class SkynetSingleAgent:
84
  print(f"Processing question with file: {file_path}")
85
  else:
86
  eval_question = question
 
87
  fixed_answer = self.agent.run(eval_question)
88
  print(f"Agent returning fixed answer: {fixed_answer}")
89
  return fixed_answer
 
7
  WikipediaSearchTool,
8
  DuckDuckGoSearchTool,
9
  SpeechToTextTool,
10
+ PythonInterpreterTool,
11
  )
12
  import os
13
+ import time
14
  from typing import Optional
15
+ from tools import MySearchTool
16
 
17
 
18
  gemini_api_key = os.environ.get("GEMINI_API_KEY", None)
19
  open_router_api_key = os.environ.get("OPENROUTER_API_KEY", None)
20
  gemini_model = LiteLLMModel(
21
+ model_id="gemini/gemini-2.0-flash",
22
  api_key=gemini_api_key,
23
  )
24
  # alternative model
 
32
  search_tool = DuckDuckGoSearchTool()
33
  speech_tool = SpeechToTextTool()
34
  wiki_tool = WikipediaSearchTool()
35
+ python_tool = PythonInterpreterTool()
36
+ visit_webpage_tool = VisitWebpageTool()
37
+ my_search_tool = MySearchTool()
38
 
39
 
40
  class SkynetMultiAgent:
 
64
  print(f"Processing question with file: {file_path}")
65
  else:
66
  eval_question = question
67
+
68
+ time.sleep(2) # 2-second delay
69
+ fixed_answer = self.agent.run(eval_question, max_steps=5)
70
  print(f"Agent returning fixed answer: {fixed_answer}")
71
  return fixed_answer
72
 
 
74
  class SkynetSingleAgent:
75
  def __init__(self):
76
  self.agent = CodeAgent(
77
+ tools=[
78
+ speech_tool,
79
+ wiki_tool,
80
+ my_search_tool,
81
+ visit_webpage_tool,
82
+ python_tool,
83
+ ],
84
  model=gemini_model,
85
  name="skynet_agent",
 
 
86
  max_steps=5,
87
  description="Agent to answer questions and run code",
88
  additional_authorized_imports=["time", "numpy", "pandas"],
 
96
  print(f"Processing question with file: {file_path}")
97
  else:
98
  eval_question = question
99
+ time.sleep(2) # 2-second delay
100
  fixed_answer = self.agent.run(eval_question)
101
  print(f"Agent returning fixed answer: {fixed_answer}")
102
  return fixed_answer
app.py CHANGED
@@ -31,7 +31,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
31
 
32
  # 1. Instantiate Agent ( modify this part to create your agent)
33
  try:
34
- multi_agent = SkynetMultiAgent()
35
  agent = SkynetSingleAgent()
36
  print(f"Agent instantiated successfully: {agent}")
37
  except Exception as e:
 
31
 
32
  # 1. Instantiate Agent ( modify this part to create your agent)
33
  try:
34
+ # multi_agent = SkynetMultiAgent()
35
  agent = SkynetSingleAgent()
36
  print(f"Agent instantiated successfully: {agent}")
37
  except Exception as e:
tools.py CHANGED
@@ -1,6 +1,11 @@
1
  from smolagents import Tool
2
  from langchain_community.retrievers import BM25Retriever
3
  from langchain.docstore.document import Document
 
 
 
 
 
4
 
5
 
6
  class DownloadFilesTool(Tool):
@@ -58,3 +63,75 @@ class PythonCodeAnalyzerTool(Tool):
58
  # Placeholder for actual code analysis logic
59
  # In a real implementation, you would use a library or service to analyze the code
60
  return f"Analyzed code:\n{code}\n\nNo issues found."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from smolagents import Tool
2
  from langchain_community.retrievers import BM25Retriever
3
  from langchain.docstore.document import Document
4
+ import requests
5
+ import os
6
+ import time
7
+ from typing import List, Dict, Any, Optional
8
+ from .utils import get_env_var, logger
9
 
10
 
11
  class DownloadFilesTool(Tool):
 
63
  # Placeholder for actual code analysis logic
64
  # In a real implementation, you would use a library or service to analyze the code
65
  return f"Analyzed code:\n{code}\n\nNo issues found."
66
+
67
+
68
+ class MySearchTool(Tool):
69
+ name = "Search tool to avoid rate limit"
70
+ description = "It receives a question and returns a list of search results from various sources. It uses DuckDuckGo as the primary source"
71
+ inputs = {
72
+ "query": {
73
+ "type": "string",
74
+ "description": "The question or topic to search in internet.",
75
+ },
76
+ }
77
+ output_type = "string"
78
+
79
+ def __init__(self):
80
+ # Primary: Free alternatives
81
+ self.duckduckgo_enabled = True
82
+
83
+ def forward(self, query: str, max_results: int = 5) -> List[Dict[str, Any]]:
84
+ """
85
+ Free search using DuckDuckGo Instant Answer API
86
+
87
+ Args:
88
+ query: Search query
89
+ max_results: Maximum number of results
90
+
91
+ Returns:
92
+ List of search results
93
+ """
94
+ try:
95
+ # DuckDuckGo Instant Answer API (free)
96
+ url = "https://api.duckduckgo.com/"
97
+ params = {
98
+ "q": query,
99
+ "format": "json",
100
+ "no_html": "1",
101
+ "skip_disambig": "1",
102
+ }
103
+
104
+ response = requests.get(url, params=params, timeout=10)
105
+ response.raise_for_status()
106
+ time.sleep(2) # 2-second delay
107
+ data = response.json()
108
+ results = []
109
+
110
+ # Process abstract
111
+ if data.get("Abstract"):
112
+ results.append(
113
+ {
114
+ "title": data.get("Heading", "DuckDuckGo Result"),
115
+ "url": data.get("AbstractURL", ""),
116
+ "content": data.get("Abstract", ""),
117
+ "source": "DuckDuckGo",
118
+ }
119
+ )
120
+
121
+ # Process related topics
122
+ for topic in data.get("RelatedTopics", [])[: max_results - len(results)]:
123
+ if isinstance(topic, dict) and "Text" in topic:
124
+ results.append(
125
+ {
126
+ "title": topic.get("Text", "")[:100],
127
+ "url": topic.get("FirstURL", ""),
128
+ "content": topic.get("Text", ""),
129
+ "source": "DuckDuckGo",
130
+ }
131
+ )
132
+
133
+ return results[:max_results]
134
+
135
+ except Exception as e:
136
+ logger.error(f"DuckDuckGo search failed: {str(e)}")
137
+ return []