Spaces:
Running
Running
Remove retry mechanism from conversation route
Browse files- server/backend.py +27 -33
server/backend.py
CHANGED
@@ -24,43 +24,37 @@ class Backend_Api:
|
|
24 |
}
|
25 |
|
26 |
def _conversation(self):
|
27 |
-
"""
|
28 |
-
Handles the conversation route.
|
29 |
|
30 |
-
:return: Response object containing the generated conversation stream
|
31 |
"""
|
32 |
-
max_retries = 3
|
33 |
-
retries = 0
|
34 |
conversation_id = request.json['conversation_id']
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
'success': False,
|
61 |
-
"error": f"an error occurred {str(e)}"
|
62 |
-
}, 400
|
63 |
-
time.sleep(3) # Wait 3 second before trying again
|
64 |
|
65 |
|
66 |
def build_messages(jailbreak):
|
|
|
24 |
}
|
25 |
|
26 |
def _conversation(self):
|
27 |
+
"""
|
28 |
+
Handles the conversation route.
|
29 |
|
30 |
+
:return: Response object containing the generated conversation stream
|
31 |
"""
|
|
|
|
|
32 |
conversation_id = request.json['conversation_id']
|
33 |
|
34 |
+
try:
|
35 |
+
jailbreak = request.json['jailbreak']
|
36 |
+
model = request.json['model']
|
37 |
+
messages = build_messages(jailbreak)
|
38 |
+
|
39 |
+
# Generate response
|
40 |
+
response = ChatCompletion.create(
|
41 |
+
model=model,
|
42 |
+
stream=True,
|
43 |
+
chatId=conversation_id,
|
44 |
+
messages=messages
|
45 |
+
)
|
46 |
+
|
47 |
+
return Response(stream_with_context(generate_stream(response, jailbreak)), mimetype='text/event-stream')
|
48 |
+
|
49 |
+
except Exception as e:
|
50 |
+
print(e)
|
51 |
+
print(e.__traceback__.tb_next)
|
52 |
+
|
53 |
+
return {
|
54 |
+
'_action': '_ask',
|
55 |
+
'success': False,
|
56 |
+
"error": f"an error occurred {str(e)}"
|
57 |
+
}, 400
|
|
|
|
|
|
|
|
|
58 |
|
59 |
|
60 |
def build_messages(jailbreak):
|