mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(rust-bridge): support traced OCR errors
This commit is contained in:
parent
fc7f15e9e3
commit
bfea249305
2 changed files with 21 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use litellm_core::error::Error;
|
||||
use pyo3::exceptions::{PyRuntimeError, PyValueError};
|
||||
use pyo3::prelude::*;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
pyo3::create_exception!(
|
||||
_native,
|
||||
|
|
@ -28,6 +29,21 @@ pub(crate) enum BridgeError {
|
|||
Host(PyErr),
|
||||
}
|
||||
|
||||
impl Display for BridgeError {
|
||||
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::InvalidArgument(message) | Self::Declined(message) | Self::Internal(message) => {
|
||||
formatter.write_str(message)
|
||||
}
|
||||
Self::Upstream { status, message } => match status {
|
||||
Some(status) => write!(formatter, "{status}: {message}"),
|
||||
None => formatter.write_str(message),
|
||||
},
|
||||
Self::Host(error) => Display::fmt(error, formatter),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BridgeError> for PyErr {
|
||||
fn from(error: BridgeError) -> Self {
|
||||
match error {
|
||||
|
|
|
|||
|
|
@ -134,6 +134,10 @@ fn prepare_ocr(
|
|||
})
|
||||
}
|
||||
|
||||
fn identity_bridge_error(error: BridgeError) -> BridgeError {
|
||||
error
|
||||
}
|
||||
|
||||
bridge_route! {
|
||||
sync = ocr,
|
||||
asynchronous = aocr,
|
||||
|
|
@ -159,7 +163,7 @@ bridge_route! {
|
|||
call_completion: Option<Py<PyAny>>,
|
||||
},
|
||||
prepare = prepare_ocr,
|
||||
errors = std::convert::identity,
|
||||
errors = identity_bridge_error,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue