diff --git a/crates/meilisearch-types/src/error.rs b/crates/meilisearch-types/src/error.rs index 077600a8e..3f7f00cd0 100644 --- a/crates/meilisearch-types/src/error.rs +++ b/crates/meilisearch-types/src/error.rs @@ -391,6 +391,7 @@ EditDocumentsByFunctionError , InvalidRequest , BAD_REQU InvalidSettingsIndexChat , InvalidRequest , BAD_REQUEST ; // Experimental features - Chat Completions UnimplementedNonStreamingChatCompletions , InvalidRequest , NOT_IMPLEMENTED ; +UnimplementedMultiChoiceChatCompletions , InvalidRequest , NOT_IMPLEMENTED ; ChatNotFound , InvalidRequest , NOT_FOUND ; InvalidChatCompletionOrgId , InvalidRequest , BAD_REQUEST ; InvalidChatCompletionProjectId , InvalidRequest , BAD_REQUEST ; diff --git a/crates/meilisearch/src/routes/chats/chat_completions.rs b/crates/meilisearch/src/routes/chats/chat_completions.rs index 786398cf7..e06f9a082 100644 --- a/crates/meilisearch/src/routes/chats/chat_completions.rs +++ b/crates/meilisearch/src/routes/chats/chat_completions.rs @@ -64,12 +64,6 @@ async fn chat( ) -> impl Responder { let ChatsParam { workspace_uid } = chats_param.into_inner(); - assert_eq!( - chat_completion.n.unwrap_or(1), - 1, - "Meilisearch /chat only support one completion at a time (n = 1, n = null)" - ); - if chat_completion.stream.unwrap_or(false) { Either::Right( streamed_chat( @@ -309,6 +303,13 @@ async fn non_streamed_chat( ) -> Result { index_scheduler.features().check_chat_completions("using the /chats chat completions route")?; + if let Some(n) = chat_completion.n.filter(|&n| n != 1) { + return Err(ResponseError::from_msg( + format!("You tried to specify n = {n} but only single choices are supported (n = 1)."), + Code::UnimplementedMultiChoiceChatCompletions, + )); + } + return Err(ResponseError::from_msg( "Non-streamed chat completions is not implemented".to_string(), Code::UnimplementedNonStreamingChatCompletions, @@ -412,6 +413,13 @@ async fn streamed_chat( index_scheduler.features().check_chat_completions("using the /chats chat completions route")?; let filters = index_scheduler.filters(); + if let Some(n) = chat_completion.n.filter(|&n| n != 1) { + return Err(ResponseError::from_msg( + format!("You tried to specify n = {n} but only single choices are supported (n = 1)."), + Code::UnimplementedMultiChoiceChatCompletions, + )); + } + let chat_settings = match index_scheduler.chat_settings(workspace_uid)? { Some(settings) => settings, None => {