9jini commited on
Commit
8122588
·
verified ·
1 Parent(s): d57b1a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -7
app.py CHANGED
@@ -3,23 +3,49 @@ import gradio as gr
3
  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
- #Carlitos was here
 
23
 
24
  def run_and_submit_all( profile: gr.OAuthProfile | None):
25
  """
@@ -148,13 +174,16 @@ with gr.Blocks() as demo:
148
  gr.Markdown(
149
  """
150
  **Instructions:**
 
151
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
152
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
153
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
 
154
  ---
155
  **Disclaimers:**
156
  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).
157
  This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
 
158
  """
159
  )
160
 
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from langchain_core.prompts import ChatPromptTemplate
7
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, WikipediaSearchTool
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
+ SYSTEM_PROMPT = """
14
+ You are GAIA-Bot, a fully-autonomous problem-solver.
15
+ • For each question, THINK step-by-step before answering.
16
+ • When outside knowledge or calculations are needed, CALL an appropriate tool.
17
+ • Explain your reasoning only to yourself (in “Thought” messages); do NOT reveal it to the user.
18
+ • After finishing all reasoning, RESPOND with **only** the final answer string—no pre-amble, no labels, no extra text.
19
+ You have access to these tools:
20
+ - gaia_file_fetch – download the file attached to the current task_id.
21
+ - duckduckgo_search – look up current facts on the public web.
22
+ If you require a file attached to the current task, download it with
23
+ `requests_get("https://agents-course-unit4-scoring.hf.space/files/{task_id}")`
24
+ and parse it inside Python.
25
+ Adhere strictly to these rules:
26
+ 1. Use tools whenever they can reduce hallucination.
27
+ 2. Never mention tool names or JSON in your final answer.
28
+ 3. If you cannot find an answer, return “unknown”.
29
+ Begin.
30
+ """
31
  # --- Basic Agent Definition ---
32
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
33
  class BasicAgent:
34
  def __init__(self):
35
+ model = OpenAIServerModel(model_id="deepseek-chat",api_key="sk-04da63f756c9468182d278f52e33ad15", api_base="https://api.deepseek.com")
36
+
37
+ search_tool = DuckDuckGoSearchTool()
38
+ wiki_search = WikipediaSearchTool()
39
+
40
+ self.agent = CodeAgent(
41
+ model = model,
42
+ tools=[search_tool,wiki_search],
43
+ prompt=SYSTEM_PROMPT,
44
+
45
+ )
46
 
47
+ def __call__(self, question: str) -> str:
48
+ return self.agent.run(question) # type: ignore
49
 
50
  def run_and_submit_all( profile: gr.OAuthProfile | None):
51
  """
 
174
  gr.Markdown(
175
  """
176
  **Instructions:**
177
+
178
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
179
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
180
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
181
+
182
  ---
183
  **Disclaimers:**
184
  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).
185
  This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
186
+ Please note that this version requires an OpenAI Key to run.
187
  """
188
  )
189