dawid-lorek commited on
Commit
91cad6f
·
verified ·
1 Parent(s): cfcd62e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -25
app.py CHANGED
@@ -4,37 +4,32 @@ import requests
4
  import inspect
5
  import pandas as pd
6
  import openai
 
 
 
7
 
8
- # (Keep Constants as is)
9
- # --- Constants ---
10
- DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
-
12
- # --- Basic Agent Definition ---
13
- # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
- class BasicAgent:
15
  def __init__(self):
16
- openai.api_key = os.getenv("OPENAI_API_KEY") # Set this in HF secrets
17
-
18
- def __call__(self, question: str) -> str:
19
- system_prompt = (
20
- "You are a smart AI assistant that answers factual questions clearly and concisely. "
21
- "If a question requires step-by-step reasoning, do it in your head before producing a short answer. "
22
- "Answer with a single sentence or phrase, no extra explanation, and no 'Final answer' phrase."
 
 
 
 
 
 
23
  )
24
 
 
25
  try:
26
- response = openai.ChatCompletion.create(
27
- model="gpt-4",
28
- messages=[
29
- {"role": "system", "content": system_prompt},
30
- {"role": "user", "content": question}
31
- ],
32
- temperature=0.3,
33
- )
34
- answer = response['choices'][0]['message']['content'].strip()
35
- return answer
36
  except Exception as e:
37
- print(f"Error during OpenAI call: {e}")
38
  return "error"
39
 
40
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
4
  import inspect
5
  import pandas as pd
6
  import openai
7
+ from smolagents.agents import ToolCallingAgent
8
+ from smolagents.tools import CodeInterpreterTool
9
+ from langchain_community.tools import DuckDuckGoSearchRun
10
 
11
+ class SmartGAIAAgent:
 
 
 
 
 
 
12
  def __init__(self):
13
+ openai.api_key = os.getenv("OPENAI_API_KEY")
14
+
15
+ self.search = DuckDuckGoSearchRun()
16
+ self.calculator = CodeInterpreterTool()
17
+
18
+ self.agent = ToolCallingAgent(
19
+ tools=[self.search, self.calculator],
20
+ model="gpt-4", # or gpt-3.5-turbo
21
+ max_steps=8,
22
+ system_prompt=(
23
+ "You are an expert assistant answering complex factual and reasoning questions. "
24
+ "Use tools only when necessary. Only return the final answer, nothing else."
25
+ )
26
  )
27
 
28
+ def __call__(self, question: str) -> str:
29
  try:
30
+ return self.agent.run(question)
 
 
 
 
 
 
 
 
 
31
  except Exception as e:
32
+ print(f"Agent error: {e}")
33
  return "error"
34
 
35
  def run_and_submit_all( profile: gr.OAuthProfile | None):