use siumai::error::LlmError;
use siumai::provider::SiumaiBuilder;
use siumai::types::CommonParams;
#[tokio::test]
async fn test_parameter_internal_verification() {
println!("🔍 Testing internal parameter verification");
let test_model = "test-model-internal";
let test_temperature = 0.75;
let test_max_tokens = 1200u32;
let test_top_p = 0.88;
let test_seed = 54321u64;
test_gemini_internal_parameters(
test_model,
test_temperature,
test_max_tokens,
test_top_p,
test_seed,
)
.await;
test_xai_internal_parameters(
test_model,
test_temperature,
test_max_tokens,
test_top_p,
test_seed,
)
.await;
println!("✅ Internal parameter verification completed");
}
async fn test_gemini_internal_parameters(
model: &str,
temperature: f32,
max_tokens: u32,
top_p: f32,
seed: u64,
) {
println!(" 🔍 Testing Gemini internal parameter access...");
let result = SiumaiBuilder::new()
.gemini()
.api_key("test-key-gemini-internal")
.model(model)
.temperature(temperature)
.max_tokens(max_tokens)
.top_p(top_p)
.seed(seed)
.build()
.await;
match result {
Ok(client) => {
println!(" ✅ Gemini client created successfully");
assert!(client.supports("chat"));
assert!(client.supports("streaming"));
println!(" ✅ Gemini client supports expected capabilities");
}
Err(e) => {
println!(" ✅ Gemini client failed as expected: {}", e);
}
}
}
async fn test_xai_internal_parameters(
model: &str,
temperature: f32,
max_tokens: u32,
top_p: f32,
seed: u64,
) {
println!(" 🔍 Testing xAI internal parameter access...");
let result = SiumaiBuilder::new()
.xai()
.api_key("test-key-xai-internal")
.model(model)
.temperature(temperature)
.max_tokens(max_tokens)
.top_p(top_p)
.seed(seed)
.build()
.await;
match result {
Ok(client) => {
println!(" ✅ xAI client created successfully");
assert!(client.supports("chat"));
assert!(client.supports("streaming"));
println!(" ✅ xAI client supports expected capabilities");
}
Err(e) => {
println!(" ✅ xAI client failed as expected: {}", e);
}
}
}
#[tokio::test]
async fn test_parameter_consistency_across_builds() {
println!("🔍 Testing parameter consistency across multiple builds");
let test_params = [
("model-1", 0.1, 100u32, 0.1, 1u64),
("model-2", 0.5, 500u32, 0.5, 2u64),
("model-3", 0.9, 900u32, 0.9, 3u64),
("model-4", 1.5, 1500u32, 1.0, 4u64),
("model-5", 2.0, 2000u32, 1.0, 5u64),
];
for (i, (model, temperature, max_tokens, top_p, seed)) in test_params.iter().enumerate() {
println!(" 🔍 Testing parameter set {} with model: {}", i + 1, model);
let result = SiumaiBuilder::new()
.openai()
.api_key("test-key")
.model(*model)
.temperature(*temperature)
.max_tokens(*max_tokens)
.top_p(*top_p)
.seed(*seed)
.build()
.await;
match result {
Ok(client) => {
println!(" ✅ Client {} created successfully", i + 1);
assert!(client.supports("chat"));
}
Err(e) => match e {
LlmError::ConfigurationError(msg) if msg.contains("parameter") => {
panic!(
" ❌ Parameter configuration error for set {}: {}",
i + 1,
msg
);
}
_ => {
println!(" ✅ Client {} failed with expected error: {}", i + 1, e);
}
},
}
}
}
#[tokio::test]
async fn test_default_parameter_handling() {
println!("🔍 Testing default parameter handling");
println!(" 🔍 Testing minimal parameter configuration...");
let result = SiumaiBuilder::new()
.openai()
.api_key("test-key")
.model("gpt-4")
.build()
.await;
match result {
Ok(client) => {
println!(" ✅ Client created with minimal parameters");
assert!(client.supports("chat"));
}
Err(e) => match e {
LlmError::ConfigurationError(msg) if msg.contains("parameter") => {
panic!(" ❌ Minimal parameter configuration error: {}", msg);
}
_ => {
println!(" ✅ Minimal config failed with expected error: {}", e);
}
},
}
println!(" 🔍 Testing explicit default parameter values...");
let result = SiumaiBuilder::new()
.anthropic()
.api_key("test-key")
.model("claude-3-sonnet")
.build()
.await;
match result {
Ok(client) => {
println!(" ✅ Client created with explicit defaults");
assert!(client.supports("chat"));
}
Err(e) => match e {
LlmError::ConfigurationError(msg) if msg.contains("parameter") => {
panic!(" ❌ Default parameter configuration error: {}", msg);
}
_ => {
println!(" ✅ Default config failed with expected error: {}", e);
}
},
}
}
#[tokio::test]
async fn test_parameter_override_behavior() {
println!("🔍 Testing parameter override behavior");
println!(" 🔍 Testing parameter override...");
let result = SiumaiBuilder::new()
.gemini()
.api_key("test-key")
.model("gemini-1.0") .temperature(0.1) .model("gemini-2.0") .temperature(0.9) .max_tokens(100) .max_tokens(2000) .build()
.await;
match result {
Ok(client) => {
println!(" ✅ Client created with overridden parameters");
assert!(client.supports("chat"));
}
Err(e) => match e {
LlmError::ConfigurationError(msg) if msg.contains("parameter") => {
panic!(" ❌ Parameter override configuration error: {}", msg);
}
_ => {
println!(" ✅ Override config failed with expected error: {}", e);
}
},
}
}
#[tokio::test]
async fn test_parameter_validation_during_build() {
println!("🔍 Testing parameter validation during build");
println!(" 🔍 Testing build-time validation...");
let builder = SiumaiBuilder::new()
.ollama()
.api_key("test-key")
.model("test-model")
.temperature(0.5)
.max_tokens(1000);
println!(" ✅ Builder created with parameters (no validation yet)");
let result = builder.build().await;
match result {
Ok(client) => {
println!(" ✅ Client built successfully");
assert!(client.supports("chat"));
}
Err(e) => match e {
LlmError::ConfigurationError(msg) if msg.contains("parameter") => {
println!(
" ✅ Parameter validation correctly occurred at build time: {}",
msg
);
}
_ => {
println!(" ✅ Build failed with expected error: {}", e);
}
},
}
}
#[tokio::test]
async fn test_common_parameter_acceptance() {
println!("🔍 Testing common parameter acceptance across providers");
let common_params = CommonParams {
model: "test-model".to_string(),
temperature: Some(0.7),
max_tokens: Some(1000),
top_p: Some(0.9),
stop_sequences: Some(vec!["STOP".to_string()]),
seed: Some(42),
};
let providers = vec![
("openai", SiumaiBuilder::new().openai()),
("anthropic", SiumaiBuilder::new().anthropic()),
("gemini", SiumaiBuilder::new().gemini()),
(
"ollama",
SiumaiBuilder::new()
.ollama()
.base_url("http://localhost:11434"),
),
("xai", SiumaiBuilder::new().xai()),
("groq", SiumaiBuilder::new().groq()),
("deepseek", SiumaiBuilder::new().deepseek()),
("openrouter", SiumaiBuilder::new().openrouter()),
];
for (provider_name, builder) in providers {
println!(" 🔍 Testing {} with common parameters...", provider_name);
let result = builder
.api_key("test-key")
.model(&common_params.model)
.temperature(common_params.temperature.unwrap())
.max_tokens(common_params.max_tokens.unwrap())
.top_p(common_params.top_p.unwrap())
.seed(common_params.seed.unwrap())
.stop_sequences(common_params.stop_sequences.clone().unwrap())
.build()
.await;
match result {
Ok(client) => {
println!(" ✅ {} accepted all common parameters", provider_name);
assert!(client.supports("chat"));
}
Err(e) => match e {
LlmError::ConfigurationError(msg) if msg.contains("parameter") => {
panic!(
" ❌ {} rejected common parameters: {}",
provider_name, msg
);
}
_ => {
println!(" ✅ {} failed with expected error: {}", provider_name, e);
}
},
}
}
}