deanoreese commited on
Commit
d1c343c
·
verified ·
1 Parent(s): 3c2e9d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -10,23 +10,28 @@ 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
- from transformers import pipeline
 
 
14
  import os
15
 
16
  class BasicAgent:
17
  def __init__(self):
18
- print(" Using flan-t5-base for fast generation...")
19
- self.generator = pipeline(
20
- "text2text-generation", # Note: different pipeline type for T5-style models
21
- model="google/flan-t5-base",
22
- token=os.getenv("HF_API_KEY")
 
 
 
 
 
 
23
  )
24
 
25
  def __call__(self, question: str) -> str:
26
- prompt = f"Answer this question: {question}"
27
- result = self.generator(prompt, max_new_tokens=50, truncation=True)
28
- return result[0]['generated_text'].strip()
29
-
30
 
31
  def run_and_submit_all( profile: gr.OAuthProfile | None):
32
  """
 
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
+ from smolagent.agent import ToolCallingAgent
14
+ from smolagent.models.hf_api import HfApiModel
15
+ from smolagent.tools.duckduckgo import DuckDuckGoSearchTool
16
  import os
17
 
18
  class BasicAgent:
19
  def __init__(self):
20
+ print(" Agent with search + model ready...")
21
+ self.model = HfApiModel(
22
+ model="mistralai/Mistral-7B-Instruct-v0.2", # or flan-t5-xl if smaller
23
+ api_key=os.getenv("HF_API_KEY")
24
+ )
25
+ self.agent = ToolCallingAgent(
26
+ name="search_agent",
27
+ description="Agent that can use web search and answer questions.",
28
+ model=self.model,
29
+ tools=[DuckDuckGoSearchTool()],
30
+ max_steps=4
31
  )
32
 
33
  def __call__(self, question: str) -> str:
34
+ return self.agent.run(question).strip()
 
 
 
35
 
36
  def run_and_submit_all( profile: gr.OAuthProfile | None):
37
  """