dawid-lorek commited on
Commit
f86bd24
·
verified ·
1 Parent(s): 81917a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -12,12 +13,29 @@ 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
  """
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ import openai
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
 
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):
41
  """