slush0 commited on
Commit
fd37b55
·
1 Parent(s): 92a31fb

WIP: Prevent overflooding max_length and throwing error.

Browse files
Files changed (2) hide show
  1. chat.py +5 -0
  2. prompt.py +5 -0
chat.py CHANGED
@@ -172,6 +172,11 @@ def _generate(
172
  state["history"] = orig_history + [[prompt, new_line + stats()]]
173
  yield state, state["history"], "", output
174
 
 
 
 
 
 
175
  # Final line w/o statistics
176
  yield state, state["history"], "", output
177
 
 
172
  state["history"] = orig_history + [[prompt, new_line + stats()]]
173
  yield state, state["history"], "", output
174
 
175
+ # Avoid throwing an exception by generate()
176
+ # to prevent UI errors.
177
+ if cnt >= max_length - 6: # FIXME Bulgarian constant
178
+ break
179
+
180
  # Final line w/o statistics
181
  yield state, state["history"], "", output
182
 
prompt.py CHANGED
@@ -109,6 +109,11 @@ def _generate(
109
 
110
  yield state, prompt2, output + stats()
111
 
 
 
 
 
 
112
  # Prints final result w/o statistics
113
  yield state, prompt2, output
114
  except Exception as e:
 
109
 
110
  yield state, prompt2, output + stats()
111
 
112
+ # Avoid throwing exception by generate()
113
+ # to prevent UI errors.
114
+ if cnt >= max_length - 6: # FIXME bulgarian constant
115
+ break
116
+
117
  # Prints final result w/o statistics
118
  yield state, prompt2, output
119
  except Exception as e: