Ashhar commited on
Commit
b40d264
·
1 Parent(s): 28b826f

fixed retry loop on consecutive user msgs

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -83,6 +83,9 @@ def __isInvalidResponse(response: str):
83
 
84
  if C.EXCEPTION_KEYWORD in response:
85
  U.pprint("LLM API threw exception")
 
 
 
86
  return True
87
 
88
  if ('{\n "options"' in response) and (C.JSON_SEPARATOR not in response):
@@ -253,7 +256,6 @@ def predict():
253
  max_tokens=4000,
254
  stream=True
255
  )
256
-
257
  for chunk in response:
258
  choices = chunk.choices
259
  if not choices:
@@ -264,7 +266,7 @@ def predict():
264
  yield chunkContent
265
  except Exception as e:
266
  U.pprint(f"LLM API Error: {e}")
267
- yield C.EXCEPTION_KEYWORD
268
 
269
 
270
  def __generateImage(prompt: str):
 
83
 
84
  if C.EXCEPTION_KEYWORD in response:
85
  U.pprint("LLM API threw exception")
86
+ if 'roles must alternate between "user" and "assistant"' in str(response):
87
+ U.pprint("Removing last msg from context...")
88
+ st.session_state.messages.pop(-2)
89
  return True
90
 
91
  if ('{\n "options"' in response) and (C.JSON_SEPARATOR not in response):
 
256
  max_tokens=4000,
257
  stream=True
258
  )
 
259
  for chunk in response:
260
  choices = chunk.choices
261
  if not choices:
 
266
  yield chunkContent
267
  except Exception as e:
268
  U.pprint(f"LLM API Error: {e}")
269
+ yield f"{C.EXCEPTION_KEYWORD} | {e}"
270
 
271
 
272
  def __generateImage(prompt: str):