Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import openai
|
| 4 |
import os
|
| 5 |
|
| 6 |
# Configure the OpenAI API key
|
| 7 |
-
openai.api_key = os.getenv('sk-proj-
|
| 8 |
|
| 9 |
def get_completion(code_snippet):
|
| 10 |
# Code examples to illustrate the output
|
|
@@ -43,12 +44,13 @@ def get_completion(code_snippet):
|
|
| 43 |
"""
|
| 44 |
|
| 45 |
try:
|
| 46 |
-
|
|
|
|
| 47 |
model="gpt-3.5-turbo", # Specify the model
|
| 48 |
messages=[{"role": "user", "content": prompt}],
|
| 49 |
max_tokens=500
|
| 50 |
)
|
| 51 |
-
return
|
| 52 |
except Exception as e:
|
| 53 |
return f"An error occurred: {str(e)}"
|
| 54 |
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
import openai
|
| 5 |
import os
|
| 6 |
|
| 7 |
# Configure the OpenAI API key
|
| 8 |
+
openai.api_key = os.getenv('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') # Ensure your API key is set in environment variables
|
| 9 |
|
| 10 |
def get_completion(code_snippet):
|
| 11 |
# Code examples to illustrate the output
|
|
|
|
| 44 |
"""
|
| 45 |
|
| 46 |
try:
|
| 47 |
+
# Updated to use openai.ChatCompletion.create
|
| 48 |
+
response = openai.ChatCompletion.create(
|
| 49 |
model="gpt-3.5-turbo", # Specify the model
|
| 50 |
messages=[{"role": "user", "content": prompt}],
|
| 51 |
max_tokens=500
|
| 52 |
)
|
| 53 |
+
return response['choices'][0]['message']['content']
|
| 54 |
except Exception as e:
|
| 55 |
return f"An error occurred: {str(e)}"
|
| 56 |
|