mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
refactor(python-bridge): derive NativeCall extraction (#45449)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f45407b4c3
commit
abee1c14e7
1 changed files with 4 additions and 12 deletions
|
|
@ -16,24 +16,16 @@ use pyo3::{
|
|||
types::{PyDict, PyMapping, PyTuple},
|
||||
};
|
||||
|
||||
#[derive(FromPyObject)]
|
||||
pub(crate) struct NativeCall<'py> {
|
||||
#[pyo3(attribute)]
|
||||
args: Bound<'py, PyTuple>,
|
||||
#[pyo3(attribute, from_py_with = mapping_dict)]
|
||||
kwargs: Bound<'py, PyDict>,
|
||||
#[pyo3(attribute, from_py_with = mapping_dict)]
|
||||
bound: Bound<'py, PyDict>,
|
||||
}
|
||||
|
||||
impl<'py> FromPyObject<'_, 'py> for NativeCall<'py> {
|
||||
type Error = PyErr;
|
||||
|
||||
fn extract(call: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
args: call.getattr("args")?.cast_into()?,
|
||||
kwargs: mapping_dict(&call.getattr("kwargs")?)?,
|
||||
bound: mapping_dict(&call.getattr("bound")?)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn mapping_dict<'py>(value: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyDict>> {
|
||||
if let Ok(dict) = value.cast::<PyDict>() {
|
||||
return Ok(dict.clone());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue