Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,30 @@
|
|
1 |
import os
|
2 |
-
import
|
3 |
-
import gradio as gr
|
4 |
import requests
|
5 |
import pandas as pd
|
6 |
|
7 |
# --- Configuration ---
|
8 |
-
|
9 |
API_URL = "https://agents-course-unit4-scoring.hf.space"
|
10 |
-
MODEL_NAME = "gpt-4.1"
|
11 |
|
12 |
-
# ---
|
|
|
|
|
|
|
13 |
def ask_chatgpt_4_1(question: str) -> str:
|
14 |
-
response =
|
15 |
model=MODEL_NAME,
|
16 |
-
|
17 |
-
{"role": "system", "content": "You are a helpful assistant."},
|
18 |
-
{"role": "user", "content": question}
|
19 |
-
],
|
20 |
-
temperature=0.7,
|
21 |
-
max_tokens=1500
|
22 |
)
|
23 |
-
|
|
|
24 |
|
25 |
# --- Agent Class ---
|
26 |
class BasicAgent:
|
27 |
def __init__(self):
|
28 |
-
print("BasicAgent using OpenAI GPT-4.1 ready.")
|
29 |
|
30 |
def __call__(self, question: str) -> str:
|
31 |
print(f"Q>> {question}")
|
|
|
1 |
import os
|
2 |
+
from openai import OpenAI # new client entrypoint
|
3 |
+
import gradio as gr
|
4 |
import requests
|
5 |
import pandas as pd
|
6 |
|
7 |
# --- Configuration ---
|
8 |
+
# In your Space settings, add OPENAI_API_KEY as a Secret; the client reads it automatically.
|
9 |
API_URL = "https://agents-course-unit4-scoring.hf.space"
|
10 |
+
MODEL_NAME = "gpt-4.1"
|
11 |
|
12 |
+
# --- OpenAI Client ---
|
13 |
+
client = OpenAI() # reads OPENAI_API_KEY from env
|
14 |
+
|
15 |
+
# --- GPT-4.1 Caller ---
|
16 |
def ask_chatgpt_4_1(question: str) -> str:
|
17 |
+
response = client.responses.create(
|
18 |
model=MODEL_NAME,
|
19 |
+
input=question
|
|
|
|
|
|
|
|
|
|
|
20 |
)
|
21 |
+
# The new library returns `output_text`
|
22 |
+
return response.output_text
|
23 |
|
24 |
# --- Agent Class ---
|
25 |
class BasicAgent:
|
26 |
def __init__(self):
|
27 |
+
print("BasicAgent using OpenAI GPT-4.1 (new client) ready.")
|
28 |
|
29 |
def __call__(self, question: str) -> str:
|
30 |
print(f"Q>> {question}")
|