Spaces:
Sleeping
Sleeping
Updated code for smolagent
Browse files
app.py
CHANGED
|
@@ -3,9 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from
|
| 7 |
-
from llama_index.core.agent.workflow import FunctionAgent
|
| 8 |
-
from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec
|
| 9 |
|
| 10 |
# (Keep Constants as is)
|
| 11 |
# --- Constants ---
|
|
@@ -13,24 +11,29 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 13 |
|
| 14 |
# --- Basic Agent Definition ---
|
| 15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 16 |
-
|
|
|
|
| 17 |
class BasicAgent:
|
| 18 |
def __init__(self):
|
| 19 |
print("Srj's Agent initialized.")
|
| 20 |
-
self.
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
#self.model = InferenceClientModel(model= "Qwen/Qwen2.5-7B-Instruct",)
|
| 35 |
#self.agent = CodeAgent(tools=[WebSearchTool()], model=self.model, stream_outputs=False, add_base_tools=False)
|
| 36 |
|
|
@@ -68,7 +71,7 @@ class BasicAgent:
|
|
| 68 |
|
| 69 |
Respond with ONLY the final answer."""
|
| 70 |
|
| 71 |
-
output =
|
| 72 |
return str(output).strip()
|
| 73 |
|
| 74 |
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import CodeAgent, WebSearchTool, InferenceClientModel, FinalAnswerTool, tool
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
|
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
+
web_search = WebSearchTool()
|
| 15 |
+
final_answer = FinalAnswerTool()
|
| 16 |
class BasicAgent:
|
| 17 |
def __init__(self):
|
| 18 |
print("Srj's Agent initialized.")
|
| 19 |
+
self.model = InferenceClientModel(max_tokens=2096,
|
| 20 |
+
temperature=0.5,
|
| 21 |
+
model_id='Qwen/Qwen2.5-Coder-7B-Instruct',
|
| 22 |
+
provider="nscale"
|
| 23 |
+
|
| 24 |
+
)
|
| 25 |
+
self.agent = CodeAgent(
|
| 26 |
+
model=self.model,
|
| 27 |
+
tools=[final_answer, web_search], # add your tools here (don't remove final_answer)
|
| 28 |
+
max_steps=6,
|
| 29 |
+
verbosity_level=1,
|
| 30 |
+
grammar=None,
|
| 31 |
+
planning_interval=None,
|
| 32 |
+
name=None,
|
| 33 |
+
description=None,
|
| 34 |
+
prompt_templates=prompt_templates
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
#self.model = InferenceClientModel(model= "Qwen/Qwen2.5-7B-Instruct",)
|
| 38 |
#self.agent = CodeAgent(tools=[WebSearchTool()], model=self.model, stream_outputs=False, add_base_tools=False)
|
| 39 |
|
|
|
|
| 71 |
|
| 72 |
Respond with ONLY the final answer."""
|
| 73 |
|
| 74 |
+
output = self.agent.run(prompt))
|
| 75 |
return str(output).strip()
|
| 76 |
|
| 77 |
|