feat: Add reasoning support for Cohere chat generator #2266
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Issues
Proposed Changes:
This PR implements reasoning support for Cohere's chat generator following the parent issue #9700 requirements. The implementation adds the ability to extract and store model reasoning content in the
ReasoningContentfield ofChatMessage.Key Features Added:
_extract_reasoning_from_response) thatsupports multiple formats:
<thinking>,<reasoning>## Reasoning,## Thinking,## My reasoningcall scenarios
_convert_streaming_chunks_to_chat_message_with_reasoningfunctionwithout conflicts
text
positives
The implementation follows the established patterns from Ollama (#2200) and
Google GenAI (#2212) PRs, ensuring consistency across providers.
How did you test it?
TestReasoningExtraction)covering:
<thinking>,<reasoning>,step-by-step)
TestCohereChatGeneratorReasoningclass with:(lightweight)
rate limiting (API working correctly)
hatch run fmt) and type checking (hatch run test:types) passNotes for the reviewer
_extract_reasoning_from_response()function (lines ~355-435)
_parse_response()for both regular and toolcall paths (lines ~194-220)
reasoning in response text
command-a-reasoning-111b-2024-10-03model asrecommended
thinkingparameter viageneration_kwargs={"thinking": True}Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:.