use async_trait::async_trait; use kernelx_core::{models, prelude::*, Error}; use serde_json::Value; #[derive(Clone, Debug)] pub struct MockProvider { models: Vec, config: ModelConfig, } impl MockProvider { pub fn builder() -> ProviderBuilder { ProviderBuilder::new() } pub fn with_capabilities(capabilities: Vec) -> Result { Self::builder() .api_key("test-key") .models(vec![ModelInfo { id: "mock-model".to_string(), capabilities, }]) .build() } } impl Provider for MockProvider { fn models(&self) -> &[ModelInfo] { &self.models } fn from_builder(mut builder: ProviderBuilder) -> Result { if builder.get_api_key().is_none() { return Err(Error::Config("API key is required".into())); } Ok(Self { models: builder.take_models().unwrap_or_else(|| { models![ "mock-model" => [Capability::Chat, Capability::Complete, Capability::Structured] ] }), config: builder.take_config().unwrap_or_default(), }) } } impl HasCapability for MockProvider { fn model_id(&self) -> &str { "mock" } fn config(&self) -> &ModelConfig { &self.config } } #[async_trait] impl Chat for MockProvider { async fn chat_impl( &self, _model: &str, _messages: Vec, _config: &ModelConfig, ) -> Result { Ok("Mock chat response".to_string()) } } #[async_trait] impl Complete for MockProvider { async fn complete_impl( &self, _model: &str, _prompt: &str, _config: &ModelConfig, ) -> Result { Ok("Mock completion response".to_string()) } } #[async_trait] impl Structured for MockProvider { async fn structured_impl( &self, _model: &str, _prompt: &str, _schema: &Value, _config: &ModelConfig, ) -> Result { Ok(serde_json::json!({ "message": "Mock structured response", "confidence": 0.95, "tags": ["test", "mock", "structured"], "setup": "Why did the mock cross the road?", "punchline": "To test the other side!", "genre": "Programming Humor" })) } } // Helper functions for tests pub fn setup_mock_provider(capabilities: Vec) -> Result { MockProvider::with_capabilities(capabilities) } #[allow(dead_code)] pub fn setup_mock_llm() -> Result { setup_mock_provider(vec![Capability::Chat, Capability::Complete]) } #[allow(dead_code)] pub fn setup_mock_structured_llm() -> Result { setup_mock_provider(vec![ Capability::Chat, Capability::Complete, Capability::Structured, ]) } #[allow(dead_code)] pub fn setup_mock_provider_with_models(models: Vec) -> Result { MockProvider::builder() .api_key("test-key") .models(models) .build() } #[allow(dead_code)] pub fn create_model_info(id: &str, capabilities: Vec) -> ModelInfo { ModelInfo { id: id.to_string(), capabilities, } }