Spaces:
Sleeping
Sleeping
hammaad-swe
commited on
Commit
·
ff5ced3
1
Parent(s):
fd5668b
feat: gemini-model support - LiteLLM
Browse files- agent.py +10 -33
- requirements.txt +2 -1
agent.py
CHANGED
|
@@ -1,48 +1,25 @@
|
|
| 1 |
-
from smolagents import (
|
| 2 |
-
CodeAgent,
|
| 3 |
-
DuckDuckGoSearchTool,
|
| 4 |
-
FinalAnswerTool,
|
| 5 |
-
PythonInterpreterTool,
|
| 6 |
-
VisitWebpageTool,
|
| 7 |
-
WikipediaSearchTool,
|
| 8 |
-
tool,
|
| 9 |
-
)
|
| 10 |
-
from smolagents.models import Model
|
| 11 |
-
import google.generativeai as genai
|
| 12 |
-
from dotenv import load_dotenv
|
| 13 |
import os
|
| 14 |
|
| 15 |
-
load_dotenv
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def __init__(self):
|
| 19 |
-
self.api_key = os.getenv("GEMINI_API_KEY")
|
| 20 |
-
self.model_name = os.getenv("GEMINI_MODEL", "gemini-pro")
|
| 21 |
|
| 22 |
-
|
| 23 |
-
raise ValueError("GEMINI_API_KEY not found in .env")
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
def complete(self, prompt: str) -> str:
|
| 29 |
-
try:
|
| 30 |
-
response = self.model.generate_content(prompt)
|
| 31 |
-
return response.text.strip() if hasattr(response, "text") else str(response)
|
| 32 |
-
except Exception as e:
|
| 33 |
-
return f"Error generating content: {e}"
|
| 34 |
|
| 35 |
class GaiaAgent:
|
| 36 |
"""
|
| 37 |
An agent designed to answer questions using a combination of tools,
|
| 38 |
including search engines, web page access, a Python interpreter, and more.
|
| 39 |
"""
|
| 40 |
-
|
| 41 |
def __init__(self):
|
| 42 |
print("GaiaAgent initialized with tools.")
|
| 43 |
|
| 44 |
-
gemini_model = GeminiModel()
|
| 45 |
-
|
| 46 |
tools = [
|
| 47 |
DuckDuckGoSearchTool(),
|
| 48 |
VisitWebpageTool(),
|
|
@@ -51,10 +28,10 @@ class GaiaAgent:
|
|
| 51 |
FinalAnswerTool(),
|
| 52 |
]
|
| 53 |
|
| 54 |
-
self.agent = CodeAgent(model=
|
| 55 |
|
| 56 |
def __call__(self, task_id: str, question: str) -> str:
|
| 57 |
print(f"Agent received {task_id=}\n{question[:50]=}...")
|
| 58 |
answer = self.agent.run(question)
|
| 59 |
print(f"Agent returning answer: {answer}")
|
| 60 |
-
return answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from smolagents import (CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, LiteLLMModel,
|
| 5 |
+
PythonInterpreterTool, VisitWebpageTool, WikipediaSearchTool)
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
load_dotenv()
|
|
|
|
| 8 |
|
| 9 |
+
model = LiteLLMModel(
|
| 10 |
+
model_id=os.getenv("GEMINI_MODEL"),
|
| 11 |
+
api_key=os.getenv("GEMINI_API_KEY")
|
| 12 |
+
)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
class GaiaAgent:
|
| 16 |
"""
|
| 17 |
An agent designed to answer questions using a combination of tools,
|
| 18 |
including search engines, web page access, a Python interpreter, and more.
|
| 19 |
"""
|
|
|
|
| 20 |
def __init__(self):
|
| 21 |
print("GaiaAgent initialized with tools.")
|
| 22 |
|
|
|
|
|
|
|
| 23 |
tools = [
|
| 24 |
DuckDuckGoSearchTool(),
|
| 25 |
VisitWebpageTool(),
|
|
|
|
| 28 |
FinalAnswerTool(),
|
| 29 |
]
|
| 30 |
|
| 31 |
+
self.agent = CodeAgent(model=model, tools=tools)
|
| 32 |
|
| 33 |
def __call__(self, task_id: str, question: str) -> str:
|
| 34 |
print(f"Agent received {task_id=}\n{question[:50]=}...")
|
| 35 |
answer = self.agent.run(question)
|
| 36 |
print(f"Agent returning answer: {answer}")
|
| 37 |
+
return answer
|
requirements.txt
CHANGED
|
@@ -5,4 +5,5 @@ python-dotenv
|
|
| 5 |
pandas
|
| 6 |
smolagents
|
| 7 |
wikipedia-api
|
| 8 |
-
google-generativeai
|
|
|
|
|
|
| 5 |
pandas
|
| 6 |
smolagents
|
| 7 |
wikipedia-api
|
| 8 |
+
google-generativeai
|
| 9 |
+
smolagents[litellm]
|