use crate::{InvokeError, PythonOwned}; use litellm_host::protocol::Protocol; use pyo3::prelude::*; use pyo3::types::PyDict; /// Converts requests, responses, stream values and errors at the Python boundary. pub trait PythonBinding: PythonOwned { type Protocol: Protocol; /// The public exception a native failure maps to, kept as a value until the driver /// raises it. type Failure: Into; /// Decodes the keyword view returned by `prepare_arguments`, including preflight rewrites. fn decode_request( &mut self, py: Python<'_>, arguments: &Bound<'_, PyDict>, ) -> Result< ::Request, InvokeError<::Error>, >; fn encode_response( &mut self, py: Python<'_>, response: ::Response, ) -> PyResult>; /// What the stream carries at hand-off, as the caller's stream receives it. fn encode_stream_head( &mut self, py: Python<'_>, head: ::StreamHead, ) -> PyResult>; /// One streamed chunk as the caller receives it. fn encode_chunk( &mut self, py: Python<'_>, chunk: ::Chunk, ) -> PyResult>; fn map_error( &self, py: Python<'_>, error: ::Error, ) -> PyResult; fn host_error(error: &PyErr) -> ::Error; }