Amir313 commited on
Commit
0a34b76
·
1 Parent(s): 81917a3

First simple implementation

Browse files
Files changed (2) hide show
  1. app.py +9 -1
  2. prompt.txt +0 -0
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 ---
@@ -12,10 +13,17 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
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
 
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, VisitWebpageTool, FinalAnswerTool
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
 
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
  class BasicAgent:
15
  def __init__(self):
16
+ self.agent = CodeAgent(
17
+ model=HfApiModel(model="Qwen/Qwen2.5-72B-Instruct"),
18
+ tools=[DuckDuckGoSearchTool(), VisitWebpageTool(), FinalAnswerTool()],
19
+ verbose=True,
20
+ max_steps=5,
21
+ )
22
  print("BasicAgent initialized.")
23
  def __call__(self, question: str) -> str:
24
  print(f"Agent received question (first 50 chars): {question[:50]}...")
25
+ prompt = "You are a general AI assistant. I will ask you a question. When answering, provide only the requested answer with no explanatory text, formatting, or preamble.. 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."
26
+ fixed_answer = self.agent.run(prompt)
27
  print(f"Agent returning fixed answer: {fixed_answer}")
28
  return fixed_answer
29
 
prompt.txt ADDED
File without changes