Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import gradio as gr
|
|
| 4 |
import openai
|
| 5 |
import os
|
| 6 |
|
| 7 |
-
#
|
| 8 |
openai.api_key ='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'
|
| 9 |
|
| 10 |
def get_completion(code_snippet):
|
|
@@ -44,13 +44,14 @@ def get_completion(code_snippet):
|
|
| 44 |
"""
|
| 45 |
|
| 46 |
try:
|
| 47 |
-
# Using the updated method for chat completion
|
| 48 |
response = openai.ChatCompletion.create(
|
| 49 |
-
model="gpt-3.5-turbo",
|
| 50 |
messages=[{"role": "user", "content": prompt}],
|
| 51 |
-
max_tokens=
|
| 52 |
)
|
| 53 |
return response['choices'][0]['message']['content']
|
|
|
|
|
|
|
| 54 |
except Exception as e:
|
| 55 |
return f"An error occurred: {str(e)}"
|
| 56 |
|
|
|
|
| 4 |
import openai
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# Set your OpenAI API key
|
| 8 |
openai.api_key ='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'
|
| 9 |
|
| 10 |
def get_completion(code_snippet):
|
|
|
|
| 44 |
"""
|
| 45 |
|
| 46 |
try:
|
|
|
|
| 47 |
response = openai.ChatCompletion.create(
|
| 48 |
+
model="gpt-3.5-turbo",
|
| 49 |
messages=[{"role": "user", "content": prompt}],
|
| 50 |
+
max_tokens=300 # Reduced max tokens to limit usage
|
| 51 |
)
|
| 52 |
return response['choices'][0]['message']['content']
|
| 53 |
+
except openai.error.RateLimitError:
|
| 54 |
+
return "Quota exceeded. Please try again later."
|
| 55 |
except Exception as e:
|
| 56 |
return f"An error occurred: {str(e)}"
|
| 57 |
|