Skip to content

Commit 4105b1c

Browse files
committed
better error handling in chatbot v10, and avoid to start with models beginning with all-
they do not support the generate interface as it seems
1 parent d7ca0c8 commit 4105b1c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

notebooks/tps/chatbot/chatbot-10.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ def update_models(self):
153153
if current_model in available_models:
154154
self.model.value = current_model
155155
else:
156-
# find the first model that does start with
157-
available_models[0]
156+
# xxx somehow the first model on GPU - all-minilm:22m-l6-v2-fp16
157+
# returns an error saying the model does not support generate
158+
# so, as a workaround, find the first model that does not start with all-
159+
self.model.value = next(
160+
model for model in available_models if not model.startswith("all-")
161+
)
158162
self.page.update()
159163

160164
def submit(self, event):
@@ -204,6 +208,9 @@ def send_request(self, _event):
204208
if not streaming:
205209
answer = requests.post(url, json=data, **extra_args)
206210
print("HTTP status code:", answer.status_code)
211+
if answer.status_code != 200:
212+
history.add_answer(f"Error: {answer.text}")
213+
return
207214
# print(f"Received answer: {answer.text}")
208215
# turns out we receive a stream of JSON objects
209216
# each one on its own line
@@ -230,6 +237,9 @@ def send_request(self, _event):
230237
# and read the stream
231238
with requests.post(url, json=data, stream=True, **extra_args) as answer:
232239
print("HTTP status code:", answer.status_code)
240+
if answer.status_code != 200:
241+
history.add_chunk(f"Error: {answer.text}")
242+
return
233243
for line in answer.iter_lines():
234244
if not line:
235245
continue

0 commit comments

Comments
 (0)