feat: Add has_reasoning flag to chat completion responses#7657
feat: Add has_reasoning flag to chat completion responses#7657AsadShahid04 wants to merge 1 commit intoai-dynamo:mainfrom
Conversation
|
👋 Hi AsadShahid04! Thank you for contributing to ai-dynamo/dynamo. Just a reminder: The 🚀 |
WalkthroughThe PR adds a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
lib/llm/src/protocols/openai/chat_completions/aggregator.rs (2)
442-448:⚠️ Potential issue | 🔴 CriticalMissing
has_reasoningfield in test helper will cause compilation failure.The
ChatChoiceStreamstruct now requires thehas_reasoningfield, but the test helper at lines 442-448 doesn't include it. This will prevent the tests from compiling.🐛 Proposed fix
let choice = dynamo_async_openai::types::ChatChoiceStream { index, delta, finish_reason, stop_reason: None, logprobs, + has_reasoning: None, };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/llm/src/protocols/openai/chat_completions/aggregator.rs` around lines 442 - 448, The test helper constructing dynamo_async_openai::types::ChatChoiceStream is missing the new required has_reasoning field; update the construction in aggregator.rs (the ChatChoiceStream creation around index/delta/finish_reason/logprobs) to include has_reasoning (true or false as appropriate for the test case) so the struct initializer matches the updated type and the tests compile.
666-693:⚠️ Potential issue | 🔴 CriticalMissing
has_reasoningfield in test constructions.These
ChatChoiceStreamconstructions are also missing the newhas_reasoningfield and will fail to compile.🐛 Proposed fix
dynamo_async_openai::types::ChatChoiceStream { index: 0, delta: dynamo_async_openai::types::ChatCompletionStreamResponseDelta { role: Some(dynamo_async_openai::types::Role::Assistant), content: Some(ChatCompletionMessageContent::Text("Choice 0".to_string())), function_call: None, tool_calls: None, refusal: None, reasoning_content: None, }, finish_reason: Some(dynamo_async_openai::types::FinishReason::Stop), stop_reason: None, logprobs: None, + has_reasoning: None, }, dynamo_async_openai::types::ChatChoiceStream { index: 1, delta: dynamo_async_openai::types::ChatCompletionStreamResponseDelta { role: Some(dynamo_async_openai::types::Role::Assistant), content: Some(ChatCompletionMessageContent::Text("Choice 1".to_string())), function_call: None, tool_calls: None, refusal: None, reasoning_content: None, }, finish_reason: Some(dynamo_async_openai::types::FinishReason::Stop), stop_reason: None, logprobs: None, + has_reasoning: None, },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/llm/src/protocols/openai/chat_completions/aggregator.rs` around lines 666 - 693, The test ChatChoiceStream constructions are missing the new has_reasoning field and thus won't compile; update each dynamo_async_openai::types::ChatChoiceStream literal (the ones with index: 0 and index: 1) to include the has_reasoning field and set it to the appropriate default for the type (e.g., has_reasoning: None if it's Option<bool> or has_reasoning: false if it's a bool) so the struct literals for ChatChoiceStream/ChatCompletionStreamResponseDelta compile.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/llm/src/protocols/openai/chat_completions/delta.rs`:
- Around line 265-277: The has_reasoning computation is dead because
reasoning_content is hardcoded to None in create_choice; either accept
reasoning_content as a parameter to create_choice and set
delta.reasoning_content accordingly so the has_reasoning check
(delta.reasoning_content.as_ref().is_some_and(|r| !r.is_empty())) can reflect
real data, or remove the reasoning_content/has_reasoning logic entirely and stop
populating dynamo_async_openai::types::ChatChoiceStream.has_reasoning here;
update the create_choice signature and callers (or remove the check and related
field) and ensure consistency with components that currently populate
reasoning_content later (e.g., jail.rs, aggregator.rs).
---
Outside diff comments:
In `@lib/llm/src/protocols/openai/chat_completions/aggregator.rs`:
- Around line 442-448: The test helper constructing
dynamo_async_openai::types::ChatChoiceStream is missing the new required
has_reasoning field; update the construction in aggregator.rs (the
ChatChoiceStream creation around index/delta/finish_reason/logprobs) to include
has_reasoning (true or false as appropriate for the test case) so the struct
initializer matches the updated type and the tests compile.
- Around line 666-693: The test ChatChoiceStream constructions are missing the
new has_reasoning field and thus won't compile; update each
dynamo_async_openai::types::ChatChoiceStream literal (the ones with index: 0 and
index: 1) to include the has_reasoning field and set it to the appropriate
default for the type (e.g., has_reasoning: None if it's Option<bool> or
has_reasoning: false if it's a bool) so the struct literals for
ChatChoiceStream/ChatCompletionStreamResponseDelta compile.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3d696228-fd02-486b-9396-08eb26b203dd
📒 Files selected for processing (3)
lib/async-openai/src/types/chat.rslib/llm/src/protocols/openai/chat_completions/aggregator.rslib/llm/src/protocols/openai/chat_completions/delta.rs
4cf09b8 to
88938f0
Compare
- Add has_reasoning field to ChatChoice and ChatChoiceStream structs - Set has_reasoning to true when reasoning_content is present and non-empty - Helps clients identify responses that include reasoning content Fixes ai-dynamo#7154 Signed-off-by: Asad Shahid <[email protected]>
88938f0 to
076c910
Compare
|
Hi @AsadShahid04 , thanks for the contribution. I don't think we need a new Boolean field to identify this, we can instead fix the root of the problem by making sure the content field is always present in the response, even if an empty string. |
Fixes #7154
Summary by CodeRabbit