| 19 | #include <ai/ai.h> |
| 20 | |
| 21 | void demonstrate_api_errors() { |
| 22 | std::cout << "1. API Error Handling\n"; |
| 23 | std::cout << "======================\n\n"; |
| 24 | |
| 25 | // Test with invalid API key |
| 26 | std::cout << "Testing with invalid model name:\n"; |
| 27 | auto client = ai::openai::create_client(); |
| 28 | ai::GenerateOptions options1; |
| 29 | options1.model = "invalid-model-2024"; |
| 30 | options1.prompt = "Hello, world!"; |
| 31 | auto result1 = client.generate_text(options1); |
| 32 | |
| 33 | if (!result1) { |
| 34 | std::cout << "Expected error: " << result1.error_message() << "\n\n"; |
| 35 | } |
| 36 | |
| 37 | // Test with empty prompt |
| 38 | std::cout << "Testing with empty prompt:\n"; |
| 39 | ai::GenerateOptions options2; |
| 40 | options2.model = ai::openai::models::kGpt54; |
| 41 | options2.prompt = ""; |
| 42 | auto result2 = client.generate_text(options2); |
| 43 | |
| 44 | if (!result2) { |
| 45 | std::cout << "Expected error: " << result2.error_message() << "\n\n"; |
| 46 | } |
| 47 | |
| 48 | // Test with malformed model identifier |
| 49 | std::cout << "Testing with malformed model identifier:\n"; |
| 50 | ai::GenerateOptions options3; |
| 51 | options3.model = ""; |
| 52 | options3.prompt = "Hello, world!"; |
| 53 | auto result3 = client.generate_text(options3); |
| 54 | |
| 55 | if (!result3) { |
| 56 | std::cout << "Expected error: " << result3.error_message() << "\n\n"; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void demonstrate_validation() { |
| 61 | std::cout << "2. Input Validation\n"; |
no test coverage detected