FinnNick commited on
Commit
fbf97e1
·
verified ·
1 Parent(s): 81917a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -12,12 +12,25 @@ 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
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
 
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
14
  def __init__(self):
15
+ from openai import OpenAI
16
+ self.llm = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
17
  print("BasicAgent initialized.")
18
  def __call__(self, question: str) -> str:
19
+ prompt = f"""Answer the following concisely and exactly:
20
+ {question}"""
21
+ try:
22
+ response = self.llm.chat.completions.create(
23
+ model="gpt-4o",
24
+ messages=[
25
+ {"role": "system", "content": "You are an expert AI assistant."},
26
+ {"role": "user", "content": prompt}
27
+ ],
28
+ temperature=0.2,
29
+ )
30
+ return response.choices[0].message.content.strip()
31
+ except Exception as e:
32
+ return f"ERROR: {e}"
33
+
34
 
35
  def run_and_submit_all( profile: gr.OAuthProfile | None):
36
  """