Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-local-stack/blob/main/src/lib.rs # aien-local-stack aien-dev/aien-local-stack Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-local-stack / src / lib.rs` 111 lines ยท 3667 bytes Raw Blame History 1 pub mod recipe; 2 pub mod sovereign_service; 3 4 pub use recipe::{ContextRecipe, RecipeStore, SharedRecipeStore}; 5 pub use sovereign_service::{BranchState, SovereignInferenceService}; 6 7 use aegis::inference::ProtocolInferenceBackend; 8 use std::sync::Arc; 9 10 pub struct LocalStack { 11 pub inference_service: Arc, 12 pub protocol_backend: Arc, 13 pub recipe_store: Arc, 14 } 15 16 impl LocalStack { 17 pub fn new() -> Result { 18 let sovereign = Arc::new(SovereignInferenceService::new_default()?); 19 let backend = Arc::new(ProtocolInferenceBackend::new( 20 sovereign.clone(), 21 "sovereign-embedded-model".to_string(), 22 )); 23 let recipe_store = Arc::new(RecipeStore::new()); 24 25 Ok(Self { 26 inference_service: sovereign, 27 protocol_backend: backend, 28 recipe_store, 29 }) 30 } 31 } 32 33 #[cfg(test)] 34 mod tests { 35 use super::*; 36 use aien_inference_protocol::*; 37 38 #[tokio::test] 39 async fn test_local_stack_in_process_composition() { 40 let stack = LocalStack::new().expect("Failed to initialize LocalStack"); 41 let caps = stack.inference_service.get_capabilities().await.unwrap(); 42 assert!(caps.context_branching); 43 assert!(caps.physical_cow); 44 45 let req = InferenceRequest { 46 request_id: uuid::Uuid::new_v4(), 47 model: "sovereign-embedded-model".to_string(), 48 messages: vec![InferenceMessage { 49 role: "user".to_string(), 50 content: "ping".to_string(), 51 }], 52 context: None, 53 max_tokens: 4, 54 temperature: 0.0, 55 stop_sequences: vec![], 56 }; 57 58 let res = stack.inference_service.infer(req).await.unwrap(); 59 assert_eq!(res.finish_reason, "stop"); 60 assert!(res.completion_tokens > 0); 61 } 62 63 #[tokio::test] 64 async fn test_local_stack_branch_and_cow() { 65 let stack = LocalStack::new().expect("Failed to initialize LocalStack"); 66 67 let prompt: Vec = (1..=32).collect(); 68 let recipe = ContextRecipe::new(prompt.clone()); 69 stack.recipe_store.insert(recipe.clone()).unwrap(); 70 71 let (_root_h, parent_ctx) = stack 72 .inference_service 73 .create_root_context(&prompt, &recipe) 74 .expect("create root context"); 75 76 let branch_req = BranchContextRequest { 77 operation_id: uuid::Uuid::new_v4(), 78 parent_context: parent_ctx.clone(), 79 child_branch_id: BranchId::new_v4(), 80 isolation: parent_ctx.isolation, 81 }; 82 83 let receipt = stack 84 .inference_service 85 .branch_context(branch_req) 86 .await 87 .unwrap(); 88 assert!(receipt.shared_pages > 0); 89 assert_eq!(receipt.copied_pages, 0); 90 91 let infer_req = InferenceRequest { 92 request_id: uuid::Uuid::new_v4(), 93 model: "sovereign-embedded-model".to_string(), 94 messages: vec![InferenceMessage { 95 role: "user".to_string(), 96 content: "step".to_string(), 97 }], 98 context: Some(receipt.child_context), 99 max_tokens: 2, 100 temperature: 0.0, 101 stop_sequences: vec![], 102 }; 103 104 let res = stack.inference_service.infer(infer_req).await.unwrap(); 105 assert_eq!(res.completion_tokens, 2); 106 assert!(res.context.is_some()); 107 let ctx = res.context.unwrap(); 108 assert_eq!(ctx.generation, Generation(3)); // 1 root -> 2 fork -> 3 after step 109 assert!(ctx.token_count > 32); 110 } 111 }