at1300 commited on
Commit
ac8e929
·
verified ·
1 Parent(s): 81917a3

Initial POC

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -4,20 +4,39 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
 
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  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
  """
@@ -35,7 +54,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
35
  return "Please Login to Hugging Face with the button.", None
36
 
37
  api_url = DEFAULT_API_URL
38
- questions_url = f"{api_url}/questions"
 
39
  submit_url = f"{api_url}/submit"
40
 
41
  # 1. Instantiate Agent ( modify this part to create your agent)
@@ -44,7 +64,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
44
  except Exception as e:
45
  print(f"Error instantiating agent: {e}")
46
  return f"Error initializing agent: {e}", None
47
- # In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
48
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
49
  print(agent_code)
50
 
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ from smolagents import CodeAgent, WebSearchTool, InferenceClientModel, DuckDuckGoSearchTool, Tool
8
+
9
  # (Keep Constants as is)
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
+ prompt_templates = """
14
+ You are an expert assistant who can find out any fact. You are skilled in using search tools to find information, using reasoning to identify complex relationships and can generate code to find precise answers. You are being asked specific questions and the fate of the world rests in your ability to precisely answer them. Your primary objective is to track down the exact answer required by the question. The number of iterations needed to find the answer is not a concern so long as you are 100% confident in the answer you return.
15
+
16
+ After you identify and validate the exact answer to the question you will return only that with no further explanation. Debugging logs will be used if needed to identify how you arrived at that answer.
17
+ """
18
  # --- Basic Agent Definition ---
19
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
20
  class BasicAgent:
21
  def __init__(self):
22
+ websearchtool = WebSearchTool()
23
+ search_tool = DuckDuckGoSearchTool()
24
+ model = InferenceClientModel()
25
+ # TODO: add additional tools and or subagents (e.g. OpenAI image recognition)
26
+ master_agent = CodeAgent(
27
+ tools=[websearchtool, search_tool],
28
+ model=model,
29
+ add_base_tools=True,
30
+ planning_interval=3,
31
+ max_steps=10,
32
+ prompt_templates=prompt_templates,
33
+ )
34
  print("BasicAgent initialized.")
35
  def __call__(self, question: str) -> str:
36
  print(f"Agent received question (first 50 chars): {question[:50]}...")
37
+ agent_answer = master_agent.run(question)
38
+ print(f"Agent answer: {agent_answer}")
39
+ return agent_answer
40
 
41
  def run_and_submit_all( profile: gr.OAuthProfile | None):
42
  """
 
54
  return "Please Login to Hugging Face with the button.", None
55
 
56
  api_url = DEFAULT_API_URL
57
+ #questions_url = f"{api_url}/questions"
58
+ questions_url = f"{api_url}/random-question"
59
  submit_url = f"{api_url}/submit"
60
 
61
  # 1. Instantiate Agent ( modify this part to create your agent)
 
64
  except Exception as e:
65
  print(f"Error instantiating agent: {e}")
66
  return f"Error initializing agent: {e}", None
67
+ # In the case of an app running as a hugging Face space, this link points toward your codebase ( useful for others so please keep it public)
68
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
69
  print(agent_code)
70