Update app.py
Browse files
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 |
-
|
|
|
16 |
def __call__(self, question: str) -> str:
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
"""
|