mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
fix(secrets): keep bridge JSON interop centralized
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
e6980ed358
commit
70a29d9170
4 changed files with 13 additions and 8 deletions
|
|
@ -28,7 +28,7 @@ pub use fork_gate::RuntimeAlreadyStarted;
|
|||
pub use gil::{release_count, release_gil};
|
||||
pub use handle::{Execution, ExecutionBody, ExecutionStep};
|
||||
pub use marshal::{
|
||||
Pythonized, from_py, from_py_argument, json_object_field, panic_to_pyerr, to_py,
|
||||
Pythonized, from_py, from_py_argument, json_loads, json_object_field, panic_to_pyerr, to_py,
|
||||
};
|
||||
|
||||
/// Starts the interpreter and imports the standard modules the tests share, once, so
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use std::panic::{AssertUnwindSafe, catch_unwind};
|
|||
use pyo3::exceptions::PyValueError;
|
||||
use pyo3::panic::PanicException;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyBytes;
|
||||
use serde::Serialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
|
|
@ -39,6 +40,12 @@ pub fn json_object_field(py: Python<'_>, document: &str, name: &str) -> PyResult
|
|||
.map(Bound::unbind)
|
||||
}
|
||||
|
||||
pub fn json_loads(py: Python<'_>, document: &[u8]) -> PyResult<Py<PyAny>> {
|
||||
py.import("json")?
|
||||
.call_method1("loads", (PyBytes::new(py, document),))
|
||||
.map(Bound::unbind)
|
||||
}
|
||||
|
||||
pub struct Pythonized<T>(pub T);
|
||||
|
||||
impl<'py, T> IntoPyObject<'py> for Pythonized<T>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use super::operations::{PythonMutationError, PythonMutationResponse};
|
||||
use litellm_host_python::to_py;
|
||||
use litellm_host_python::{json_loads, to_py};
|
||||
use litellm_secrets::cyberark;
|
||||
use pyo3::{exceptions::PyValueError, prelude::*, types::PyDict};
|
||||
|
||||
|
|
@ -85,9 +85,7 @@ fn os_error_code(error: &(dyn std::error::Error + 'static)) -> Option<i32> {
|
|||
}
|
||||
|
||||
pub(super) fn json_value(py: Python<'_>, body: &[u8]) -> PyResult<Py<PyAny>> {
|
||||
py.import("json")?
|
||||
.call_method1("loads", (pyo3::types::PyBytes::new(py, body),))
|
||||
.map(Bound::unbind)
|
||||
json_loads(py, body)
|
||||
}
|
||||
|
||||
pub(super) fn error_value(py: Python<'_>, message: String) -> PyResult<Py<PyAny>> {
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ pub(crate) async fn rotate(
|
|||
let status = raw_object_field(parsed, "status")
|
||||
.ok()
|
||||
.flatten()
|
||||
.and_then(|value| serde_json::from_str::<String>(value.get()).ok());
|
||||
.and_then(|value| serde_json::from_slice::<String>(value.get().as_bytes()).ok());
|
||||
if status.as_deref() == Some("error") {
|
||||
return Ok(response);
|
||||
}
|
||||
|
|
@ -134,7 +134,7 @@ pub(crate) async fn rotate(
|
|||
let actual = verification_value(parsed, data_key).map_err(|failure| {
|
||||
Failure::from(failure).during(FailureStage::Replacement(new_name.to_owned()))
|
||||
})?;
|
||||
let actual_string = serde_json::from_str::<String>(actual.get()).ok();
|
||||
let actual_string = serde_json::from_slice::<String>(actual.get().as_bytes()).ok();
|
||||
if actual_string.as_deref() != Some(value.expose()) {
|
||||
return Err(FailureKind::ValueMismatch {
|
||||
expected: value.clone(),
|
||||
|
|
@ -162,7 +162,7 @@ fn raw_object_field<'a>(
|
|||
document: &'a RawValue,
|
||||
key: &str,
|
||||
) -> Result<Option<&'a RawValue>, FailureKind> {
|
||||
let object: HashMap<String, &RawValue> = serde_json::from_str(document.get())
|
||||
let object: HashMap<String, &RawValue> = serde_json::from_slice(document.get().as_bytes())
|
||||
.map_err(|_| FailureKind::MissingGet(document.get().as_bytes().to_vec()))?;
|
||||
Ok(object.get(key).copied())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue