fix: propagate completions error events to stream
This commit is contained in:
parent
9a5cc08c76
commit
85701eac32
|
@ -848,7 +848,14 @@ async fn completions(
|
||||||
|
|
||||||
yield Ok(event);
|
yield Ok(event);
|
||||||
}
|
}
|
||||||
Err(err) => yield Ok(Event::from(err)),
|
Err(err) => {
|
||||||
|
let error_event: ErrorEvent = err.into();
|
||||||
|
let event = Event::default().json_data(error_event).unwrap_or_else(|e| {
|
||||||
|
InferError::StreamSerializationError(e.to_string()).into()
|
||||||
|
});
|
||||||
|
yield Ok::<Event, Infallible>(event);
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2516,20 +2523,22 @@ impl From<InferError> for Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
pub struct ErrorWithMessage {
|
pub struct APIError {
|
||||||
message: String,
|
message: String,
|
||||||
|
http_status_code: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
pub struct ErrorEvent {
|
pub struct ErrorEvent {
|
||||||
error: ErrorWithMessage,
|
error: APIError,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<InferError> for ErrorEvent {
|
impl From<InferError> for ErrorEvent {
|
||||||
fn from(err: InferError) -> Self {
|
fn from(err: InferError) -> Self {
|
||||||
ErrorEvent {
|
ErrorEvent {
|
||||||
error: ErrorWithMessage {
|
error: APIError {
|
||||||
message: err.to_string(),
|
message: err.to_string(),
|
||||||
|
http_status_code: 500,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue