Gary Simmons commited on
Commit
2eea0c9
·
1 Parent(s): ed7d4b5

refactor BasicAgent initialization to include AgentName and update requirements.txt to include huggingface-hub

Browse files
Files changed (2) hide show
  1. app.py +23 -8
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,15 +1,14 @@
1
  import os
2
  import gradio as gr
3
  import requests
4
- import inspect
5
  import pandas as pd
6
  from smolagents import (
7
  CodeAgent,
8
  DuckDuckGoSearchTool,
9
- InferenceClientModel,
10
  VisitWebpageTool,
11
  PythonInterpreterTool,
12
  WikipediaSearchTool,
 
13
  )
14
 
15
 
@@ -17,10 +16,18 @@ from smolagents import (
17
  # --- Constants ---
18
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
19
 
 
20
  # --- Basic Agent Definition ---
21
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
 
 
 
 
22
  class BasicAgent:
23
- def __init__(self):
 
24
  self.code_agent = CodeAgent(
25
  tools=[
26
  DuckDuckGoSearchTool(),
@@ -28,8 +35,10 @@ class BasicAgent:
28
  PythonInterpreterTool(),
29
  WikipediaSearchTool(),
30
  ],
31
- model=InferenceClientModel("Qwen/Qwen2.5-Coder-32b-instruct"),
32
- max_steps=20,
 
 
33
  )
34
  print("BasicAgent initialized.")
35
  def __call__(self, question: str) -> str:
@@ -64,7 +73,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
64
 
65
  # 1. Instantiate Agent ( modify this part to create your agent)
66
  try:
67
- agent = BasicAgent()
 
68
  except Exception as e:
69
  print(f"Error instantiating agent: {e}")
70
  return f"Error initializing agent: {e}", None
@@ -115,8 +125,13 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
115
  print("Agent did not produce any answers to submit.")
116
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
117
 
118
- # 4. Prepare Submission
119
- submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
 
 
 
 
 
120
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
121
  print(status_update)
122
 
 
1
  import os
2
  import gradio as gr
3
  import requests
 
4
  import pandas as pd
5
  from smolagents import (
6
  CodeAgent,
7
  DuckDuckGoSearchTool,
 
8
  VisitWebpageTool,
9
  PythonInterpreterTool,
10
  WikipediaSearchTool,
11
+ LiteLLMModel
12
  )
13
 
14
 
 
16
  # --- Constants ---
17
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
18
 
19
+
20
  # --- Basic Agent Definition ---
21
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
22
+
23
+ model = LiteLLMModel(
24
+ model_id="gemini/gemini-2.5-flash",
25
+ temperature=0.2
26
+ )
27
+
28
  class BasicAgent:
29
+ def __init__(self, name: str = "GGSAgent"):
30
+ self.name = name
31
  self.code_agent = CodeAgent(
32
  tools=[
33
  DuckDuckGoSearchTool(),
 
35
  PythonInterpreterTool(),
36
  WikipediaSearchTool(),
37
  ],
38
+ model=model,
39
+ max_steps=15,
40
+ verbosity_level=1,
41
+ additional_authorized_imports=["json", "math"]
42
  )
43
  print("BasicAgent initialized.")
44
  def __call__(self, question: str) -> str:
 
73
 
74
  # 1. Instantiate Agent ( modify this part to create your agent)
75
  try:
76
+ agent_name = os.getenv("AGENT_NAME", "GGSAgent")
77
+ agent = BasicAgent(name=agent_name)
78
  except Exception as e:
79
  print(f"Error instantiating agent: {e}")
80
  return f"Error initializing agent: {e}", None
 
125
  print("Agent did not produce any answers to submit.")
126
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
127
 
128
+ # 4. Prepare Submission
129
+ submission_data = {
130
+ "username": username.strip(),
131
+ "agent_code": agent_code,
132
+ "agent_name": getattr(agent, "name", "BasicAgent"),
133
+ "answers": answers_payload,
134
+ }
135
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
136
  print(status_update)
137
 
requirements.txt CHANGED
@@ -4,3 +4,4 @@ pandas==1.5.3
4
  requests>=2.28.0
5
  smolagents==1.22.0
6
  ddgs==9.6.1
 
 
4
  requests>=2.28.0
5
  smolagents==1.22.0
6
  ddgs==9.6.1
7
+ huggingface-hub>=0.15.1