dawid-lorek commited on
Commit
2d924bf
·
verified ·
1 Parent(s): 5c60e20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -20
app.py CHANGED
@@ -2,36 +2,25 @@ import os
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
5
- import openai
6
 
7
- from smolagents.agents import ToolCallingAgent
8
- from smolagents.tools.code_interpreter import CodeInterpreterTool
9
- from langchain_community.tools import DuckDuckGoSearchRun
10
 
11
  # Constants
12
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
13
 
14
- # --- Agent Definition with Tools ---
15
  class SmartGAIAAgent:
16
  def __init__(self):
17
  self.api_key = os.getenv("OPENAI_API_KEY")
18
  if not self.api_key:
19
  raise ValueError("Missing OPENAI_API_KEY")
20
- openai.api_key = self.api_key
21
-
22
- # Define tools
23
- self.search = DuckDuckGoSearchRun()
24
- self.calculator = CodeInterpreterTool()
25
-
26
- # Create tool-using agent
27
- self.agent = ToolCallingAgent(
28
- tools=[self.search, self.calculator],
29
- model="gpt-4",
30
- max_steps=8,
31
- system_prompt=(
32
- "You are a helpful assistant solving complex reasoning and factual questions. "
33
- "Use tools only if needed. Return only the final answer. Do not add explanations or formatting."
34
- )
35
  )
36
 
37
  def __call__(self, question: str) -> str:
 
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
 
5
 
6
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel
 
 
7
 
8
  # Constants
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
+ # --- Agent Definition using smolagents ---
12
  class SmartGAIAAgent:
13
  def __init__(self):
14
  self.api_key = os.getenv("OPENAI_API_KEY")
15
  if not self.api_key:
16
  raise ValueError("Missing OPENAI_API_KEY")
17
+ self.model = OpenAIServerModel(model_id="gpt-4", api_key=self.api_key)
18
+
19
+ # Agent with DuckDuckGo and code execution tool
20
+ self.agent = CodeAgent(
21
+ tools=[DuckDuckGoSearchTool()],
22
+ model=self.model,
23
+ add_base_tools=True # adds code interpreter and other built-ins
 
 
 
 
 
 
 
 
24
  )
25
 
26
  def __call__(self, question: str) -> str: