Skip to content

Commit

Permalink
fix(graphQL): use better err msg for openai api error (#3371)
Browse files Browse the repository at this point in the history
  • Loading branch information
zwpaper authored Nov 5, 2024
1 parent b6e28d1 commit 32373eb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ pub mod worker;
use std::{sync::Arc, time::Instant};

use access_policy::{AccessPolicyService, SourceIdAccessPolicy};
use async_openai::types::{
ChatCompletionRequestMessage, ChatCompletionRequestUserMessageArgs,
CreateChatCompletionRequestArgs,
use async_openai::{
error::OpenAIError,
types::{
ChatCompletionRequestMessage, ChatCompletionRequestUserMessageArgs,
CreateChatCompletionRequestArgs,
},
};
use auth::{
AuthenticationService, Invitation, RefreshTokenResponse, RegisterResponse, TokenAuthResponse,
Expand Down Expand Up @@ -165,6 +168,15 @@ pub enum TestModelConnectionError {
Other(#[from] CoreError),
}

impl From<OpenAIError> for TestModelConnectionError {
fn from(err: OpenAIError) -> Self {
match err {
OpenAIError::ApiError(e) => Self::FailedToConnect(e.message),
_ => Self::FailedToConnect(err.to_string()),
}
}
}

impl<S: ScalarValue> IntoFieldError<S> for TestModelConnectionError {
fn into_field_error(self) -> FieldError<S> {
match self {
Expand Down Expand Up @@ -763,7 +775,7 @@ impl Query {
Ok(_) => Ok(ModelBackendHealthInfo {
latency_ms: start.elapsed().as_millis() as i32,
}),
Err(e) => Err(TestModelConnectionError::FailedToConnect(e.to_string())),
Err(e) => Err(e.into()),
}
} else {
Err(TestModelConnectionError::NotEnabled)
Expand Down

0 comments on commit 32373eb

Please sign in to comment.