qver3nc1a commited on
Commit
d768e11
·
verified ·
1 Parent(s): 745bb16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -23,17 +23,11 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
23
 
24
 
25
  wikipedia = WikipediaAPIWrapper()
26
- @tool
27
  def wikipedia_search(query: str) -> str:
28
- '''
29
- Search Wikipedia and return a summary for a given query.
30
- Args:
31
- query: The search term or question to look up in Wikipedia.
32
- '''
33
  return wikipedia.run(query)
34
 
35
  # --- Basic Agent Definition ---
36
- # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
37
  class BasicAgent:
38
  def __init__(self):
39
  print('BasicAgent initialized.')
@@ -41,16 +35,36 @@ class BasicAgent:
41
  def __call__(self, question: str) -> str:
42
  print(f"Agent received question: {question[:50]}...")
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  agent = ToolCallingAgent(
45
- tools=[DuckDuckGoSearchTool(), wikipedia_search],
46
- model = LiteLLMModel(model_id="ollama/qwen2:7b", api_base='http://192.168.1.77:11434'),
 
 
 
47
  max_steps=15,
48
  verbosity_level=2,
49
  )
50
 
51
  return agent.run(question)
52
- return answer
53
-
54
  def run_and_submit_all( profile: gr.OAuthProfile | None):
55
  """
56
  Fetches all questions, runs the BasicAgent on them, submits all answers,
@@ -123,7 +137,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
123
  print("Agent did not produce any answers to submit.")
124
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
125
 
126
- # 4. Prepare Submission
127
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
128
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
129
  print(status_update)
@@ -178,11 +192,9 @@ with gr.Blocks() as demo:
178
  gr.Markdown(
179
  """
180
  **Instructions:**
181
-
182
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
183
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
184
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
185
-
186
  ---
187
  **Disclaimers:**
188
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
 
23
 
24
 
25
  wikipedia = WikipediaAPIWrapper()
 
26
  def wikipedia_search(query: str) -> str:
 
 
 
 
 
27
  return wikipedia.run(query)
28
 
29
  # --- Basic Agent Definition ---
30
+ # ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
31
  class BasicAgent:
32
  def __init__(self):
33
  print('BasicAgent initialized.')
 
35
  def __call__(self, question: str) -> str:
36
  print(f"Agent received question: {question[:50]}...")
37
 
38
+ # Define tools using the Tool class
39
+ web_search_tool = ToolNode(
40
+ tool=Tool(
41
+ name="WebSearch",
42
+ func=DuckDuckGoSearchRun().run,
43
+ description="Search the web for information."
44
+ )
45
+ )
46
+
47
+ open_webpage_tool = ToolNode(
48
+ tool=Tool(
49
+ name="OpenWebPage",
50
+ func=wikipedia_search,
51
+ description="Search Wikipedia for information."
52
+ )
53
+ )
54
+
55
+ # Instantiate the agent with the tools
56
  agent = ToolCallingAgent(
57
+ tools=[web_search_tool, open_webpage_tool],
58
+ model=LiteLLMModel(
59
+ model_id="ollama/qwen2:7b",
60
+ api_base='http://192.168.1.77:11434'
61
+ ),
62
  max_steps=15,
63
  verbosity_level=2,
64
  )
65
 
66
  return agent.run(question)
67
+
 
68
  def run_and_submit_all( profile: gr.OAuthProfile | None):
69
  """
70
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
137
  print("Agent did not produce any answers to submit.")
138
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
139
 
140
+ # 4. Prepare Submission
141
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
142
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
143
  print(status_update)
 
192
  gr.Markdown(
193
  """
194
  **Instructions:**
 
195
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
196
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
197
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
 
198
  ---
199
  **Disclaimers:**
200
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).