Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,18 +54,27 @@ with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
|
| 54 |
return mode
|
| 55 |
|
| 56 |
def answer(history):
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
return result
|
| 70 |
|
| 71 |
def init_history(language, messages_history1, messages_history2, messages_history3): #Reinitialize the state file
|
|
|
|
| 54 |
return mode
|
| 55 |
|
| 56 |
def answer(history):
|
| 57 |
+
for attempt in range(5):
|
| 58 |
+
try:
|
| 59 |
+
response = openai.ChatCompletion.create(
|
| 60 |
+
model='gpt-3.5-turbo',
|
| 61 |
+
messages=history,
|
| 62 |
+
temperature=0.5,
|
| 63 |
+
max_tokens=800,
|
| 64 |
+
top_p=1,
|
| 65 |
+
n=1,
|
| 66 |
+
frequency_penalty=0.9,
|
| 67 |
+
presence_penalty=0.9,
|
| 68 |
+
stop=None
|
| 69 |
+
)
|
| 70 |
+
result = response['choices'][0]['message']['content']
|
| 71 |
+
break
|
| 72 |
+
except Exception as e:
|
| 73 |
+
print(f"Error occurred on attempt {attempt + 1}: {e}")
|
| 74 |
+
if attempt < 5:
|
| 75 |
+
time.sleep(10)
|
| 76 |
+
else:
|
| 77 |
+
raise e
|
| 78 |
return result
|
| 79 |
|
| 80 |
def init_history(language, messages_history1, messages_history2, messages_history3): #Reinitialize the state file
|