Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,14 +17,14 @@ class BasicAgent:
|
|
| 17 |
print("BasicAgent initialized.")
|
| 18 |
groq_key = os.getenv("GROQ_API_KEY")
|
| 19 |
model = OpenAIServerModel(
|
| 20 |
-
model_id="
|
| 21 |
api_base="https://api.groq.com/openai/v1",
|
| 22 |
api_key=groq_key,
|
| 23 |
)
|
| 24 |
self.agent = CodeAgent(
|
| 25 |
tools=[DuckDuckGoSearchTool()],
|
| 26 |
model=model,
|
| 27 |
-
max_steps=
|
| 28 |
additional_authorized_imports=["requests", "pandas", "numpy", "time", "bs4", "re"]
|
| 29 |
)
|
| 30 |
|
|
@@ -43,13 +43,16 @@ class BasicAgent:
|
|
| 43 |
"""
|
| 44 |
|
| 45 |
try:
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
except BaseException as e:
|
| 54 |
import traceback
|
| 55 |
print(f"Agent failed to answer: {e}")
|
|
|
|
| 17 |
print("BasicAgent initialized.")
|
| 18 |
groq_key = os.getenv("GROQ_API_KEY")
|
| 19 |
model = OpenAIServerModel(
|
| 20 |
+
model_id="llama-3.1-8b-instant",
|
| 21 |
api_base="https://api.groq.com/openai/v1",
|
| 22 |
api_key=groq_key,
|
| 23 |
)
|
| 24 |
self.agent = CodeAgent(
|
| 25 |
tools=[DuckDuckGoSearchTool()],
|
| 26 |
model=model,
|
| 27 |
+
max_steps=8,
|
| 28 |
additional_authorized_imports=["requests", "pandas", "numpy", "time", "bs4", "re"]
|
| 29 |
)
|
| 30 |
|
|
|
|
| 43 |
"""
|
| 44 |
|
| 45 |
try:
|
| 46 |
+
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
|
| 47 |
+
future = executor.submit(self.agent.run, prompt)
|
| 48 |
+
try:
|
| 49 |
+
result = future.result(timeout=120)
|
| 50 |
+
executor.shutdown(wait=False)
|
| 51 |
+
return str(result).strip()
|
| 52 |
+
except concurrent.futures.TimeoutError:
|
| 53 |
+
print("Agent timed out after 120s, moving on")
|
| 54 |
+
executor.shutdown(wait=False, cancel_futures=True)
|
| 55 |
+
return "ERROR: Timeout"
|
| 56 |
except BaseException as e:
|
| 57 |
import traceback
|
| 58 |
print(f"Agent failed to answer: {e}")
|