Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -17,7 +17,7 @@ load_dotenv()
|
|
| 17 |
|
| 18 |
# Initialize the model with OpenRouter Gemini
|
| 19 |
model = LiteLLMModel(
|
| 20 |
-
model_id=os.getenv(
|
| 21 |
api_key=os.getenv("GEMINI_API_KEY"), # your OpenRouter API key
|
| 22 |
base_url="https://openrouter.ai/api/v1" # required for OpenRouter
|
| 23 |
)
|
|
@@ -90,15 +90,19 @@ class GaiaAgent:
|
|
| 90 |
model=model,
|
| 91 |
tools=tools,
|
| 92 |
add_base_tools=True,
|
| 93 |
-
# show reasoning in logs
|
| 94 |
additional_authorized_imports=["pandas", "numpy", "csv", "subprocess"],
|
| 95 |
)
|
| 96 |
|
| 97 |
def __call__(self, task_id: str, question: str) -> str:
|
| 98 |
print(f"Agent received task_id='{task_id}' | question='{question[:50]}...'")
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
if not answer:
|
| 101 |
answer = "⚠️ Sorry, I could not generate a valid response."
|
|
|
|
| 102 |
print(f"Agent returning answer: {answer}")
|
| 103 |
return answer
|
| 104 |
|
|
|
|
| 17 |
|
| 18 |
# Initialize the model with OpenRouter Gemini
|
| 19 |
model = LiteLLMModel(
|
| 20 |
+
model_id=f"openrouter/{os.getenv('GEMINI_MODEL', 'google/gemini-2.5-flash-preview-09-2025')}",
|
| 21 |
api_key=os.getenv("GEMINI_API_KEY"), # your OpenRouter API key
|
| 22 |
base_url="https://openrouter.ai/api/v1" # required for OpenRouter
|
| 23 |
)
|
|
|
|
| 90 |
model=model,
|
| 91 |
tools=tools,
|
| 92 |
add_base_tools=True,
|
|
|
|
| 93 |
additional_authorized_imports=["pandas", "numpy", "csv", "subprocess"],
|
| 94 |
)
|
| 95 |
|
| 96 |
def __call__(self, task_id: str, question: str) -> str:
|
| 97 |
print(f"Agent received task_id='{task_id}' | question='{question[:50]}...'")
|
| 98 |
+
try:
|
| 99 |
+
answer = self.agent.run(question)
|
| 100 |
+
except Exception as e:
|
| 101 |
+
answer = f"⚠️ Agent failed: {e}"
|
| 102 |
+
|
| 103 |
if not answer:
|
| 104 |
answer = "⚠️ Sorry, I could not generate a valid response."
|
| 105 |
+
|
| 106 |
print(f"Agent returning answer: {answer}")
|
| 107 |
return answer
|
| 108 |
|