mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-15 04:19:08 +00:00
* refactor(rust): extract litellm-host-native as the shared Rust host driver Move service and hook dispatch out of host-http into a Driver that owns the machine and Rust handlers, returning at completion or a stream boundary and holding the demand reply until the consumer advances. Move the in-process runner onto the same driver. host-http now layers encoding, SSE, body polling and lifecycle observation over it. host-python keeps driving litellm-host directly Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(rust): interrupt the machine when the in-process stream consumer fails Restores the pre-refactor interruption path for StreamConsumer errors via Driver::fail and ports the generic run lifecycle tests into host-native. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(rust): separate the machine contract from coroutine execution * auth update * refactor(rust): use standard flow control for host requests * style(rust): keep host driver imports formatted * chores * mostly relocation * refactor(rust): separate interceptors from queued observers * refactor(rust): centralize legacy callback mappings and lifecycle * docs: define Python host boundaries and migration plan * refactor: enforce Python host and bridge boundaries * refactor(rust): separate operations from callback composition * refactor(rust): compose SDK policy through call hooks --------- Co-authored-by: Yujong Lee <yujong@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
mod chain;
|
|
pub use chain::HookChain;
|
|
|
|
use crate::PythonOwned;
|
|
use litellm_host::hooks::{CallHooks, HookRuntime, RuntimeCallEvent};
|
|
use pyo3::prelude::*;
|
|
use pyo3::types::PyDict;
|
|
|
|
/// What a hook step produced: either the value the driver asked for, or a Python
|
|
/// awaitable the driver hands back to the caller's task before asking again.
|
|
pub type HookResume<L, T> = fn(&mut L, Python<'_>, PyResult<Py<PyAny>>) -> PyResult<HookStep<L, T>>;
|
|
|
|
pub enum HookStep<L, T> {
|
|
Await(Py<PyAny>, HookResume<L, T>),
|
|
Ready(T),
|
|
}
|
|
|
|
pub struct PythonRuntime;
|
|
|
|
impl HookRuntime for PythonRuntime {
|
|
type Context<'a> = Python<'a>;
|
|
type Arguments = Py<PyDict>;
|
|
type Response = Py<PyAny>;
|
|
type Chunk = Py<PyAny>;
|
|
type Error = PyErr;
|
|
type Step<H, T> = HookStep<H, T>;
|
|
|
|
fn ready<H, T>(value: T) -> Self::Step<H, T> {
|
|
HookStep::Ready(value)
|
|
}
|
|
}
|
|
|
|
pub type PythonCallEvent<'a> = RuntimeCallEvent<'a, PythonRuntime>;
|
|
|
|
pub trait PythonCallHooks: CallHooks<PythonRuntime> + PythonOwned {}
|
|
|
|
impl<H: CallHooks<PythonRuntime> + PythonOwned> PythonCallHooks for H {}
|