Spaces:
Sleeping
Sleeping
Commit
·
9dc66e6
1
Parent(s):
856bd20
update
Browse files
app.py
CHANGED
@@ -3,12 +3,12 @@ import openai
|
|
3 |
import os
|
4 |
|
5 |
# Set up OpenAI API key (use an environment variable for security)
|
6 |
-
|
|
|
7 |
|
8 |
def chat_with_ai(prompt):
|
9 |
"""Generates a response from OpenAI's GPT-3.5."""
|
10 |
try:
|
11 |
-
client = openai.OpenAI()
|
12 |
response = client.chat.completions.create(
|
13 |
model="gpt-3.5-turbo",
|
14 |
messages=[{"role": "user", "content": prompt}]
|
|
|
3 |
import os
|
4 |
|
5 |
# Set up OpenAI API key (use an environment variable for security)
|
6 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
7 |
+
client = openai.OpenAI(api_key=api_key)
|
8 |
|
9 |
def chat_with_ai(prompt):
|
10 |
"""Generates a response from OpenAI's GPT-3.5."""
|
11 |
try:
|
|
|
12 |
response = client.chat.completions.create(
|
13 |
model="gpt-3.5-turbo",
|
14 |
messages=[{"role": "user", "content": prompt}]
|