Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.
Rust
feat(runner): load deployment from TOML source (#545)
Bryan Bednarskif9cde3c42191
diff --git a/crates/switchyard-runner/src/config.rs b/crates/switchyard-runner/src/config.rsindex 7a90c7bba..74428895b 100644--- a/crates/switchyard-runner/src/config.rs+++ b/crates/switchyard-runner/src/config.rs@@ -43,7 +43,7 @@ pub(crate) fn load_runner(path: impl AsRef<Path>) -> RunnerResult<Runner> {})}-fn runner_from_toml(source: &str) -> RunnerResult<Runner> {+pub(crate) fn runner_from_toml(source: &str) -> RunnerResult<Runner> {let config: DeploymentConfig = toml::from_str(source).map_err(|error| {RunnerError::configuration_source(format!("failed to parse TOML: {error}"), error)})?;@@ -584,6 +584,15 @@ type = "passthrough"target = "weak""#;+ #[test]+ fn public_runner_from_toml_builds_a_deployment() -> RunnerResult<()> {+ let runner = Runner::from_toml(VALID_CONFIG)?;++ assert!(runner.route("switchyard/classifier").is_some());+ assert!(runner.route("switchyard/passthrough").is_some());+ Ok(())+ }+fn error_message(toml: &str) -> String {match runner_from_toml(toml) {Ok(_) => "configuration unexpectedly succeeded".to_string(),diff --git a/crates/switchyard-runner/src/runner.rs b/crates/switchyard-runner/src/runner.rsindex 55760f3a3..93dce5e76 100644--- a/crates/switchyard-runner/src/runner.rs+++ b/crates/switchyard-runner/src/runner.rs@@ -47,6 +47,13 @@ impl Runner {config::load_runner(path)}+ /// Loads and validates a version-1 deployment TOML document.+ ///+ /// Use [`Self::load`] when the deployment is stored in a file.+ pub fn from_toml(source: &str) -> Result<Self, RunnerError> {+ config::runner_from_toml(source)+ }+/// Builds a runner from named routes in caller-provided order./// Pre-condition: There must be at least one route.pub fn new(routes: Vec<(ModelId, Route)>) -> Self {