From 5aa6cb360056a2b2792b8375bef32b74cdabfaa1 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 30 Jul 2024 15:44:47 +0200 Subject: [PATCH] Specialize authorized error message depending on config source --- milli/src/vector/error.rs | 24 ++++++++++++++++++++---- milli/src/vector/rest.rs | 5 ++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/milli/src/vector/error.rs b/milli/src/vector/error.rs index 7e1cb8752..3c8cb4b06 100644 --- a/milli/src/vector/error.rs +++ b/milli/src/vector/error.rs @@ -62,8 +62,18 @@ pub enum EmbedErrorKind { RestResponseDeserialization(std::io::Error), #[error("expected a response containing {0} embeddings, got only {1}")] RestResponseEmbeddingCount(usize, usize), - #[error("could not authenticate against embedding server{}", option_info(.0.as_deref(), "server replied with "))] - RestUnauthorized(Option), + #[error("could not authenticate against {embedding} server{server_reply}{hint}", embedding=match *.1 { + ConfigurationSource::User => "embedding", + ConfigurationSource::OpenAi => "OpenAI", + ConfigurationSource::Ollama => "ollama" + }, + server_reply=option_info(.0.as_deref(), "server replied with "), + hint=match *.1 { + ConfigurationSource::User => "\n - Hint: Check the `apiKey` parameter in the embedder configuration", + ConfigurationSource::OpenAi => "\n - Hint: Check the `apiKey` parameter in the embedder configuration, and the `MEILI_OPENAI_API_KEY` and `OPENAI_API_KEY` environment variables", + ConfigurationSource::Ollama => "\n - Hint: Check the `apiKey` parameter in the embedder configuration" + })] + RestUnauthorized(Option, ConfigurationSource), #[error("sent too many requests to embedding server{}", option_info(.0.as_deref(), "server replied with "))] RestTooManyRequests(Option), #[error("sent a bad request to embedding server{}{}", @@ -136,8 +146,14 @@ impl EmbedError { } } - pub(crate) fn rest_unauthorized(error_response: Option) -> EmbedError { - Self { kind: EmbedErrorKind::RestUnauthorized(error_response), fault: FaultSource::User } + pub(crate) fn rest_unauthorized( + error_response: Option, + configuration_source: ConfigurationSource, + ) -> EmbedError { + Self { + kind: EmbedErrorKind::RestUnauthorized(error_response, configuration_source), + fault: FaultSource::User, + } } pub(crate) fn rest_too_many_requests(error_response: Option) -> EmbedError { diff --git a/milli/src/vector/rest.rs b/milli/src/vector/rest.rs index 593d2b509..2538f2fff 100644 --- a/milli/src/vector/rest.rs +++ b/milli/src/vector/rest.rs @@ -275,7 +275,10 @@ fn check_response( Err(ureq::Error::Status(code, response)) => { let error_response: Option = response.into_string().ok(); Err(match code { - 401 => Retry::give_up(EmbedError::rest_unauthorized(error_response)), + 401 => Retry::give_up(EmbedError::rest_unauthorized( + error_response, + configuration_source, + )), 429 => Retry::rate_limited(EmbedError::rest_too_many_requests(error_response)), 400 => Retry::give_up(EmbedError::rest_bad_request( error_response,