use crate::common::MockProvider; use kernelx_core::prelude::*; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; mod common; #[derive(Debug, Serialize, Deserialize, JsonSchema)] struct JokeResponse { setup: String, punchline: String, genre: String, } #[tokio::test] async fn test_lmp_basic() { provider! { MockProvider, api_base: "http://mock.test", api_key: "test-key", models: models!["mock-model" => [Capability::Chat, Capability::Complete]] } /// You are a helpful assistant. #[lmp(model = "mock-model")] async fn basic_completion(input: &str) -> Result { format!("Echo: {}", input) } let result = basic_completion("test").await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "Mock completion response"); } #[tokio::test] async fn test_lmp_structured() { provider! { MockProvider, api_base: "http://mock.test", api_key: "test-key", models: models!["mock-model" => [Capability::Chat, Capability::Complete, Capability::Structured]] } /// You are a comedian. #[lmp(model = "mock-model", response_format = JokeResponse)] async fn tell_joke(topic: &str) -> Result { format!("Tell me a joke about {}", topic) } let result = tell_joke("programming").await; assert!(result.is_ok()); let joke = result.unwrap(); assert_eq!(joke.setup, "Why did the mock cross the road?"); assert_eq!(joke.punchline, "To test the other side!"); assert_eq!(joke.genre, "Programming Humor"); }