Feature/OpenAI reasoning field #3533
Closed
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.
Support sending thinking parts in custom request fields for OpenAI-compatible models
Closes: #3446
This PR implements the ability to send reasoning/thinking content in a specific field of the request message (e.g.,
reasoning_content) for OpenAI-compatible providers that support it, such as Moonshot AI.Currently,
OpenAIChatModelembeds thinking parts into thecontentstring using tags (e.g.<think>...</think>). However, providers like Moonshot recommend sending this data in a separate field to allow the model to process context more effectively.Changes:
pydantic_ai_slim/pydantic_ai/profiles/openai.py: Addedopenai_chat_reasoning_fieldtoOpenAIModelProfile.pydantic_ai_slim/pydantic_ai/models/openai.py: UpdatedOpenAIChatModelto check this profile setting. If set,ThinkingPartcontent is collected and injected into the specified field of the message payload (e.g.,messages[i]['reasoning_content']) instead of being appended tocontent.pydantic_ai_slim/pydantic_ai/profiles/moonshotai.py: Updated the Moonshot AI profile to usereasoning_content.tests/models/test_openai.py: Addedtest_openai_chat_reasoning_fieldto verify that the extra field is correctly present in the API request arguments.