mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-29 01:03:17 +00:00
Some checks are pending
CI Coverage / assert-ci-coverage (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
CodSpeed Benchmarks / benchmarks (push) Waiting to run
Helm unit test / unit-test (push) Waiting to run
Publish basedpyright base counts / publish (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Code Quality Checks / code-quality (push) Waiting to run
Code Quality Checks / python-310-import-smoke (push) Waiting to run
UI Unit Tests / ui-unit-tests (push) Waiting to run
Postgres Tests / proxy-security (push) Waiting to run
Postgres Tests / schema-migration (push) Waiting to run
Postgres Tests / proxy-behavior (push) Waiting to run
LiteLLM Rust / rust-lint (push) Waiting to run
LiteLLM Rust / rust-test (push) Waiting to run
LiteLLM Rust / rust-wheel (push) Waiting to run
Unit Tests: Documentation Validation / documentation (push) Waiting to run
Unit Tests: Proxy DB Operations / custom-logging (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / db-and-spend (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / assert-shard-coverage (push) Waiting to run
Unit Tests: Proxy DB Operations / auth-checks (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / budgets (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / endpoints-and-responses (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / guardrails-hooks (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / jwt-and-keys (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / key-generation (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / logging-misc (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / proxy-runtime (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / proxy-server-core (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / proxy-utils (push) Blocked by required conditions
Unit Tests / proxy-endpoints (push) Waiting to run
Unit Tests / caching-local (push) Waiting to run
Unit Tests / core-utils (push) Waiting to run
Unit Tests / enterprise-package (push) Waiting to run
Unit Tests / enterprise-routing (push) Waiting to run
Unit Tests / integrations (push) Waiting to run
Unit Tests / All Other Providers (push) Waiting to run
Unit Tests / Vertex AI (push) Waiting to run
Unit Tests / mcp-integration (push) Waiting to run
Unit Tests / misc (push) Waiting to run
Unit Tests / proxy-auth (push) Waiting to run
Unit Tests / proxy-extras (push) Waiting to run
Unit Tests / proxy-infra (push) Waiting to run
Unit Tests / proxy-server (push) Waiting to run
Unit Tests / responses-caching-types (push) Waiting to run
GitHub Actions Security Analysis / zizmor (push) Waiting to run
The legacy callback crate carried two rewrites that have nothing to do with the Logging contract: litellm_credential_name inheritance and the max_budget and num_retries_per_request checks. Any later callback host would need them unchanged, which is the smell the crate's AGENTS.md now names. They are now a Preflight the driver in litellm-host-python runs on the keyword view begin returned, before the host projects from it, supplied by python-bridge and passed through run_legacy_call. The call order is unchanged (setup, deployment hook, credentials, limits) and a rejection still fails the call as a host failure, so the failure callbacks run as before. The preflight rewrites the adapter's own copy in place, so no extra dict copy and no new lifecycle method Co-authored-by: Yujong Lee <yujong@berri.ai> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
128 lines
4.2 KiB
Rust
128 lines
4.2 KiB
Rust
mod cache;
|
|
mod coercion;
|
|
mod credentials;
|
|
mod diagnostics;
|
|
mod errors;
|
|
mod http;
|
|
mod logger;
|
|
mod marshal;
|
|
mod preflight;
|
|
mod python_settings;
|
|
mod routes;
|
|
mod secrets;
|
|
mod tokenizer;
|
|
|
|
#[pymodule(gil_used = true)]
|
|
mod _native {
|
|
use crate::cache::{CacheResolver, CacheTestHandle, ResolvedCache};
|
|
#[cfg(feature = "panic-test")]
|
|
#[pymodule_export]
|
|
use crate::diagnostics::_panic_for_test;
|
|
#[pymodule_export]
|
|
use crate::diagnostics::{gil_stats, process_state_started, reserve_process_for_forking};
|
|
#[pymodule_export]
|
|
use crate::errors::{RustBridgeDeclined, RustUpstreamError};
|
|
#[pymodule_export]
|
|
use crate::logger::NativeDiagnosticProcessor;
|
|
#[pymodule_export]
|
|
use crate::routes::audio_transcription::{atranscription, transcription};
|
|
#[pymodule_export]
|
|
use crate::routes::chat_completions::{
|
|
achat_completions, acompletion, chat_completions, chat_completions_decline, completion,
|
|
};
|
|
#[pymodule_export]
|
|
use crate::routes::embeddings::{aembedding, embedding};
|
|
#[pymodule_export]
|
|
use crate::routes::messages::{amessages, messages};
|
|
#[pymodule_export]
|
|
use crate::routes::ocr::{aocr, ocr, ocr_health_check_document, ocr_passthrough_response};
|
|
#[pymodule_export]
|
|
use crate::routes::responses::{ResponsesWebSocketConnection, aresponses, responses};
|
|
#[pymodule_export]
|
|
use crate::routes::token_counter::TokenCounter;
|
|
#[cfg(feature = "huggingface")]
|
|
#[pymodule_export]
|
|
use crate::tokenizer::HuggingFaceEncoding;
|
|
#[pymodule_export]
|
|
use crate::tokenizer::Tokenizer;
|
|
#[pymodule_export]
|
|
use litellm_host_python::{ForkedAfterNativeRuntimeStarted, ProcessReservedForForking};
|
|
use pyo3::{prelude::*, types::PyModule};
|
|
|
|
#[pymodule_init]
|
|
fn init(module: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
let py = module.py();
|
|
let dict = module.dict();
|
|
dict.set_item("_CacheTestHandle", py.get_type::<CacheTestHandle>())?;
|
|
dict.set_item("_CacheResolver", py.get_type::<CacheResolver>())?;
|
|
dict.set_item("_CacheTestResolver", py.get_type::<CacheResolver>())?;
|
|
dict.set_item("_ResponseCacheRuntime", py.get_type::<ResolvedCache>())?;
|
|
dict.set_item(
|
|
"_SecretManagerRuntime",
|
|
py.get_type::<crate::secrets::runtime::NativeSecretManager>(),
|
|
)
|
|
}
|
|
}
|
|
|
|
use pyo3::prelude::*;
|
|
|
|
#[cfg(test)]
|
|
pub(crate) fn native_module(py: Python<'_>) -> Bound<'_, PyModule> {
|
|
pyo3::wrap_pymodule!(_native)(py).into_bound(py)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn module_registration_preserves_the_public_surface() {
|
|
Python::initialize();
|
|
Python::attach(|py| {
|
|
let mut expected = vec![
|
|
"RustBridgeDeclined",
|
|
"RustUpstreamError",
|
|
"ForkedAfterNativeRuntimeStarted",
|
|
"ProcessReservedForForking",
|
|
"ocr",
|
|
"aocr",
|
|
"ocr_health_check_document",
|
|
"ocr_passthrough_response",
|
|
"embedding",
|
|
"aembedding",
|
|
"transcription",
|
|
"atranscription",
|
|
"messages",
|
|
"amessages",
|
|
"chat_completions_decline",
|
|
"chat_completions",
|
|
"achat_completions",
|
|
"completion",
|
|
"acompletion",
|
|
"responses",
|
|
"aresponses",
|
|
"ResponsesWebSocketConnection",
|
|
"NativeDiagnosticProcessor",
|
|
"TokenCounter",
|
|
"Tokenizer",
|
|
"gil_stats",
|
|
"process_state_started",
|
|
"reserve_process_for_forking",
|
|
];
|
|
#[cfg(feature = "huggingface")]
|
|
expected.push("HuggingFaceEncoding");
|
|
expected.sort_unstable();
|
|
|
|
let mut public_names: Vec<String> = native_module(py)
|
|
.dict()
|
|
.keys()
|
|
.extract::<Vec<String>>()
|
|
.expect("module names should be strings")
|
|
.into_iter()
|
|
.filter(|name| !name.starts_with('_'))
|
|
.collect();
|
|
public_names.sort_unstable();
|
|
assert_eq!(public_names, expected);
|
|
});
|
|
}
|
|
}
|