Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(rust): parse the settings contract through Python so the bridge keeps to the interop boundary

Yujong Lee988676a0b813
diff --git a/litellm-rust/crates/python-bridge/src/python_settings.rs b/litellm-rust/crates/python-bridge/src/python_settings.rs
index 0c6554f0970..c5f9f309615 100644
--- a/litellm-rust/crates/python-bridge/src/python_settings.rs
+++ b/litellm-rust/crates/python-bridge/src/python_settings.rs
@@ -33,16 +33,32 @@ pub(crate) const CONTRACT: &str = include_str!("../python_settings.json");
#[cfg(test)]
mod tests {
- use std::collections::BTreeSet;
+ use std::{collections::BTreeSet, ffi::CString};
+
+ use pyo3::{prelude::*, types::PyDict};
use super::{CONTRACT, PythonSettings};
#[test]
fn every_settings_group_is_in_the_python_contract() {
- let contract: serde_json::Map<String, serde_json::Value> =
- serde_json::from_str(CONTRACT).unwrap();
- let declared: BTreeSet<&str> = contract.keys().map(String::as_str).collect();
- let read: BTreeSet<&str> = PythonSettings::ALL.map(PythonSettings::name).into();
- assert_eq!(read, declared);
+ Python::initialize();
+ Python::attach(|py| {
+ let locals = PyDict::new(py);
+ locals.set_item("contract", CONTRACT).unwrap();
+ let source = CString::new("import json\nkeys = list(json.loads(contract))").unwrap();
+ py.run(&source, Some(&locals), Some(&locals)).unwrap();
+ let declared: BTreeSet<String> = locals
+ .get_item("keys")
+ .unwrap()
+ .unwrap()
+ .extract::<Vec<String>>()
+ .unwrap()
+ .into_iter()
+ .collect();
+ let read: BTreeSet<String> = PythonSettings::ALL
+ .map(|group| group.name().to_owned())
+ .into();
+ assert_eq!(read, declared);
+ });
}
}