simonesarti commited on
Commit
3b24931
·
1 Parent(s): 81917a3

structured agent

Browse files
Files changed (1) hide show
  1. app.py +27 -3
app.py CHANGED
@@ -3,6 +3,9 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -12,12 +15,33 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
14
  def __init__(self):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  print("BasicAgent initialized.")
16
  def __call__(self, question: str) -> str:
17
  print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import InferenceClientModel, CodeAgent, Tool, DuckDuckGoSearchTool, VisitWebpageTool, PythonInterpreterTool
7
+
8
+
9
 
10
  # (Keep Constants as is)
11
  # --- Constants ---
 
15
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
16
  class BasicAgent:
17
  def __init__(self):
18
+
19
+ tools = [
20
+ VisitWebpageTool(),
21
+ DuckDuckGoSearchTool(),
22
+ # PythonInterpreterTool(),
23
+ # PythonInterpreterTool(),
24
+ ]
25
+
26
+ model = InferenceClientModel(
27
+ model="Qwen/Qwen2.5-Coder-32B-Instruct",
28
+ )
29
+
30
+ self.agent = CodeAgent(
31
+ model=model,
32
+ tools=tools,
33
+ additional_authorizesd_imports=["requests", "json", "re", "math", "numpy", "pandas", "datetime", "time", "random", "os", "sys"],
34
+ planning_interval=4,
35
+ max_steps=15,
36
+ verbosity_level=2,
37
+ )
38
+
39
  print("BasicAgent initialized.")
40
  def __call__(self, question: str) -> str:
41
  print(f"Agent received question (first 50 chars): {question[:50]}...")
42
+ response = self.agent.run(question)
43
+ print(f"Agent returning response: {response}")
44
+ return response
45
 
46
  def run_and_submit_all( profile: gr.OAuthProfile | None):
47
  """