From 97f93dfa88c7eb373e9b5f1d027efadbf0af2d6b Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Mon, 28 Oct 2024 02:18:14 -0700 Subject: [PATCH] fix(answer): handle cases that no choices is returned from chat model. (#3329) * fix(answer): handle cases that no choices is returned from chat model. * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- ee/tabby-webserver/src/service/answer.rs | 3 ++- ee/tabby-webserver/src/service/user_group.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ee/tabby-webserver/src/service/answer.rs b/ee/tabby-webserver/src/service/answer.rs index 058e49ff85d..7f359c3cf18 100644 --- a/ee/tabby-webserver/src/service/answer.rs +++ b/ee/tabby-webserver/src/service/answer.rs @@ -183,7 +183,8 @@ impl AnswerService { } }; - if let Some(content) = chunk.choices[0].delta.content.as_deref() { + let content = chunk.choices.first().and_then(|x| x.delta.content.as_deref()); + if let Some(content) = content { yield Ok(ThreadRunItem::ThreadAssistantMessageContentDelta(ThreadAssistantMessageContentDelta { delta: content.to_owned() })); diff --git a/ee/tabby-webserver/src/service/user_group.rs b/ee/tabby-webserver/src/service/user_group.rs index e26d79cd496..39b233f0e39 100644 --- a/ee/tabby-webserver/src/service/user_group.rs +++ b/ee/tabby-webserver/src/service/user_group.rs @@ -7,7 +7,7 @@ use tabby_schema::{ AsID, AsRowid, Result, }; -use super::{UserGroupExt, UserSecuredExt}; +use super::UserGroupExt; struct UserGroupServiceImpl { db: DbConn,