darrenphodgson76 commited on
Commit
f1dea33
·
verified ·
1 Parent(s): 71d1fe6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -1,31 +1,30 @@
1
  import os
2
- import openai # 🍕 https://www.google.com/search?q=openai.ChatCompletion.create
3
- import gradio as gr # 🍣 https://www.google.com/search?q=Gradio+python
4
  import requests
5
  import pandas as pd
6
 
7
  # --- Configuration ---
8
- openai.api_key = os.getenv("OPENAI_API_KEY") # 🍱 https://www.google.com/search?q=python+environment+variables
9
  API_URL = "https://agents-course-unit4-scoring.hf.space"
10
- MODEL_NAME = "gpt-4.1" # 🍜 https://www.google.com/search?q=gpt-4.1+openai+model+id
11
 
12
- # --- ChatGPT-4.1 Caller ---
 
 
 
13
  def ask_chatgpt_4_1(question: str) -> str:
14
- response = openai.ChatCompletion.create(
15
  model=MODEL_NAME,
16
- messages=[
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
- return response.choices[0].message.content
 
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}")