monra commited on
Commit
5342779
1 Parent(s): 9a577ee

Remove retry mechanism from conversation route

Browse files
Files changed (1) hide show
  1. 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
- while retries < max_retries:
37
- try:
38
- jailbreak = request.json['jailbreak']
39
- model = request.json['model']
40
- messages = build_messages(jailbreak)
41
-
42
- # Generate response
43
- response = ChatCompletion.create(
44
- model=model,
45
- stream=True,
46
- chatId=conversation_id,
47
- messages=messages
48
- )
49
-
50
- return Response(stream_with_context(generate_stream(response, jailbreak)), mimetype='text/event-stream')
51
-
52
- except Exception as e:
53
- print(e)
54
- print(e.__traceback__.tb_next)
55
-
56
- retries += 1
57
- if retries >= max_retries:
58
- return {
59
- '_action': '_ask',
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):