mirror of
https://github.com/mii443/rust-genai.git
synced 2025-08-22 16:25:27 +00:00
120 lines
2.9 KiB
Rust
120 lines
2.9 KiB
Rust
mod support;
|
|
|
|
use crate::support::common_tests;
|
|
use genai::adapter::AdapterKind;
|
|
use genai::resolver::AuthData;
|
|
use serial_test::serial;
|
|
|
|
type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>; // For tests.
|
|
|
|
// 4k (cheaper)
|
|
const MODEL: &str = "claude-3-haiku-20240307";
|
|
// 8k output context
|
|
// const MODEL: &str = "claude-3-5-haiku-20241022";
|
|
|
|
// region: --- Chat
|
|
|
|
#[tokio::test]
|
|
#[serial(anthropic)]
|
|
async fn test_chat_simple_ok() -> Result<()> {
|
|
common_tests::common_test_chat_simple_ok(MODEL).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_chat_multi_system_ok() -> Result<()> {
|
|
common_tests::common_test_chat_multi_system_ok(MODEL).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial(anthropic)]
|
|
async fn test_chat_temperature_ok() -> Result<()> {
|
|
common_tests::common_test_chat_temperature_ok(MODEL).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial(anthropic)]
|
|
async fn test_chat_stop_sequences_ok() -> Result<()> {
|
|
common_tests::common_test_chat_stop_sequences_ok(MODEL).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial(anthropic)]
|
|
async fn test_chat_json_mode_ok() -> Result<()> {
|
|
common_tests::common_test_chat_json_mode_ok(MODEL, true).await
|
|
}
|
|
|
|
// endregion: --- Chat
|
|
|
|
// region: --- Chat Stream Tests
|
|
|
|
#[tokio::test]
|
|
#[serial(anthropic)]
|
|
async fn test_chat_stream_simple_ok() -> Result<()> {
|
|
common_tests::common_test_chat_stream_simple_ok(MODEL).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial(anthropic)]
|
|
async fn test_chat_stream_capture_content_ok() -> Result<()> {
|
|
common_tests::common_test_chat_stream_capture_content_ok(MODEL).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial(anthropic)]
|
|
async fn test_chat_stream_capture_all_ok() -> Result<()> {
|
|
common_tests::common_test_chat_stream_capture_all_ok(MODEL).await
|
|
}
|
|
// endregion: --- Chat Stream Tests
|
|
|
|
// region: --- Image Tests
|
|
|
|
// NOTE: For now disable these tests as they failed. Needs to be resolved.
|
|
|
|
// Anthropic does not support image URL
|
|
// #[tokio::test]
|
|
// async fn test_chat_image_url_ok() -> Result<()> {
|
|
// common_tests::common_test_chat_image_url_ok(MODEL).await
|
|
// }
|
|
|
|
#[tokio::test]
|
|
async fn test_chat_image_b64_ok() -> Result<()> {
|
|
common_tests::common_test_chat_image_b64_ok(MODEL).await
|
|
}
|
|
|
|
// endregion: --- Image Test
|
|
|
|
// region: --- Tool Tests
|
|
|
|
#[tokio::test]
|
|
#[serial(anthropic)]
|
|
async fn test_tool_simple_ok() -> Result<()> {
|
|
common_tests::common_test_tool_simple_ok(MODEL, false).await
|
|
}
|
|
|
|
#[tokio::test]
|
|
// #[serial(anthropic)]
|
|
async fn test_tool_full_flow_ok() -> Result<()> {
|
|
common_tests::common_test_tool_full_flow_ok(MODEL, false).await
|
|
}
|
|
|
|
// endregion: --- Tool Tests
|
|
|
|
// region: --- Resolver Tests
|
|
|
|
#[tokio::test]
|
|
#[serial(anthropic)]
|
|
async fn test_resolver_auth_ok() -> Result<()> {
|
|
common_tests::common_test_resolver_auth_ok(MODEL, AuthData::from_env("ANTHROPIC_API_KEY")).await
|
|
}
|
|
|
|
// endregion: --- Resolver Tests
|
|
|
|
// region: --- List
|
|
|
|
#[tokio::test]
|
|
async fn test_list_models() -> Result<()> {
|
|
common_tests::common_test_list_models(AdapterKind::Anthropic, "claude-3-5-sonnet-20241022").await
|
|
}
|
|
|
|
// endregion: --- List
|