Spaces:
Sleeping
Sleeping
Pavlo Kostianov commited on
Commit ·
c525991
1
Parent(s): e39b497
Update OpenAI instructions
Browse files
app.py
CHANGED
|
@@ -2,10 +2,10 @@ import pandas as pd
|
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
import os
|
| 5 |
-
|
| 6 |
|
| 7 |
# 1. Configure OpenAI
|
| 8 |
-
|
| 9 |
MODEL_NAME = "gpt-5"
|
| 10 |
|
| 11 |
|
|
@@ -196,7 +196,7 @@ Rules:
|
|
| 196 |
|
| 197 |
try:
|
| 198 |
# Ask OpenAI
|
| 199 |
-
response =
|
| 200 |
model=MODEL_NAME,
|
| 201 |
messages=[
|
| 202 |
{"role": "system", "content": "You are a helpful assistant."},
|
|
@@ -205,7 +205,7 @@ Rules:
|
|
| 205 |
temperature=0.2,
|
| 206 |
max_tokens=1200
|
| 207 |
)
|
| 208 |
-
code = response.choices[0].message
|
| 209 |
|
| 210 |
# Strip markdown fences if any
|
| 211 |
if code.startswith("```"):
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
import os
|
| 5 |
+
from openai import OpenAI # requires OPENAI_API_KEY set as env var
|
| 6 |
|
| 7 |
# 1. Configure OpenAI
|
| 8 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 9 |
MODEL_NAME = "gpt-5"
|
| 10 |
|
| 11 |
|
|
|
|
| 196 |
|
| 197 |
try:
|
| 198 |
# Ask OpenAI
|
| 199 |
+
response = client.chat.completions.create(
|
| 200 |
model=MODEL_NAME,
|
| 201 |
messages=[
|
| 202 |
{"role": "system", "content": "You are a helpful assistant."},
|
|
|
|
| 205 |
temperature=0.2,
|
| 206 |
max_tokens=1200
|
| 207 |
)
|
| 208 |
+
code = response.choices[0].message.content.strip()
|
| 209 |
|
| 210 |
# Strip markdown fences if any
|
| 211 |
if code.startswith("```"):
|