mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-01 19:12:42 +00:00
docs: fix openai api ref (#25639)
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1120,7 +1120,6 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
Args:
|
Args:
|
||||||
schema:
|
schema:
|
||||||
The output schema. Can be passed in as:
|
The output schema. Can be passed in as:
|
||||||
|
|
||||||
- an OpenAI function/tool schema,
|
- an OpenAI function/tool schema,
|
||||||
- a JSON Schema,
|
- a JSON Schema,
|
||||||
- a TypedDict class (support added in 0.1.20),
|
- a TypedDict class (support added in 0.1.20),
|
||||||
@@ -1138,7 +1137,6 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
|
|
||||||
method:
|
method:
|
||||||
The method for steering model generation, one of:
|
The method for steering model generation, one of:
|
||||||
|
|
||||||
- "function_calling":
|
- "function_calling":
|
||||||
Uses OpenAI's tool-calling (formerly called function calling)
|
Uses OpenAI's tool-calling (formerly called function calling)
|
||||||
API: https://platform.openai.com/docs/guides/function-calling
|
API: https://platform.openai.com/docs/guides/function-calling
|
||||||
@@ -1156,8 +1154,8 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
Learn more about the differences between the methods and which models
|
Learn more about the differences between the methods and which models
|
||||||
support which methods here:
|
support which methods here:
|
||||||
|
|
||||||
- https://platform.openai.com/docs/guides/structured-outputs/structured-outputs-vs-json-mode
|
- https://platform.openai.com/docs/guides/structured-outputs/structured-outputs-vs-json-mode
|
||||||
- https://platform.openai.com/docs/guides/structured-outputs/function-calling-vs-response-format
|
- https://platform.openai.com/docs/guides/structured-outputs/function-calling-vs-response-format
|
||||||
|
|
||||||
.. versionchanged:: 0.1.21
|
.. versionchanged:: 0.1.21
|
||||||
|
|
||||||
@@ -1200,26 +1198,22 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
Returns:
|
Returns:
|
||||||
A Runnable that takes same inputs as a :class:`langchain_core.language_models.chat.BaseChatModel`.
|
A Runnable that takes same inputs as a :class:`langchain_core.language_models.chat.BaseChatModel`.
|
||||||
|
|
||||||
If ``include_raw`` is False and ``schema`` is a Pydantic class, Runnable outputs
|
| If ``include_raw`` is False and ``schema`` is a Pydantic class, Runnable outputs an instance of ``schema`` (i.e., a Pydantic object). Otherwise, if ``include_raw`` is False then Runnable outputs a dict.
|
||||||
an instance of ``schema`` (i.e., a Pydantic object).
|
|
||||||
|
|
||||||
Otherwise, if ``include_raw`` is False then Runnable outputs a dict.
|
| If ``include_raw`` is True, then Runnable outputs a dict with keys:
|
||||||
|
|
||||||
If ``include_raw`` is True, then Runnable outputs a dict with keys:
|
- "raw": BaseMessage
|
||||||
|
- "parsed": None if there was a parsing error, otherwise the type depends on the ``schema`` as described above.
|
||||||
|
- "parsing_error": Optional[BaseException]
|
||||||
|
|
||||||
- "raw": BaseMessage
|
.. dropdown:: Example: schema=Pydantic class, method="function_calling", include_raw=False, strict=True
|
||||||
- "parsed": None if there was a parsing error, otherwise the type depends on the ``schema`` as described above.
|
|
||||||
- "parsing_error": Optional[BaseException]
|
|
||||||
|
|
||||||
Example: schema=Pydantic class, method="function_calling", include_raw=False, strict=True:
|
Note, OpenAI has a number of restrictions on what types of schemas can be
|
||||||
.. note:: Valid schemas when using ``strict`` = True
|
provided if ``strict`` = True. When using Pydantic, our model cannot
|
||||||
|
specify any Field metadata (like min/max constraints) and fields cannot
|
||||||
|
have default values.
|
||||||
|
|
||||||
OpenAI has a number of restrictions on what types of schemas can be
|
See all constraints here: https://platform.openai.com/docs/guides/structured-outputs/supported-schemas
|
||||||
provided if ``strict`` = True. When using Pydantic, our model cannot
|
|
||||||
specify any Field metadata (like min/max constraints) and fields cannot
|
|
||||||
have default values.
|
|
||||||
|
|
||||||
See all constraints here: https://platform.openai.com/docs/guides/structured-outputs/supported-schemas
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
@@ -1252,7 +1246,8 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
# justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'
|
# justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'
|
||||||
# )
|
# )
|
||||||
|
|
||||||
Example: schema=Pydantic class, method="function_calling", include_raw=True:
|
.. dropdown:: Example: schema=Pydantic class, method="function_calling", include_raw=True
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from langchain_openai import ChatOpenAI
|
from langchain_openai import ChatOpenAI
|
||||||
@@ -1280,7 +1275,8 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
# 'parsing_error': None
|
# 'parsing_error': None
|
||||||
# }
|
# }
|
||||||
|
|
||||||
Example: schema=TypedDict class, method="function_calling", include_raw=False:
|
.. dropdown:: Example: schema=TypedDict class, method="function_calling", include_raw=False
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# IMPORTANT: If you are using Python <=3.8, you need to import Annotated
|
# IMPORTANT: If you are using Python <=3.8, you need to import Annotated
|
||||||
@@ -1310,7 +1306,8 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
|
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
|
||||||
# }
|
# }
|
||||||
|
|
||||||
Example: schema=OpenAI function schema, method="function_calling", include_raw=False:
|
.. dropdown:: Example: schema=OpenAI function schema, method="function_calling", include_raw=False
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from langchain_openai import ChatOpenAI
|
from langchain_openai import ChatOpenAI
|
||||||
@@ -1339,7 +1336,8 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
|
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
|
||||||
# }
|
# }
|
||||||
|
|
||||||
Example: schema=Pydantic class, method="json_mode", include_raw=True:
|
.. dropdown:: Example: schema=Pydantic class, method="json_mode", include_raw=True
|
||||||
|
|
||||||
.. code-block::
|
.. code-block::
|
||||||
|
|
||||||
from langchain_openai import ChatOpenAI
|
from langchain_openai import ChatOpenAI
|
||||||
@@ -1367,7 +1365,8 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
# 'parsing_error': None
|
# 'parsing_error': None
|
||||||
# }
|
# }
|
||||||
|
|
||||||
Example: schema=None, method="json_mode", include_raw=True:
|
.. dropdown:: Example: schema=None, method="json_mode", include_raw=True
|
||||||
|
|
||||||
.. code-block::
|
.. code-block::
|
||||||
|
|
||||||
structured_llm = llm.with_structured_output(method="json_mode", include_raw=True)
|
structured_llm = llm.with_structured_output(method="json_mode", include_raw=True)
|
||||||
|
Reference in New Issue
Block a user