George Sergia commited on
Commit
af10fd2
·
1 Parent(s): 81917a3

Initial implementation

Browse files
Files changed (4) hide show
  1. agent.py +27 -0
  2. app.py +2 -8
  3. prompts.yaml +2 -0
  4. requirements.txt +3 -1
agent.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import DuckDuckGoSearchTool, CodeAgent, HfApiModel
2
+ import yaml
3
+
4
+ class BasicAgent:
5
+ def __init__(self):
6
+ print("BasicAgent initialized.")
7
+
8
+ def __call__(self, question: str) -> str:
9
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
10
+
11
+ with open("prompts.yaml", 'r') as stream:
12
+ prompt_templates = yaml.safe_load(stream)
13
+
14
+ model = HfApiModel()
15
+ search_tool = DuckDuckGoSearchTool()
16
+
17
+ agent = CodeAgent(
18
+ tools=[search_tool],
19
+ model=model,
20
+ add_base_tools = True,
21
+ verbose=True,
22
+ prompt_templates=prompt_templates
23
+ )
24
+
25
+ fixed_answer = agent.run(question)
26
+ print(f"Agent returning fixed answer: {fixed_answer}")
27
+ return fixed_answer
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -10,14 +11,6 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Basic Agent Definition ---
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
  """
@@ -91,6 +84,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
91
  print("Agent did not produce any answers to submit.")
92
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
93
 
 
94
  # 4. Prepare Submission
95
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
96
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from agent import BasicAgent
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
 
11
 
12
  # --- Basic Agent Definition ---
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
 
 
 
 
 
 
14
 
15
  def run_and_submit_all( profile: gr.OAuthProfile | None):
16
  """
 
84
  print("Agent did not produce any answers to submit.")
85
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
86
 
87
+ return
88
  # 4. Prepare Submission
89
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
90
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
prompts.yaml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ "system_prompt": |-
2
+ You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  gradio
2
- requests
 
 
 
1
  gradio
2
+ requests
3
+ smolagents
4
+ yaml