Files
rust-genai/tests/tests_p_openai.rs
2024-12-08 10:20:26 -08:00

94 lines
2.3 KiB
Rust

mod support;
use crate::support::common_tests;
use genai::adapter::AdapterKind;
use genai::resolver::AuthData;
type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>; // For tests.
const MODEL: &str = "gpt-4o-mini";
// region: --- Chat
#[tokio::test]
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]
async fn test_chat_json_mode_ok() -> Result<()> {
common_tests::common_test_chat_json_mode_ok(MODEL, true).await
}
#[tokio::test]
async fn test_chat_json_structured_ok() -> Result<()> {
common_tests::common_test_chat_json_structured_ok(MODEL, true).await
}
#[tokio::test]
async fn test_chat_temperature_ok() -> Result<()> {
common_tests::common_test_chat_temperature_ok(MODEL).await
}
#[tokio::test]
async fn test_chat_stop_sequences_ok() -> Result<()> {
common_tests::common_test_chat_stop_sequences_ok(MODEL).await
}
// endregion: --- Chat
// region: --- Chat Stream Tests
#[tokio::test]
async fn test_chat_stream_simple_ok() -> Result<()> {
common_tests::common_test_chat_stream_simple_ok(MODEL).await
}
#[tokio::test]
async fn test_chat_stream_capture_content_ok() -> Result<()> {
common_tests::common_test_chat_stream_capture_content_ok(MODEL).await
}
#[tokio::test]
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: --- Tool Tests
#[tokio::test]
async fn test_tool_simple_ok() -> Result<()> {
common_tests::common_test_tool_simple_ok(MODEL, true).await
}
#[tokio::test]
async fn test_tool_full_flow_ok() -> Result<()> {
common_tests::common_test_tool_full_flow_ok(MODEL, true).await
}
// endregion: --- Tool Tests
// region: --- Resolver Tests
#[tokio::test]
async fn test_resolver_auth_ok() -> Result<()> {
common_tests::common_test_resolver_auth_ok(MODEL, AuthData::from_env("OPENAI_API_KEY")).await
}
// endregion: --- Resolver Tests
// region: --- List
#[tokio::test]
async fn test_list_models() -> Result<()> {
common_tests::common_test_list_models(AdapterKind::OpenAI, "gpt-4o").await
}
// endregion: --- List