Skip to content

feat(rust): add reasoning_content field to ChatMessage types#62

Merged
AnthonyRonning merged 1 commit intomasterfrom
add-reasoning-content
Jan 27, 2026
Merged

feat(rust): add reasoning_content field to ChatMessage types#62
AnthonyRonning merged 1 commit intomasterfrom
add-reasoning-content

Conversation

@AnthonyRonning
Copy link
Contributor

@AnthonyRonning AnthonyRonning commented Jan 27, 2026

Summary

Add optional reasoning_content field to ChatMessage and ChatMessageDelta structs in the Rust SDK.

Motivation

Models like Kimi K2 (via vLLM/Tinfoil) can expose their reasoning/thinking process through a reasoning_content field in the response. Without this field in the SDK types, the reasoning content is silently dropped during deserialization.

Changes

  • Added reasoning_content: Option<String> to ChatMessage (for non-streaming responses)
  • Added reasoning_content: Option<String> to ChatMessageDelta (for streaming responses)
  • Both fields use #[serde(skip_serializing_if = "Option::is_none")] to avoid serializing when not present

Testing

  • cargo check passes

Summary by CodeRabbit

  • New Features

    • Chat messages can now include an optional "reasoning content" field.
  • Tests

    • Test fixtures updated to include the new optional field where applicable.
    • Added a streaming test that verifies reasoning content can be produced in deltas for the relevant model.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

Adds an optional reasoning_content: Option<String> (with serde(skip_serializing_if = "Option::is_none")) to ChatMessage and ChatMessageDelta in rust/src/types.rs, updates test payloads to include the field (initialized as None), and adds a streaming test asserting reasoning_content appears for the kimi-k2-thinking model.

Changes

Cohort / File(s) Summary
Type additions
rust/src/types.rs
Added reasoning_content: Option<String> to ChatMessage and ChatMessageDelta with serde(skip_serializing_if = "Option::is_none").
Test updates
rust/tests/ai_integration.rs, rust/tests/api_keys.rs
Added reasoning_content: None to multiple ChatMessage instances in tests; introduced test_reasoning_content_with_kimi_k2_thinking to assert reasoning_content appears in streaming deltas; minor safe changes to streaming usage checks.

Sequence Diagram(s)

(Skipped — changes are type additions and test updates without a new multi-component control flow requiring visualization.)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 I nibble code in morning light,

A tiny field tucked out of sight,
Optional whispers, soft and keen,
Reasoning dreams in places unseen,
Hopping on, delighted and bright.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a reasoning_content field to ChatMessage types in Rust, matching the core objective of supporting this field in both ChatMessage and ChatMessageDelta structs.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 27, 2026

Deploying opensecret-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5f970f1
Status: ✅  Deploy successful!
Preview URL: https://45afd2b8.opensecret-sdk.pages.dev
Branch Preview URL: https://add-reasoning-content.opensecret-sdk.pages.dev

View logs

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 27, 2026

Greptile Overview

Greptile Summary

Added optional reasoning_content field to both ChatMessage and ChatMessageDelta structs in the Rust SDK to capture reasoning/thinking processes from AI models like Kimi K2. The implementation follows proper Rust/serde patterns with Option<String> type and #[serde(skip_serializing_if = "Option::is_none")] to ensure backward compatibility. All test fixtures have been updated to initialize the field as None.

Key changes:

  • ChatMessage and ChatMessageDelta now include reasoning_content: Option<String>
  • Test fixtures updated across ai_integration.rs and api_keys.rs
  • New test test_reasoning_content_with_kimi_k2_thinking added to verify the feature works with streaming responses

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-contained, follow Rust best practices with proper Option types and serde attributes, maintain backward compatibility through skip_serializing_if, and include appropriate test coverage. The implementation is straightforward and doesn't modify any core logic.
  • No files require special attention

Important Files Changed

Filename Overview
rust/src/types.rs Added reasoning_content field to ChatMessage and ChatMessageDelta structs with proper serde attributes
rust/tests/ai_integration.rs Updated test fixtures to include reasoning_content: None and added new test for Kimi K2 thinking model
rust/tests/api_keys.rs Updated test fixture to include reasoning_content: None for API key streaming test

Sequence Diagram

sequenceDiagram
    participant Client as Rust SDK Client
    participant API as OpenSecret API
    participant Model as AI Model (e.g., Kimi K2)
    
    Client->>API: ChatCompletionRequest (with messages)
    API->>Model: Forward request
    
    alt Streaming Response
        loop For each token
            Model-->>API: ChatCompletionChunk with delta
            Note over Model,API: delta.reasoning_content (if available)<br/>delta.content (response text)
            API-->>Client: Encrypted ChatCompletionChunk
            Client->>Client: Deserialize with reasoning_content field
        end
    else Non-Streaming Response
        Model-->>API: ChatCompletionResponse
        Note over Model,API: message.reasoning_content (if available)<br/>message.content (response text)
        API-->>Client: Encrypted ChatCompletionResponse
        Client->>Client: Deserialize with reasoning_content field
    end

Loading

@AnthonyRonning AnthonyRonning force-pushed the add-reasoning-content branch 4 times, most recently from 7b22506 to 5f970f1 Compare January 27, 2026 16:51
Add optional reasoning_content field to ChatMessage and ChatMessageDelta
structs to support models that expose their reasoning/thinking process
(e.g., Kimi K2 thinking model via vLLM).

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@AnthonyRonning AnthonyRonning merged commit 62385e4 into master Jan 27, 2026
21 of 26 checks passed
@AnthonyRonning AnthonyRonning deleted the add-reasoning-content branch January 27, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant