mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-03 03:59:42 +00:00
docs: document OpenAI reasoning summaries (#30882)
This commit is contained in:
@@ -2132,6 +2132,40 @@ class ChatOpenAI(BaseChatOpenAI): # type: ignore[override]
|
||||
|
||||
"Your name is Bob. How can I help you today, Bob?"
|
||||
|
||||
.. dropdown:: Reasoning output
|
||||
|
||||
OpenAI's Responses API supports `reasoning models <https://platform.openai.com/docs/guides/reasoning?api-mode=responses>`_
|
||||
that expose a summary of internal reasoning processes.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from langchain_openai import ChatOpenAI
|
||||
|
||||
reasoning = {
|
||||
"effort": "medium", # 'low', 'medium', or 'high'
|
||||
"summary": "auto", # 'detailed', 'auto', or None
|
||||
}
|
||||
|
||||
llm = ChatOpenAI(
|
||||
model="o4-mini", use_responses_api=True, model_kwargs={"reasoning": reasoning}
|
||||
)
|
||||
response = llm.invoke("What is 3^3?")
|
||||
|
||||
print(f"Output: {response.text()}")
|
||||
print(f"Reasoning: {response.additional_kwargs['reasoning']}")
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
Output: 3^3 = 27.
|
||||
|
||||
Reasoning: {
|
||||
'id': 'rs_67fffc44b1c08191b6ca9bead6d832590433145b1786f809',
|
||||
'summary': [
|
||||
{'text': 'The user wants to know...', 'type': 'summary_text'}
|
||||
],
|
||||
'type': 'reasoning'
|
||||
}
|
||||
|
||||
.. dropdown:: Structured output
|
||||
|
||||
.. code-block:: python
|
||||
|
Reference in New Issue
Block a user