spark-adapters
Hardware abstraction adapters for local AI accelerators
Brought by drakestapleton
spark-adapters / src / lib.rs
| 1 | pub mod distill; |
| 2 | pub mod models; |
| 3 | pub mod providers; |
| 4 | pub mod router; |
| 5 | pub mod vault; |
| 6 | pub mod verifier; |
| 7 | |
| 8 | pub use distill::DistillationEngine; |
| 9 | pub use models::*; |
| 10 | pub use router::AdapterRouter; |
| 11 | pub use vault::*; |
| 12 | pub use verifier::Verifier; |
| 13 | |
| 14 | #[cfg(test)] |
| 15 | mod tests { |
| 16 | use super::*; |
| 17 | |
| 18 | #[test] |
| 19 | fn test_catalog_discovery() { |
| 20 | let router = AdapterRouter::new(); |
| 21 | let adapters = router.discover_adapters(); |
| 22 | assert!(!adapters.is_empty()); |
| 23 | assert!(adapters.iter().any(|a| a.id == "atlas-lightning-omni")); |
| 24 | assert!(adapters.iter().any(|a| a.id == "openai/gpt-4o")); |
| 25 | assert!(adapters.iter().any(|a| a.id == "anthropic/claude-3-7-sonnet")); |
| 26 | } |
| 27 | |
| 28 | #[test] |
| 29 | fn test_router_resolution() { |
| 30 | let router = AdapterRouter::new(); |
| 31 | let (prov, endpoint, model, _) = router.resolve_route("anthropic/claude-3-7-sonnet"); |
| 32 | assert_eq!(prov, ProviderType::Anthropic); |
| 33 | assert!(endpoint.contains("anthropic")); |
| 34 | assert_eq!(model, "claude-3-7-sonnet-20250219"); |
| 35 | |
| 36 | let (prov, _endpoint, model, _) = router.resolve_route("openai/o3-mini"); |
| 37 | assert_eq!(prov, ProviderType::OpenAI); |
| 38 | assert_eq!(model, "o3-mini"); |
| 39 | } |
| 40 | |
| 41 | #[test] |
| 42 | fn test_unslop_verification() { |
| 43 | let clean = "Implementation verified with zero allocations."; |
| 44 | let out = Verifier::verify(clean, VerificationStrategy::UnslopStrict); |
| 45 | assert!(out.passed); |
| 46 | assert_eq!(out.score, 1.0); |
| 47 | |
| 48 | let dirty = "We will delve into this crucial topic."; |
| 49 | let out_dirty = Verifier::verify(dirty, VerificationStrategy::UnslopStrict); |
| 50 | assert!(!out_dirty.rule_violations.is_empty()); |
| 51 | assert!(out_dirty.score < 1.0); |
| 52 | } |
| 53 | |
| 54 | #[test] |
| 55 | fn test_distill_task_serialization() { |
| 56 | let task = DistillTask { |
| 57 | id: "task-001".to_string(), |
| 58 | task_type: TaskType::CodeSynthesis, |
| 59 | prompt: "Write an Axum handler for health checks".to_string(), |
| 60 | system_prompt: Some("You are AIEN Sovereign Architect.".to_string()), |
| 61 | teacher_model: "anthropic/claude-3-7-sonnet".to_string(), |
| 62 | student_model: Some("atlas-lightning-omni".to_string()), |
| 63 | verification_strategy: VerificationStrategy::CompilerCheck, |
| 64 | commit_to_cortex: true, |
| 65 | }; |
| 66 | |
| 67 | let json_str = serde_json::to_string(&task).expect("serialize"); |
| 68 | let parsed: DistillTask = serde_json::from_str(&json_str).expect("deserialize"); |
| 69 | assert_eq!(parsed.id, "task-001"); |
| 70 | assert_eq!(parsed.teacher_model, "anthropic/claude-3-7-sonnet"); |
| 71 | } |
| 72 | |
| 73 | #[test] |
| 74 | fn test_verification_strategy_scoring() { |
| 75 | let code = "pub fn add(a: i32, b: i32) -> i32 { a + b }"; |
| 76 | let out = Verifier::verify(code, VerificationStrategy::CompilerCheck); |
| 77 | assert!(out.passed); |
| 78 | assert_eq!(out.score, 1.0); |
| 79 | assert!(out.compiler_output.is_some()); |
| 80 | } |
| 81 | } |