mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-01 01:18:34 +00:00
42 lines
1.8 KiB
Rust
42 lines
1.8 KiB
Rust
//! Python data formats reproduced in Rust, for state that Python LiteLLM writes and reads.
|
|
//!
|
|
//! Each module mirrors one Python operation over plain data values, and its tests replay
|
|
//! fixtures generated by that operation in CPython (`scripts/generate_fixtures.py`):
|
|
//!
|
|
//! | Module | Python operation |
|
|
//! |---|---|
|
|
//! | [`literal`] | `ast.literal_eval(text)` |
|
|
//! | [`repr`] | `repr(value)` and `str(value)` |
|
|
//! | [`json`] | `json.dumps(value)`, and `json.loads(json.dumps(value))` as a JSON value |
|
|
//! | [`pickle`] | `pickle.loads(data)` and `pickle.dumps(value)` for plain data |
|
|
//! | [`truthy`] | `bool(value)` |
|
|
//! | [`number`] | `int(text)` and `float(text)` |
|
|
//!
|
|
//! [`Value`] is the closed data model these formats share. Live Python objects
|
|
//! (descriptors, `__bool__`, `__str__`, callbacks) are out of scope: those belong to the
|
|
//! PyO3 boundary in `litellm-python-bridge`, which runs the real protocol.
|
|
//!
|
|
//! Known limits, each pinned by a test:
|
|
//! - `set` iteration order follows Python's hash order, which this crate does not model
|
|
//! (string hashes are randomized per process). Sets keep their literal order.
|
|
//! - `str` values are Rust `String`s, so lone surrogates cannot be represented.
|
|
//! - [`pickle::loads`] decodes `tuple`, `set`, and `frozenset` as lists.
|
|
//! - [`number`] reads ASCII digits only, while Python's `int` and `float` accept any Unicode decimal digit.
|
|
|
|
mod error;
|
|
pub mod json;
|
|
pub mod literal;
|
|
pub mod number;
|
|
pub mod pickle;
|
|
pub mod repr;
|
|
pub mod truthy;
|
|
mod value;
|
|
|
|
pub use error::Error;
|
|
pub use num_bigint::BigInt;
|
|
pub use value::Value;
|
|
|
|
/// Nesting limit for the decoders, which recurse. It keeps untrusted persisted data from
|
|
/// overflowing the Rust stack, and is deliberately stricter than CPython, whose parser takes
|
|
/// about 200 nested brackets and whose unpickler has no limit.
|
|
pub const MAX_DEPTH: usize = 128;
|