Vani7065 commited on
Commit
92b7cca
·
verified ·
1 Parent(s): a9b5de4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -3,7 +3,8 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
- import openai
 
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
@@ -11,19 +12,21 @@ 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
  self.api_key = os.getenv("OPENAI_API_KEY")
17
  if not self.api_key:
18
  raise ValueError("OpenAI API key not found. Please set OPENAI_API_KEY as environment variable.")
19
- openai.api_key = self.api_key
20
- print("🔑 OpenAI Agent initialized.")
21
 
22
  def __call__(self, question: str) -> str:
23
  print(f"❓ Question received: {question[:50]}...")
24
  try:
25
- response = openai.ChatCompletion.create(
26
- model="gpt-3.5-turbo", # or "gpt-4" if you have access
27
  messages=[
28
  {"role": "system", "content": "You are a helpful assistant that answers GAIA benchmark questions."},
29
  {"role": "user", "content": question}
@@ -31,7 +34,7 @@ class BasicAgent:
31
  max_tokens=300,
32
  temperature=0.7
33
  )
34
- answer = response["choices"][0]["message"]["content"].strip()
35
  print(f"✅ Answer: {answer}")
36
  return answer
37
  except Exception as e:
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from openai import OpenAI
7
+ import os
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
 
12
 
13
  # --- Basic Agent Definition ---
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
+
16
+
17
  class BasicAgent:
18
  def __init__(self):
19
  self.api_key = os.getenv("OPENAI_API_KEY")
20
  if not self.api_key:
21
  raise ValueError("OpenAI API key not found. Please set OPENAI_API_KEY as environment variable.")
22
+ self.client = OpenAI(api_key=self.api_key)
23
+ print(" OpenAI Agent initialized (v1+ syntax).")
24
 
25
  def __call__(self, question: str) -> str:
26
  print(f"❓ Question received: {question[:50]}...")
27
  try:
28
+ response = self.client.chat.completions.create(
29
+ model="gpt-3.5-turbo",
30
  messages=[
31
  {"role": "system", "content": "You are a helpful assistant that answers GAIA benchmark questions."},
32
  {"role": "user", "content": question}
 
34
  max_tokens=300,
35
  temperature=0.7
36
  )
37
+ answer = response.choices[0].message.content.strip()
38
  print(f"✅ Answer: {answer}")
39
  return answer
40
  except Exception as e: