Spaces:
Sleeping
Sleeping
Alexander Hux
commited on
Commit
·
31fbac4
1
Parent(s):
cc25147
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,12 +26,18 @@ def CustomChatGPT(user_input):
|
|
| 26 |
# Ensure the conversation fits within the model's maximum token limit
|
| 27 |
conversation = messages[-4096:]
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
except openai.error.RequestError as e:
|
| 36 |
print(f"Received error from OpenAI: {e}")
|
| 37 |
return "I'm sorry, but I'm unable to generate a response at this time."
|
|
|
|
| 26 |
# Ensure the conversation fits within the model's maximum token limit
|
| 27 |
conversation = messages[-4096:]
|
| 28 |
|
| 29 |
+
try:
|
| 30 |
+
# Code that might raise an exception
|
| 31 |
+
response = openai.ChatCompletion.create(
|
| 32 |
+
model="gpt-3.5-turbo",
|
| 33 |
+
messages=conversation,
|
| 34 |
+
max_tokens=1000,
|
| 35 |
+
temperature=0.7)
|
| 36 |
+
except openai.error.RequestError as e:
|
| 37 |
+
# Code to run if the exception is raised
|
| 38 |
+
print(f"Received error from OpenAI: {e}")
|
| 39 |
+
return "I'm sorry, but I'm unable to generate a response at this time."
|
| 40 |
+
|
| 41 |
except openai.error.RequestError as e:
|
| 42 |
print(f"Received error from OpenAI: {e}")
|
| 43 |
return "I'm sorry, but I'm unable to generate a response at this time."
|