mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-30 01:08:33 +00:00
* feat(gateway): connect to Redis from config.yaml * feat(config): own Redis settings resolution * fix(config): preserve Redis input precedence and presence * fix(config): box Redis cache settings * fix(gateway): preserve borrowed redis namespace --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
57 lines
1.3 KiB
Rust
57 lines
1.3 KiB
Rust
use std::{collections::BTreeMap, fmt, ops::Deref};
|
|
|
|
use serde::{Deserialize, Deserializer};
|
|
|
|
pub type Value = serde_yaml_ng::Value;
|
|
pub type AdditionalFields = BTreeMap<String, Value>;
|
|
|
|
#[derive(Clone, Default, Deserialize)]
|
|
#[serde(transparent)]
|
|
pub struct Object(BTreeMap<String, Value>);
|
|
|
|
impl Object {
|
|
pub(crate) fn from_fields(fields: BTreeMap<String, Value>) -> Self {
|
|
Self(fields)
|
|
}
|
|
|
|
pub fn get(&self, key: &str) -> Option<&Value> {
|
|
self.0.get(key)
|
|
}
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
self.0.is_empty()
|
|
}
|
|
|
|
pub fn len(&self) -> usize {
|
|
self.0.len()
|
|
}
|
|
}
|
|
|
|
impl Deref for Object {
|
|
type Target = BTreeMap<String, Value>;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl fmt::Debug for Object {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
formatter
|
|
.debug_struct("Object")
|
|
.field("keys", &self.0.keys())
|
|
.finish()
|
|
}
|
|
}
|
|
|
|
/// Python's callback shorthand: one entry or a list of them, kept as the values written.
|
|
pub(crate) fn one_or_many<'de, D: Deserializer<'de>>(
|
|
deserializer: D,
|
|
) -> Result<Option<Vec<Value>>, D::Error> {
|
|
Ok(
|
|
Option::<Value>::deserialize(deserializer)?.map(|value| match value {
|
|
Value::Sequence(values) => values,
|
|
one => vec![one],
|
|
}),
|
|
)
|
|
}
|