Spaces:
Sleeping
Sleeping
Update src/agent.py
Browse files- src/agent.py +24 -21
src/agent.py
CHANGED
|
@@ -1,30 +1,31 @@
|
|
| 1 |
from src.settings import Settings
|
| 2 |
from smolagents import LiteLLMModel, ToolCallingAgent
|
| 3 |
-
from tools import
|
| 4 |
from src.utils import InputTokenRateLimiter
|
| 5 |
import time
|
| 6 |
import random
|
|
|
|
| 7 |
|
| 8 |
settings = Settings()
|
| 9 |
class GaiaAgent():
|
| 10 |
def __init__(self):
|
| 11 |
-
|
| 12 |
self.model = LiteLLMModel(
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
self.token_rate_limiter = InputTokenRateLimiter()
|
| 29 |
self.expected_tokens_per_step = 10000
|
| 30 |
self.max_retries = 3
|
|
@@ -40,10 +41,13 @@ class GaiaAgent():
|
|
| 40 |
while True:
|
| 41 |
try:
|
| 42 |
for step in self.agent.run(input_text):
|
|
|
|
|
|
|
| 43 |
step_name = step.__class__.__name__
|
| 44 |
-
|
|
|
|
| 45 |
print(f"Step: {step_name} Output: {step.output}")
|
| 46 |
-
print(f"Step: {step_name}")
|
| 47 |
|
| 48 |
self.token_rate_limiter.maybe_wait(self.expected_tokens_per_step)
|
| 49 |
tokens_used = getattr(step, "token_usage", None)
|
|
@@ -71,5 +75,4 @@ class GaiaAgent():
|
|
| 71 |
|
| 72 |
print(f"\nFinished agent run.\n{'='*60}")
|
| 73 |
print(f"Final Answer: {final_answer}\n")
|
| 74 |
-
return final_answer
|
| 75 |
-
|
|
|
|
| 1 |
from src.settings import Settings
|
| 2 |
from smolagents import LiteLLMModel, ToolCallingAgent
|
| 3 |
+
from tools.FinalAnswerTool import FinalAnswerTool
|
| 4 |
from src.utils import InputTokenRateLimiter
|
| 5 |
import time
|
| 6 |
import random
|
| 7 |
+
from litellm import completion
|
| 8 |
|
| 9 |
settings = Settings()
|
| 10 |
class GaiaAgent():
|
| 11 |
def __init__(self):
|
|
|
|
| 12 |
self.model = LiteLLMModel(
|
| 13 |
+
model_id=settings.llm_model_id,
|
| 14 |
+
api_key=settings.llm_api_key
|
| 15 |
+
)
|
| 16 |
+
self.agent = ToolCallingAgent(
|
| 17 |
+
tools=[
|
| 18 |
+
FinalAnswerTool(),
|
| 19 |
+
# TODO: MP3 interpretation
|
| 20 |
+
],
|
| 21 |
+
max_steps=10,
|
| 22 |
+
planning_interval=5,
|
| 23 |
+
model=self.model
|
| 24 |
+
)
|
| 25 |
+
self.token_rate_limiter = InputTokenRateLimiter()
|
| 26 |
+
self.expected_tokens_per_step = 10000
|
| 27 |
+
self.max_retries = 3
|
| 28 |
+
self.base_delay = 5
|
| 29 |
self.token_rate_limiter = InputTokenRateLimiter()
|
| 30 |
self.expected_tokens_per_step = 10000
|
| 31 |
self.max_retries = 3
|
|
|
|
| 41 |
while True:
|
| 42 |
try:
|
| 43 |
for step in self.agent.run(input_text):
|
| 44 |
+
if isinstance(step, str):
|
| 45 |
+
continue
|
| 46 |
step_name = step.__class__.__name__
|
| 47 |
+
output = getattr(step, "output", None)
|
| 48 |
+
if output:
|
| 49 |
print(f"Step: {step_name} Output: {step.output}")
|
| 50 |
+
print(f"Step: {step_name} Output: {step.output}")
|
| 51 |
|
| 52 |
self.token_rate_limiter.maybe_wait(self.expected_tokens_per_step)
|
| 53 |
tokens_used = getattr(step, "token_usage", None)
|
|
|
|
| 75 |
|
| 76 |
print(f"\nFinished agent run.\n{'='*60}")
|
| 77 |
print(f"Final Answer: {final_answer}\n")
|
| 78 |
+
return final_answer
|
|
|