mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-09-26 20:31:14 +08:00

* Initial plan * Add comprehensive reasoning field standardization tests Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com> * Standardize reasoning field to OpenAI format while maintaining input compatibility Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com> * Rename reasoning_content parameter to reasoning for consistent naming Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com> * Address review comments: remove hardcoded path and rename reasoning_content to reasoning Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com>
2.0 KiB
2.0 KiB
Reasoning Field Standardization
Issue
DeepSeek uses "reasoning_content"
field while OpenAI uses "reasoning"
field in their chat completion streaming responses. This inconsistency caused confusion about what field name to use in the g4f Interference API.
Decision
Standardized on OpenAI's "reasoning"
field format for API output while maintaining input compatibility.
Rationale
- OpenAI Compatibility: OpenAI is the de facto standard for chat completion APIs
- Ecosystem Compatibility: Most tools and libraries expect OpenAI format
- Consistency: Provides a unified output format regardless of the underlying provider
- Backward Compatibility: Input parsing continues to accept both formats
Implementation
Input Format Support (Unchanged)
The system continues to accept both input formats in OpenaiTemplate.py
:
reasoning_content = choice.get("delta", {}).get("reasoning_content", choice.get("delta", {}).get("reasoning"))
Output Format Standardization (Changed)
- Streaming Delta: Uses
reasoning
field (OpenAI format) - Non-streaming Message: Uses
reasoning
field (OpenAI format) - API Responses: Should use standard OpenAI streaming format
Example Output Formats
Streaming Response (OpenAI Compatible)
{
"id": "chatcmpl-example",
"object": "chat.completion.chunk",
"choices": [{
"index": 0,
"delta": {
"role": "assistant",
"reasoning": "I need to think about this step by step..."
},
"finish_reason": null
}]
}
Non-streaming Response
{
"choices": [{
"message": {
"role": "assistant",
"content": "Here's my answer",
"reasoning": "My reasoning process was..."
}
}]
}
Files Changed
g4f/client/stubs.py
: Updated to usereasoning
field instead ofreasoning_content
Testing
- Added comprehensive tests for format standardization
- Verified input compatibility with both OpenAI and DeepSeek formats
- Confirmed no regressions in existing functionality