From 9b06835d9012c512655dd16172700d410018f7bd Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 27 Nov 2026 00:30:37 +0000 Subject: [PATCH 1/2] Add the current Claude and GPT-6 models Anthropic: - Add `claude-fable-5-2`, `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5` and `claude-fable-5-1`; the default model is now `claude-sonnet-5-5`. - Omit sampling parameters for `claude-haiku-5-5`, which rejects non-default values; the existing prefixes already cover the point releases of Opus 5, Fable 5 and Sonnet 5. - Map the `refusal` stop reason to `kFinishReasonContentFilter` instead of `kFinishReasonStop`, both in responses and in streams. - Document that the newest models reject a forced tool choice. OpenAI: - Add `gpt-6.2-astra`, `gpt-6.2-sol`, `gpt-6.1-terra` and `gpt-6-luna`. - Treat the GPT-6 family as reasoning-first: omit sampling parameters, and send the lowest accepted `reasoning_effort` (`low`; `none` for `gpt-6-luna` and `gpt-6.1-terra`; GPT-6.2 rejects `none`). - Note the shutdown dates of `gpt-5-mini`, `gpt-5-nano`, `gpt-4.1`, `gpt-4.1-mini` and `gpt-5.4-nano`. - Keep `gpt-5.6` as the default: GPT-6 models support tool calling only through the Responses API, not Chat Completions. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- examples/basic_chat.cpp | 2 +- examples/components/all/main.cpp | 5 ++- examples/test_anthropic.cpp | 4 +- examples/tool_calling_async.cpp | 2 +- include/ai/anthropic.h | 14 +++++- include/ai/openai.h | 22 +++++++--- src/providers/anthropic/anthropic_client.cpp | 18 ++++---- .../anthropic/anthropic_request_builder.cpp | 8 ++-- .../anthropic/anthropic_response_parser.cpp | 5 +++ src/providers/anthropic/anthropic_stream.cpp | 2 + src/providers/openai/openai_client.cpp | 7 ++- .../openai/openai_request_builder.cpp | 29 +++++++++--- .../anthropic_integration_test.cpp | 19 ++++---- tests/integration/openai_integration_test.cpp | 5 ++- tests/unit/anthropic_client_test.cpp | 15 ++++++- tests/unit/anthropic_stream_test.cpp | 12 +++++ tests/unit/openai_client_test.cpp | 44 +++++++++++++++---- 18 files changed, 160 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 410c92d..c738420 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ int main() { int main() { // Ensure ANTHROPIC_API_KEY environment variable is set auto client = ai::anthropic::create_client(); - ai::GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, + ai::GenerateOptions options(ai::anthropic::models::kClaudeSonnet55, "Explain quantum computing in simple terms."); options.system = "You are a helpful assistant."; auto result = client.generate_text(options); diff --git a/examples/basic_chat.cpp b/examples/basic_chat.cpp index d179b31..2d24d80 100644 --- a/examples/basic_chat.cpp +++ b/examples/basic_chat.cpp @@ -98,7 +98,7 @@ int main() { auto client4 = ai::anthropic::create_client(); ai::GenerateOptions options4; - options4.model = ai::anthropic::models::kClaudeSonnet5; + options4.model = ai::anthropic::models::kClaudeSonnet55; options4.prompt = "Write a haiku about programming. Just the haiku, nothing else."; diff --git a/examples/components/all/main.cpp b/examples/components/all/main.cpp index 67dd8fe..3bd204a 100644 --- a/examples/components/all/main.cpp +++ b/examples/components/all/main.cpp @@ -51,8 +51,9 @@ int main() { try { auto anthropic_client = ai::anthropic::create_client(); std::cout << "✓ Anthropic client created successfully\n"; - std::cout << "✓ Available models: " << ai::anthropic::models::kClaudeSonnet5 - << ", " << ai::anthropic::models::kClaudeHaiku45 << "\n"; + std::cout << "✓ Available models: " + << ai::anthropic::models::kClaudeSonnet55 << ", " + << ai::anthropic::models::kClaudeHaiku55 << "\n"; } catch (const std::exception& e) { std::cout << "✗ Anthropic client failed: " << e.what() << "\n"; } diff --git a/examples/test_anthropic.cpp b/examples/test_anthropic.cpp index 5b72ca3..13149d8 100644 --- a/examples/test_anthropic.cpp +++ b/examples/test_anthropic.cpp @@ -16,7 +16,7 @@ int main() { // Test simple generation std::cout << "Testing Anthropic text generation...\n\n"; - ai::GenerateOptions options(ai::anthropic::models::kClaudeHaiku45, + ai::GenerateOptions options(ai::anthropic::models::kClaudeHaiku55, "You are a helpful assistant.", "Why is the sky blue? Give a short answer."); @@ -35,7 +35,7 @@ int main() { std::cout << "\nTesting streaming...\n"; ai::GenerateOptions stream_opts( - ai::anthropic::models::kClaudeHaiku45, + ai::anthropic::models::kClaudeHaiku55, "Count from 1 to 5 slowly and with each number say 'tick'"); ai::StreamOptions stream_options(stream_opts); diff --git a/examples/tool_calling_async.cpp b/examples/tool_calling_async.cpp index 2510d1f..89435f8 100644 --- a/examples/tool_calling_async.cpp +++ b/examples/tool_calling_async.cpp @@ -342,7 +342,7 @@ int main() { start_time = std::chrono::high_resolution_clock::now(); ai::GenerateOptions anthropic_options; - anthropic_options.model = ai::anthropic::models::kClaudeSonnet5; + anthropic_options.model = ai::anthropic::models::kClaudeSonnet55; anthropic_options.prompt = R"( Please help me with these THREE tasks. You MUST use the tools to complete ALL of them: 1. Use the fetch_news tool to get tech news articles diff --git a/include/ai/anthropic.h b/include/ai/anthropic.h index 0a10da7..67df022 100644 --- a/include/ai/anthropic.h +++ b/include/ai/anthropic.h @@ -16,6 +16,18 @@ namespace anthropic { namespace models { /// Current Anthropic model identifiers +/// +/// Claude Fable 5.1 and later, Claude Opus 5.5 and Claude Sonnet 5.5 reject a +/// forced tool choice (`ToolChoice::required()` and `ToolChoice::specific()`) +/// with HTTP 400; use `ToolChoice::auto_choice()` and name the tool in the +/// prompt instead. +constexpr const char* kClaudeFable52 = "claude-fable-5-2"; +constexpr const char* kClaudeOpus55 = "claude-opus-5-5"; +constexpr const char* kClaudeSonnet55 = "claude-sonnet-5-5"; +constexpr const char* kClaudeHaiku55 = "claude-haiku-5-5"; + +/// Previous-generation model identifiers (still available) +constexpr const char* kClaudeFable51 = "claude-fable-5-1"; constexpr const char* kClaudeFable5 = "claude-fable-5"; constexpr const char* kClaudeOpus5 = "claude-opus-5"; constexpr const char* kClaudeOpus48 = "claude-opus-4-8"; @@ -39,7 +51,7 @@ constexpr const char* kClaudeOpus41 = constexpr const char* kClaudeOpus41Snapshot = "claude-opus-4-1-20250805"; /// Default model used when none is specified -constexpr const char* kDefaultModel = kClaudeSonnet5; +constexpr const char* kDefaultModel = kClaudeSonnet55; } // namespace models /// Create an Anthropic client with default configuration diff --git a/include/ai/openai.h b/include/ai/openai.h index 1ed0df1..7772c0f 100644 --- a/include/ai/openai.h +++ b/include/ai/openai.h @@ -17,24 +17,33 @@ namespace openai { namespace models { /// Common OpenAI model identifiers -// GPT-5.6 series (current frontier family) +// GPT-6 series (current frontier family). On Chat Completions, which this +// SDK uses, these models reject sampling parameters and do not support tool +// calling (OpenAI serves their tool calling through the Responses API only). +constexpr const char* kGpt62Astra = "gpt-6.2-astra"; +constexpr const char* kGpt62Sol = "gpt-6.2-sol"; +constexpr const char* kGpt61Terra = "gpt-6.1-terra"; +constexpr const char* kGpt6Luna = "gpt-6-luna"; + +// GPT-5.6 series (latest family with tool calling on Chat Completions) constexpr const char* kGpt56 = "gpt-5.6"; // Alias for GPT-5.6 Sol constexpr const char* kGpt56Sol = "gpt-5.6-sol"; constexpr const char* kGpt56Terra = "gpt-5.6-terra"; constexpr const char* kGpt56Luna = "gpt-5.6-luna"; -// Earlier current GPT-5 series +// Earlier GPT-5 series constexpr const char* kGpt55 = "gpt-5.5"; constexpr const char* kGpt54 = "gpt-5.4"; constexpr const char* kGpt54Pro = "gpt-5.4-pro"; constexpr const char* kGpt54Mini = "gpt-5.4-mini"; -constexpr const char* kGpt54Nano = "gpt-5.4-nano"; +constexpr const char* kGpt54Nano = "gpt-5.4-nano"; // Shutdown: 2027-04-01 -// GPT-5 small variants (current) +// GPT-5 small variants (deprecated, shutdown: 2026-12-11; use kGpt61Terra +// and kGpt6Luna) constexpr const char* kGpt5Mini = "gpt-5-mini"; constexpr const char* kGpt5Nano = "gpt-5-nano"; -// GPT-4.1 series (still current non-reasoning leaders) +// GPT-4.1 series (deprecated, shutdown: 2027-01-14; use kGpt6Luna) constexpr const char* kGpt41 = "gpt-4.1"; constexpr const char* kGpt41Mini = "gpt-4.1-mini"; @@ -42,7 +51,8 @@ constexpr const char* kGpt41Mini = "gpt-4.1-mini"; constexpr const char* kTextEmbedding3Small = "text-embedding-3-small"; constexpr const char* kTextEmbedding3Large = "text-embedding-3-large"; -/// Default model used when none is specified +/// Default model used when none is specified. It stays on GPT-5.6 because the +/// GPT-6 series does not support tool calling on Chat Completions. constexpr const char* kDefaultModel = kGpt56; } // namespace models diff --git a/src/providers/anthropic/anthropic_client.cpp b/src/providers/anthropic/anthropic_client.cpp index 4516235..9fa1bc6 100644 --- a/src/providers/anthropic/anthropic_client.cpp +++ b/src/providers/anthropic/anthropic_client.cpp @@ -77,14 +77,16 @@ std::vector AnthropicClient::supported_models() const { // snapshot variants (e.g. "claude-sonnet-4-5-20250929") are accepted by the // Anthropic API; list both so identifiers in `ai::anthropic::models::*` // resolve via `supports_model()`. - return {models::kClaudeFable5, models::kClaudeOpus5, - models::kClaudeOpus48, models::kClaudeSonnet5, - models::kClaudeOpus47, models::kClaudeSonnet46, - models::kClaudeOpus46, models::kClaudeHaiku45, - models::kClaudeHaiku45Snapshot, models::kClaudeOpus45, - models::kClaudeOpus45Snapshot, models::kClaudeSonnet45, - models::kClaudeSonnet45Snapshot, models::kClaudeOpus41, - models::kClaudeOpus41Snapshot}; + return {models::kClaudeFable52, models::kClaudeOpus55, + models::kClaudeSonnet55, models::kClaudeHaiku55, + models::kClaudeFable51, models::kClaudeFable5, + models::kClaudeOpus5, models::kClaudeOpus48, + models::kClaudeSonnet5, models::kClaudeOpus47, + models::kClaudeSonnet46, models::kClaudeOpus46, + models::kClaudeHaiku45, models::kClaudeHaiku45Snapshot, + models::kClaudeOpus45, models::kClaudeOpus45Snapshot, + models::kClaudeSonnet45, models::kClaudeSonnet45Snapshot, + models::kClaudeOpus41, models::kClaudeOpus41Snapshot}; } bool AnthropicClient::supports_model(const std::string& model_name) const { diff --git a/src/providers/anthropic/anthropic_request_builder.cpp b/src/providers/anthropic/anthropic_request_builder.cpp index f63fd09..504d015 100644 --- a/src/providers/anthropic/anthropic_request_builder.cpp +++ b/src/providers/anthropic/anthropic_request_builder.cpp @@ -99,9 +99,11 @@ nlohmann::json AnthropicRequestBuilder::build_request_json( // Add optional parameters // Recent Anthropic models reject sampling controls. Keep accepting the // provider-neutral options while omitting them for those model IDs. - constexpr std::array kSamplingRejectingModelPrefixes = { - models::kClaudeOpus5, models::kClaudeOpus48, models::kClaudeOpus47, - models::kClaudeFable5, models::kClaudeSonnet5}; + // The prefixes also cover the later point releases ("claude-opus-5-5", + // "claude-fable-5-2", "claude-sonnet-5-5", ...). + constexpr std::array kSamplingRejectingModelPrefixes = { + models::kClaudeOpus5, models::kClaudeOpus48, models::kClaudeOpus47, + models::kClaudeFable5, models::kClaudeSonnet5, models::kClaudeHaiku55}; const bool rejects_sampling_parameters = std::any_of( kSamplingRejectingModelPrefixes.begin(), kSamplingRejectingModelPrefixes.end(), [&options](const char* prefix) { diff --git a/src/providers/anthropic/anthropic_response_parser.cpp b/src/providers/anthropic/anthropic_response_parser.cpp index a78bbe1..4ad3e51 100644 --- a/src/providers/anthropic/anthropic_response_parser.cpp +++ b/src/providers/anthropic/anthropic_response_parser.cpp @@ -146,6 +146,11 @@ FinishReason AnthropicResponseParser::parse_stop_reason( if (reason == "tool_use") { return kFinishReasonToolCalls; } + if (reason == "refusal") { + // Safety classifiers declined the request (HTTP 200, details in + // `stop_details`). + return kFinishReasonContentFilter; + } return kFinishReasonStop; } diff --git a/src/providers/anthropic/anthropic_stream.cpp b/src/providers/anthropic/anthropic_stream.cpp index 5a3b6a6..14078bf 100644 --- a/src/providers/anthropic/anthropic_stream.cpp +++ b/src/providers/anthropic/anthropic_stream.cpp @@ -138,6 +138,8 @@ void AnthropicStreamImpl::process_sse_event(const std::string& data) { finish_reason_ = kFinishReasonLength; } else if (stop_reason == "tool_use") { finish_reason_ = kFinishReasonToolCalls; + } else if (stop_reason == "refusal") { + finish_reason_ = kFinishReasonContentFilter; } else if (!stop_reason.empty()) { finish_reason_ = kFinishReasonStop; } diff --git a/src/providers/openai/openai_client.cpp b/src/providers/openai/openai_client.cpp index ef52005..4f0e947 100644 --- a/src/providers/openai/openai_client.cpp +++ b/src/providers/openai/openai_client.cpp @@ -83,12 +83,15 @@ std::string OpenAIClient::provider_name() const { } std::vector OpenAIClient::supported_models() const { - return {// Current GPT-5 series + return {// GPT-6 series + models::kGpt62Astra, models::kGpt62Sol, models::kGpt61Terra, + models::kGpt6Luna, + // GPT-5 series models::kGpt56, models::kGpt56Sol, models::kGpt56Terra, models::kGpt56Luna, models::kGpt55, models::kGpt54, models::kGpt54Pro, models::kGpt54Mini, models::kGpt54Nano, models::kGpt5Mini, models::kGpt5Nano, - // Current GPT-4.1 series + // GPT-4.1 series models::kGpt41, models::kGpt41Mini}; } diff --git a/src/providers/openai/openai_request_builder.cpp b/src/providers/openai/openai_request_builder.cpp index 621243c..bef33e9 100644 --- a/src/providers/openai/openai_request_builder.cpp +++ b/src/providers/openai/openai_request_builder.cpp @@ -13,13 +13,28 @@ namespace openai { namespace { -// The lowest `reasoning_effort` a GPT-5 family model accepts on Chat +// The lowest `reasoning_effort` a GPT-5 or GPT-6 family model accepts on Chat // Completions, or nullopt when the parameter must be left out: the model is // not in the family, or it is a variant whose accepted values are fixed or // not known. An unsupported value fails the request with HTTP 400, so the // field is only sent where the value is known to be accepted. std::optional lowest_reasoning_effort( std::string_view model) { + if (model.starts_with("gpt-6")) { + // The pro and cyber variants have value sets of their own. + for (const std::string_view variant : {"-pro", "-cyber"}) { + if (model.find(variant) != std::string_view::npos) { + return std::nullopt; + } + } + // Every GPT-6 model accepts "low"; GPT-6.2 and later reject "none", which + // only GPT-6 Luna and GPT-6.1 Terra are documented to accept. + if (model.starts_with("gpt-6-luna") || model.starts_with("gpt-6.1-terra")) { + return "none"; + } + return "low"; + } + if (!model.starts_with("gpt-5")) { return std::nullopt; } @@ -141,13 +156,13 @@ nlohmann::json OpenAIRequestBuilder::build_request_json( } // Add optional parameters - // The GPT-5 family is reasoning-first on Chat Completions: it rejects - // sampling controls ("'temperature' does not support 0.0 with this model. - // Only the default (1) value is supported."). Keep accepting the + // The GPT-5 and GPT-6 families are reasoning-first on Chat Completions: they + // reject sampling controls ("'temperature' does not support 0.0 with this + // model. Only the default (1) value is supported."). Keep accepting the // provider-neutral options while omitting them for those model IDs, // mirroring the Anthropic builder. - const bool is_gpt5_family = options.model.starts_with("gpt-5"); - const bool rejects_sampling_parameters = is_gpt5_family; + const bool rejects_sampling_parameters = + options.model.starts_with("gpt-5") || options.model.starts_with("gpt-6"); const auto add_sampling_parameter = [&](const char* key, const std::optional& value) { if (!value) { @@ -181,7 +196,7 @@ nlohmann::json OpenAIRequestBuilder::build_request_json( request["seed"] = *options.seed; } - // Much of the GPT-5 family defaults to reasoning in Chat Completions. That + // The GPT-5 and GPT-6 families default to reasoning in Chat Completions. That // mode can consume the full completion budget on hidden reasoning without // producing user-visible text (acute with a small max_tokens), and on // GPT-5.6 it does not support function tools. The unified SDK currently diff --git a/tests/integration/anthropic_integration_test.cpp b/tests/integration/anthropic_integration_test.cpp index 83bb9ab..e09c32a 100644 --- a/tests/integration/anthropic_integration_test.cpp +++ b/tests/integration/anthropic_integration_test.cpp @@ -135,6 +135,8 @@ TEST_F(AnthropicIntegrationTest, DifferentModelSupport) { std::vector models_to_test = { ai::anthropic::models::kDefaultModel, + ai::anthropic::models::kClaudeOpus55, + ai::anthropic::models::kClaudeHaiku55, ai::anthropic::models::kClaudeHaiku45}; for (const auto& model : models_to_test) { @@ -278,7 +280,7 @@ TEST_F(AnthropicIntegrationTest, LargePromptHandling) { auto large_prompt = TestDataGenerator::createLargePrompt(2000); // ~2KB prompt - GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, large_prompt); + GenerateOptions options(ai::anthropic::models::kClaudeSonnet55, large_prompt); auto result = client_->generate_text(options); TestAssertions::assertSuccess(result); @@ -299,7 +301,7 @@ TEST_F(AnthropicIntegrationTest, CustomBaseUrl) { auto custom_client = ai::anthropic::create_client(api_key, "https://api.anthropic.com"); - GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, + GenerateOptions options(ai::anthropic::models::kClaudeSonnet55, "Test custom base URL"); auto result = custom_client.generate_text(options); @@ -313,7 +315,7 @@ TEST_F(AnthropicIntegrationTest, EmptyPrompt) { GTEST_SKIP() << "No ANTHROPIC_API_KEY environment variable set"; } - GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, ""); + GenerateOptions options(ai::anthropic::models::kClaudeSonnet55, ""); // Empty prompt should be caught by validation EXPECT_FALSE(options.is_valid()); @@ -328,7 +330,7 @@ TEST_F(AnthropicIntegrationTest, VeryLongResponse) { GTEST_SKIP() << "No ANTHROPIC_API_KEY environment variable set"; } - GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, + GenerateOptions options(ai::anthropic::models::kClaudeSonnet55, "Write a detailed explanation of quantum physics"); options.max_tokens = 500; // Reasonable limit for testing @@ -349,7 +351,8 @@ TEST_F(AnthropicIntegrationTest, NetworkTimeout) { // Note: This test documents timeout behavior but cannot reliably trigger it // with the real API under normal conditions - GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, "Simple test"); + GenerateOptions options(ai::anthropic::models::kClaudeSonnet55, + "Simple test"); auto result = client_->generate_text(options); // Under normal conditions, this should succeed @@ -374,7 +377,7 @@ TEST_F(AnthropicIntegrationTest, NetworkFailure) { auto failing_client = ai::anthropic::create_client( api_key, "http://localhost:59999"); // Very unlikely port to be in use - GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, + GenerateOptions options(ai::anthropic::models::kClaudeSonnet55, "Test network failure"); auto result = failing_client.generate_text(options); @@ -425,7 +428,7 @@ TEST_F(AnthropicIntegrationTest, MaxTokensRequired) { GTEST_SKIP() << "No ANTHROPIC_API_KEY environment variable set"; } - GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, + GenerateOptions options(ai::anthropic::models::kClaudeSonnet55, "Tell me about artificial intelligence"); // Anthropic requires max_tokens to be set options.max_tokens = 100; @@ -444,7 +447,7 @@ TEST_F(AnthropicIntegrationTest, SystemMessageHandling) { // Anthropic has specific handling for system messages GenerateOptions options( - ai::anthropic::models::kClaudeSonnet5, + ai::anthropic::models::kClaudeSonnet55, "You are Claude, an AI assistant created by Anthropic.", "What is your name?"); options.max_tokens = 50; diff --git a/tests/integration/openai_integration_test.cpp b/tests/integration/openai_integration_test.cpp index cbabff3..ad9e243 100644 --- a/tests/integration/openai_integration_test.cpp +++ b/tests/integration/openai_integration_test.cpp @@ -133,8 +133,9 @@ TEST_F(OpenAIIntegrationTest, DifferentModelSupport) { GTEST_SKIP() << "No OPENAI_API_KEY environment variable set"; } - std::vector models_to_test = {ai::openai::models::kGpt56, - ai::openai::models::kGpt56Luna}; + std::vector models_to_test = { + ai::openai::models::kGpt56, ai::openai::models::kGpt56Luna, + ai::openai::models::kGpt62Sol, ai::openai::models::kGpt6Luna}; for (const auto& model : models_to_test) { if (!client_->supports_model(model)) { diff --git a/tests/unit/anthropic_client_test.cpp b/tests/unit/anthropic_client_test.cpp index aeab3da..0202a1c 100644 --- a/tests/unit/anthropic_client_test.cpp +++ b/tests/unit/anthropic_client_test.cpp @@ -94,6 +94,11 @@ TEST_F(AnthropicClientTest, ConstructorWithCustomRetryConfig) { TEST_F(AnthropicClientTest, SupportedModelsContainsExpectedModels) { auto models = client_->supported_models(); + EXPECT_THAT(models, testing::Contains(anthropic::models::kClaudeFable52)); + EXPECT_THAT(models, testing::Contains(anthropic::models::kClaudeOpus55)); + EXPECT_THAT(models, testing::Contains(anthropic::models::kClaudeSonnet55)); + EXPECT_THAT(models, testing::Contains(anthropic::models::kClaudeHaiku55)); + EXPECT_THAT(models, testing::Contains(anthropic::models::kClaudeFable51)); EXPECT_THAT(models, testing::Contains(anthropic::models::kClaudeFable5)); EXPECT_THAT(models, testing::Contains(anthropic::models::kClaudeOpus5)); EXPECT_THAT(models, testing::Contains(anthropic::models::kClaudeOpus48)); @@ -104,6 +109,7 @@ TEST_F(AnthropicClientTest, SupportedModelsContainsExpectedModels) { } TEST_F(AnthropicClientTest, SupportsValidModel) { + EXPECT_TRUE(client_->supports_model(anthropic::models::kDefaultModel)); EXPECT_TRUE(client_->supports_model(anthropic::models::kClaudeFable5)); EXPECT_TRUE(client_->supports_model(anthropic::models::kClaudeOpus5)); EXPECT_TRUE(client_->supports_model(anthropic::models::kClaudeOpus48)); @@ -170,8 +176,11 @@ TEST_F(AnthropicClientTest, ValidateOptionsValidation) { TEST_F(AnthropicClientTest, RecentModelsOmitUnsupportedSamplingParameters) { anthropic::AnthropicRequestBuilder builder; for (const auto* model : - {anthropic::models::kClaudeOpus48, anthropic::models::kClaudeOpus47, - anthropic::models::kClaudeFable5, anthropic::models::kClaudeSonnet5}) { + {anthropic::models::kClaudeFable52, anthropic::models::kClaudeFable51, + anthropic::models::kClaudeOpus55, anthropic::models::kClaudeSonnet55, + anthropic::models::kClaudeHaiku55, anthropic::models::kClaudeOpus48, + anthropic::models::kClaudeOpus47, anthropic::models::kClaudeFable5, + anthropic::models::kClaudeSonnet5}) { GenerateOptions options(model, "Hello"); options.temperature = 0.7; options.top_p = 0.8; @@ -232,6 +241,8 @@ TEST_F(AnthropicClientTest, TestStopReasonParsing) { EXPECT_EQ(client_->parse_stop_reason("max_tokens"), kFinishReasonLength); EXPECT_EQ(client_->parse_stop_reason("stop_sequence"), kFinishReasonStop); EXPECT_EQ(client_->parse_stop_reason("tool_use"), kFinishReasonToolCalls); + EXPECT_EQ(client_->parse_stop_reason("refusal"), + kFinishReasonContentFilter); EXPECT_EQ(client_->parse_stop_reason("unknown"), kFinishReasonStop); // Anthropic defaults unknown to stop } diff --git a/tests/unit/anthropic_stream_test.cpp b/tests/unit/anthropic_stream_test.cpp index ded11ba..747f78c 100644 --- a/tests/unit/anthropic_stream_test.cpp +++ b/tests/unit/anthropic_stream_test.cpp @@ -450,5 +450,17 @@ TEST_F(AnthropicStreamEventTypesTest, MessageStopEvent) { EXPECT_THAT(event_data, testing::HasSubstr("message_stop")); } +TEST_F(AnthropicStreamEventTest, MapsRefusalToContentFilter) { + anthropic::AnthropicStreamImpl stream; + stream.process_sse_chunk_for_testing( + "data: {\"type\":\"message_delta\",\"delta\":{\"stop_reason\":" + "\"refusal\"}}\n\n" + "data: {\"type\":\"message_stop\"}\n\n"); + + auto finish_event = stream.get_next_event(); + ASSERT_TRUE(finish_event.is_finish()); + EXPECT_EQ(finish_event.finish_reason, kFinishReasonContentFilter); +} + } // namespace test } // namespace ai diff --git a/tests/unit/openai_client_test.cpp b/tests/unit/openai_client_test.cpp index 3cac86b..ba65d0a 100644 --- a/tests/unit/openai_client_test.cpp +++ b/tests/unit/openai_client_test.cpp @@ -81,6 +81,10 @@ TEST_F(OpenAIClientTest, ConstructorWithHttpUrl) { TEST_F(OpenAIClientTest, SupportedModelsContainsExpectedModels) { auto models = client_->supported_models(); + EXPECT_THAT(models, testing::Contains(openai::models::kGpt62Astra)); + EXPECT_THAT(models, testing::Contains(openai::models::kGpt62Sol)); + EXPECT_THAT(models, testing::Contains(openai::models::kGpt61Terra)); + EXPECT_THAT(models, testing::Contains(openai::models::kGpt6Luna)); EXPECT_THAT(models, testing::Contains(openai::models::kGpt56)); EXPECT_THAT(models, testing::Contains(openai::models::kGpt56Sol)); EXPECT_THAT(models, testing::Contains(openai::models::kGpt56Terra)); @@ -154,20 +158,19 @@ TEST_F(OpenAIClientTest, Gpt5FamilyUsesChatCompletionsCompatibleReasoning) { openai::OpenAIRequestBuilder builder; // GPT-5.1 and later accept "none" and reject "minimal". - for (const auto* model : - {openai::models::kGpt56, openai::models::kGpt56Luna, - openai::models::kGpt55, openai::models::kGpt54, - openai::models::kGpt54Mini, openai::models::kGpt54Nano, "gpt-5.2", - "gpt-5.1"}) { + for (const auto* model : {openai::models::kGpt56, openai::models::kGpt56Luna, + openai::models::kGpt55, openai::models::kGpt54, + openai::models::kGpt54Mini, + openai::models::kGpt54Nano, "gpt-5.2", "gpt-5.1"}) { GenerateOptions options(model, "Use a tool"); EXPECT_EQ(builder.build_request_json(options)["reasoning_effort"], "none") << model; } // The original GPT-5 models reject "none"; they get the "minimal" floor. - for (const auto* model : {"gpt-5", "gpt-5-2025-08-07", - openai::models::kGpt5Mini, - openai::models::kGpt5Nano}) { + for (const auto* model : + {"gpt-5", "gpt-5-2025-08-07", openai::models::kGpt5Mini, + openai::models::kGpt5Nano}) { GenerateOptions options(model, "Use a tool"); EXPECT_EQ(builder.build_request_json(options)["reasoning_effort"], "minimal") @@ -175,6 +178,28 @@ TEST_F(OpenAIClientTest, Gpt5FamilyUsesChatCompletionsCompatibleReasoning) { } } +TEST_F(OpenAIClientTest, Gpt6FamilyUsesLowestAcceptedReasoningEffort) { + openai::OpenAIRequestBuilder builder; + + // GPT-6.2 rejects "none"; "low" is accepted by every GPT-6 model. + for (const auto* model : + {openai::models::kGpt62Astra, openai::models::kGpt62Sol, "gpt-6-sol"}) { + GenerateOptions options(model, "Hello"); + EXPECT_EQ(builder.build_request_json(options)["reasoning_effort"], "low") + << model; + } + + for (const auto* model : + {openai::models::kGpt61Terra, openai::models::kGpt6Luna}) { + GenerateOptions options(model, "Hello"); + EXPECT_EQ(builder.build_request_json(options)["reasoning_effort"], "none") + << model; + } + + GenerateOptions cyber("gpt-6-cyber", "Hello"); + EXPECT_FALSE(builder.build_request_json(cyber).contains("reasoning_effort")); +} + TEST_F(OpenAIClientTest, ReasoningEffortIsOmittedWhereItsValuesAreNotKnown) { openai::OpenAIRequestBuilder builder; @@ -194,7 +219,8 @@ TEST_F(OpenAIClientTest, ReasoningEffortIsOmittedWhereItsValuesAreNotKnown) { TEST_F(OpenAIClientTest, Gpt5FamilyOmitsUnsupportedSamplingParameters) { openai::OpenAIRequestBuilder builder; for (const auto* model : - {openai::models::kGpt56, openai::models::kGpt56Terra, + {openai::models::kGpt62Sol, openai::models::kGpt6Luna, + openai::models::kGpt56, openai::models::kGpt56Terra, openai::models::kGpt55, openai::models::kGpt5Mini}) { GenerateOptions options(model, "Hello"); options.temperature = 0.0; From 01b88fa3aba9c4556b4660806422ca2f1076cddb Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 27 Nov 2026 00:42:29 +0000 Subject: [PATCH 2/2] Format `openai_stream.cpp` with clang-format 18 (as in #63) Co-Authored-By: Claude Opus 5.5 --- src/providers/openai/openai_stream.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/providers/openai/openai_stream.cpp b/src/providers/openai/openai_stream.cpp index bf3ce39..105e9c8 100644 --- a/src/providers/openai/openai_stream.cpp +++ b/src/providers/openai/openai_stream.cpp @@ -45,13 +45,14 @@ void OpenAIStreamImpl::process_sse_line(std::string_view line) { if (delta.contains("reasoning_content") && !delta["reasoning_content"].is_null()) { - std::string content = delta["reasoning_content"].get(); ai::logger::log_debug("Received reasoning_content chunk - length: {}", content.length()); - //TODO: currently not passing content, needs revamping of StreamEvent constructor - push_event(StreamEvent(StreamEventType::kStreamEventTypeReasoningDelta)); - } + // TODO: currently not passing content, needs revamping of StreamEvent + // constructor + push_event( + StreamEvent(StreamEventType::kStreamEventTypeReasoningDelta)); + } if (delta.contains("tool_calls") && delta["tool_calls"].is_array()) { for (const auto& fragment : delta["tool_calls"]) {