mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
style: address Sphinx double-backtick snippet syntax (#33389)
This commit is contained in:
@@ -84,7 +84,7 @@ def _get_default_httpx_client(
|
||||
) -> _SyncHttpxClientWrapper:
|
||||
"""Get default httpx client.
|
||||
|
||||
Uses cached client unless timeout is ``httpx.Timeout``, which is not hashable.
|
||||
Uses cached client unless timeout is `httpx.Timeout`, which is not hashable.
|
||||
"""
|
||||
try:
|
||||
hash(timeout)
|
||||
@@ -99,7 +99,7 @@ def _get_default_async_httpx_client(
|
||||
) -> _AsyncHttpxClientWrapper:
|
||||
"""Get default httpx client.
|
||||
|
||||
Uses cached client unless timeout is ``httpx.Timeout``, which is not hashable.
|
||||
Uses cached client unless timeout is `httpx.Timeout`, which is not hashable.
|
||||
"""
|
||||
try:
|
||||
hash(timeout)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"""Converts between AIMessage output formats, governed by ``output_version``.
|
||||
"""Converts between AIMessage output formats, governed by `output_version`.
|
||||
|
||||
``output_version`` is an attribute on ChatOpenAI.
|
||||
`output_version` is an attribute on ChatOpenAI.
|
||||
|
||||
Supported values are `None`, ``'v0'``, and ``'responses/v1'``.
|
||||
Supported values are `None`, `'v0'`, and `'responses/v1'`.
|
||||
|
||||
``'v0'`` corresponds to the format as of ``ChatOpenAI`` v0.3. For the Responses API, it
|
||||
stores reasoning and tool outputs in ``AIMessage.additional_kwargs``:
|
||||
`'v0'` corresponds to the format as of `ChatOpenAI` v0.3. For the Responses API, it
|
||||
stores reasoning and tool outputs in `AIMessage.additional_kwargs`:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -32,7 +32,7 @@ stores reasoning and tool outputs in ``AIMessage.additional_kwargs``:
|
||||
id="msg_123",
|
||||
)
|
||||
|
||||
``'responses/v1'`` is only applicable to the Responses API. It retains information
|
||||
`'responses/v1'` is only applicable to the Responses API. It retains information
|
||||
about response item sequencing and accommodates multiple reasoning items by
|
||||
representing these items in the content sequence:
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
to create your Azure OpenAI deployment.
|
||||
|
||||
Then install `langchain-openai` and set environment variables
|
||||
``AZURE_OPENAI_API_KEY`` and ``AZURE_OPENAI_ENDPOINT``:
|
||||
`AZURE_OPENAI_API_KEY` and `AZURE_OPENAI_ENDPOINT`:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
@@ -68,13 +68,13 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
Max number of retries.
|
||||
organization: str | None
|
||||
OpenAI organization ID. If not passed in will be read from env
|
||||
var ``OPENAI_ORG_ID``.
|
||||
var `OPENAI_ORG_ID`.
|
||||
model: str | None
|
||||
The name of the underlying OpenAI model. Used for tracing and token
|
||||
counting. Does not affect completion. E.g. ``'gpt-4'``, ``'gpt-35-turbo'``, etc.
|
||||
counting. Does not affect completion. E.g. `'gpt-4'`, `'gpt-35-turbo'`, etc.
|
||||
model_version: str | None
|
||||
The version of the underlying OpenAI model. Used for tracing and token
|
||||
counting. Does not affect completion. E.g., ``'0125'``, ``'0125-preview'``, etc.
|
||||
counting. Does not affect completion. E.g., `'0125'`, `'0125-preview'`, etc.
|
||||
|
||||
See full list of supported init args and their descriptions in the params section.
|
||||
|
||||
@@ -98,7 +98,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
|
||||
!!! note
|
||||
Any param which is not explicitly supported will be passed directly to the
|
||||
``openai.AzureOpenAI.chat.completions.create(...)`` API every time to the model is
|
||||
`openai.AzureOpenAI.chat.completions.create(...)` API every time to the model is
|
||||
invoked.
|
||||
|
||||
For example:
|
||||
@@ -314,7 +314,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
rating=None,
|
||||
)
|
||||
|
||||
See ``AzureChatOpenAI.with_structured_output()`` for more.
|
||||
See `AzureChatOpenAI.with_structured_output()` for more.
|
||||
|
||||
JSON mode:
|
||||
.. code-block:: python
|
||||
@@ -467,14 +467,14 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
)
|
||||
"""Your Azure endpoint, including the resource.
|
||||
|
||||
Automatically inferred from env var ``AZURE_OPENAI_ENDPOINT`` if not provided.
|
||||
Automatically inferred from env var `AZURE_OPENAI_ENDPOINT` if not provided.
|
||||
|
||||
Example: ``https://example-resource.azure.openai.com/``
|
||||
Example: `https://example-resource.azure.openai.com/`
|
||||
"""
|
||||
deployment_name: str | None = Field(default=None, alias="azure_deployment")
|
||||
"""A model deployment.
|
||||
|
||||
If given sets the base client URL to include ``/deployments/{azure_deployment}``
|
||||
If given sets the base client URL to include `/deployments/{azure_deployment}`
|
||||
|
||||
!!! note
|
||||
This means you won't be able to use non-deployment endpoints.
|
||||
@@ -483,7 +483,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
alias="api_version",
|
||||
default_factory=from_env("OPENAI_API_VERSION", default=None),
|
||||
)
|
||||
"""Automatically inferred from env var ``OPENAI_API_VERSION`` if not provided."""
|
||||
"""Automatically inferred from env var `OPENAI_API_VERSION` if not provided."""
|
||||
# Check OPENAI_API_KEY for backwards compatibility.
|
||||
# TODO: Remove OPENAI_API_KEY support to avoid possible conflict when using
|
||||
# other forms of azure credentials.
|
||||
@@ -493,13 +493,13 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
["AZURE_OPENAI_API_KEY", "OPENAI_API_KEY"], default=None
|
||||
),
|
||||
)
|
||||
"""Automatically inferred from env var ``AZURE_OPENAI_API_KEY`` if not provided."""
|
||||
"""Automatically inferred from env var `AZURE_OPENAI_API_KEY` if not provided."""
|
||||
azure_ad_token: SecretStr | None = Field(
|
||||
default_factory=secret_from_env("AZURE_OPENAI_AD_TOKEN", default=None)
|
||||
)
|
||||
"""Your Azure Active Directory token.
|
||||
|
||||
Automatically inferred from env var ``AZURE_OPENAI_AD_TOKEN`` if not provided.
|
||||
Automatically inferred from env var `AZURE_OPENAI_AD_TOKEN` if not provided.
|
||||
|
||||
For more, see [this page](https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id).
|
||||
"""
|
||||
@@ -507,7 +507,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
"""A function that returns an Azure Active Directory token.
|
||||
|
||||
Will be invoked on every sync request. For async requests,
|
||||
will be invoked if ``azure_ad_async_token_provider`` is not provided.
|
||||
will be invoked if `azure_ad_async_token_provider` is not provided.
|
||||
"""
|
||||
|
||||
azure_ad_async_token_provider: Callable[[], Awaitable[str]] | None = None
|
||||
@@ -517,7 +517,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
"""
|
||||
|
||||
model_version: str = ""
|
||||
"""The version of the model (e.g. ``'0125'`` for ``'gpt-3.5-0125'``).
|
||||
"""The version of the model (e.g. `'0125'` for `'gpt-3.5-0125'`).
|
||||
|
||||
Azure OpenAI doesn't return model version with the response by default so it must
|
||||
be manually specified if you want to use this information downstream, e.g. when
|
||||
@@ -532,15 +532,15 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
openai_api_type: str | None = Field(
|
||||
default_factory=from_env("OPENAI_API_TYPE", default="azure")
|
||||
)
|
||||
"""Legacy, for ``openai<1.0.0`` support."""
|
||||
"""Legacy, for `openai<1.0.0` support."""
|
||||
|
||||
validate_base_url: bool = True
|
||||
"""If legacy arg ``openai_api_base`` is passed in, try to infer if it is a
|
||||
``base_url`` or ``azure_endpoint`` and update client params accordingly.
|
||||
"""If legacy arg `openai_api_base` is passed in, try to infer if it is a
|
||||
`base_url` or `azure_endpoint` and update client params accordingly.
|
||||
"""
|
||||
|
||||
model_name: str | None = Field(default=None, alias="model") # type: ignore[assignment]
|
||||
"""Name of the deployed OpenAI model, e.g. ``'gpt-4o'``, ``'gpt-35-turbo'``, etc.
|
||||
"""Name of the deployed OpenAI model, e.g. `'gpt-4o'`, `'gpt-35-turbo'`, etc.
|
||||
|
||||
Distinct from the Azure deployment name, which is set by the Azure user.
|
||||
Used for tracing and token counting.
|
||||
@@ -553,12 +553,12 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
"""Parameters of the OpenAI client or chat.completions endpoint that should be
|
||||
disabled for the given model.
|
||||
|
||||
Should be specified as ``{"param": None | ['val1', 'val2']}`` where the key is the
|
||||
Should be specified as `{"param": None | ['val1', 'val2']}` where the key is the
|
||||
parameter and the value is either None, meaning that parameter should never be
|
||||
used, or it's a list of disabled values for the parameter.
|
||||
|
||||
For example, older models may not support the ``'parallel_tool_calls'`` parameter at
|
||||
all, in which case ``disabled_params={"parallel_tool_calls: None}`` can ben passed
|
||||
For example, older models may not support the `'parallel_tool_calls'` parameter at
|
||||
all, in which case `disabled_params={"parallel_tool_calls: None}` can ben passed
|
||||
in.
|
||||
|
||||
If a parameter is disabled then it will not be used by default in any methods, e.g.
|
||||
@@ -567,8 +567,8 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
However this does not prevent a user from directly passed in the parameter during
|
||||
invocation.
|
||||
|
||||
By default, unless ``model_name="gpt-4o"`` is specified, then
|
||||
``'parallel_tools_calls'`` will be disabled.
|
||||
By default, unless `model_name="gpt-4o"` is specified, then
|
||||
`'parallel_tools_calls'` will be disabled.
|
||||
"""
|
||||
|
||||
max_tokens: int | None = Field(default=None, alias="max_completion_tokens") # type: ignore[assignment]
|
||||
@@ -842,7 +842,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
- or a Pydantic class,
|
||||
- an OpenAI function/tool schema.
|
||||
|
||||
If ``schema`` is a Pydantic class then the model output will be a
|
||||
If `schema` is a Pydantic class then the model output will be a
|
||||
Pydantic instance of that class, and the model-generated fields will be
|
||||
validated by the Pydantic class. Otherwise the model output will be a
|
||||
dict and will not be validated. See `langchain_core.utils.function_calling.convert_to_openai_tool`
|
||||
@@ -851,14 +851,14 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
|
||||
method: The method for steering model generation, one of:
|
||||
|
||||
- ``'json_schema'``:
|
||||
- `'json_schema'`:
|
||||
Uses OpenAI's [Structured Output API](https://platform.openai.com/docs/guides/structured-outputs).
|
||||
Supported for ``'gpt-4o-mini'``, ``'gpt-4o-2024-08-06'``, ``'o1'``, and later
|
||||
Supported for `'gpt-4o-mini'`, `'gpt-4o-2024-08-06'`, `'o1'`, and later
|
||||
models.
|
||||
- ``'function_calling'``:
|
||||
- `'function_calling'`:
|
||||
Uses OpenAI's tool-calling (formerly called function calling)
|
||||
[API](https://platform.openai.com/docs/guides/function-calling)
|
||||
- ``'json_mode'``:
|
||||
- `'json_mode'`:
|
||||
Uses OpenAI's [JSON mode](https://platform.openai.com/docs/guides/structured-outputs/json-mode).
|
||||
Note that if using JSON mode then you must include instructions for
|
||||
formatting the output into the desired schema into the model call
|
||||
@@ -872,7 +872,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
then both the raw model response (a BaseMessage) and the parsed model
|
||||
response will be returned. If an error occurs during output parsing it
|
||||
will be caught and returned as well. The final output is always a dict
|
||||
with keys ``'raw'``, ``'parsed'``, and ``'parsing_error'``.
|
||||
with keys `'raw'`, `'parsed'`, and `'parsing_error'`.
|
||||
strict:
|
||||
|
||||
- True:
|
||||
@@ -882,23 +882,23 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
Input schema will not be validated and model output will not be
|
||||
validated.
|
||||
- None:
|
||||
``strict`` argument will not be passed to the model.
|
||||
`strict` argument will not be passed to the model.
|
||||
|
||||
If schema is specified via TypedDict or JSON schema, ``strict`` is not
|
||||
enabled by default. Pass ``strict=True`` to enable it.
|
||||
If schema is specified via TypedDict or JSON schema, `strict` is not
|
||||
enabled by default. Pass `strict=True` to enable it.
|
||||
|
||||
!!! note
|
||||
``strict`` can only be non-null if ``method`` is ``'json_schema'``
|
||||
or ``'function_calling'``.
|
||||
`strict` can only be non-null if `method` is `'json_schema'`
|
||||
or `'function_calling'`.
|
||||
tools:
|
||||
A list of tool-like objects to bind to the chat model. Requires that:
|
||||
|
||||
- ``method`` is ``'json_schema'`` (default).
|
||||
- ``strict=True``
|
||||
- ``include_raw=True``
|
||||
- `method` is `'json_schema'` (default).
|
||||
- `strict=True`
|
||||
- `include_raw=True`
|
||||
|
||||
If a model elects to call a
|
||||
tool, the resulting `AIMessage` in ``'raw'`` will include tool calls.
|
||||
tool, the resulting `AIMessage` in `'raw'` will include tool calls.
|
||||
|
||||
??? example
|
||||
|
||||
@@ -940,35 +940,35 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
||||
Returns:
|
||||
A Runnable that takes same inputs as a `langchain_core.language_models.chat.BaseChatModel`.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
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'``: BaseException | None
|
||||
- `'raw'`: BaseMessage
|
||||
- `'parsed'`: None if there was a parsing error, otherwise the type depends on the `schema` as described above.
|
||||
- `'parsing_error'`: BaseException | None
|
||||
|
||||
!!! warning "Behavior changed in 0.1.20"
|
||||
Added support for TypedDict class ``schema``.
|
||||
Added support for TypedDict class `schema`.
|
||||
|
||||
!!! warning "Behavior changed in 0.1.21"
|
||||
Support for ``strict`` argument added.
|
||||
Support for ``method="json_schema"`` added.
|
||||
Support for `strict` argument added.
|
||||
Support for `method="json_schema"` added.
|
||||
|
||||
!!! warning "Behavior changed in 0.3.0"
|
||||
``method`` default changed from "function_calling" to "json_schema".
|
||||
`method` default changed from "function_calling" to "json_schema".
|
||||
|
||||
!!! warning "Behavior changed in 0.3.12"
|
||||
Support for `tools` added.
|
||||
|
||||
!!! warning "Behavior changed in 0.3.21"
|
||||
Pass ``kwargs`` through to the model.
|
||||
Pass `kwargs` through to the model.
|
||||
|
||||
??? note "Example: `schema=Pydantic` class, `method='json_schema'`, `include_raw=False`, `strict=True`"
|
||||
|
||||
Note, OpenAI has a number of restrictions on what types of schemas can be
|
||||
provided if ``strict`` = True. When using Pydantic, our model cannot
|
||||
provided if `strict` = True. When using Pydantic, our model cannot
|
||||
specify any Field metadata (like min/max constraints) and fields cannot
|
||||
have default values.
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ class AzureOpenAIEmbeddings(OpenAIEmbeddings): # type: ignore[override]
|
||||
.. code-block:: python
|
||||
|
||||
vector = await embed.aembed_query(input_text)
|
||||
print(vector[:3])
|
||||
print(vector[:3])
|
||||
|
||||
# multiple:
|
||||
# await embed.aembed_documents(input_texts)
|
||||
@@ -107,7 +107,7 @@ class AzureOpenAIEmbeddings(OpenAIEmbeddings): # type: ignore[override]
|
||||
)
|
||||
"""Your Azure endpoint, including the resource.
|
||||
|
||||
Automatically inferred from env var ``AZURE_OPENAI_ENDPOINT`` if not provided.
|
||||
Automatically inferred from env var `AZURE_OPENAI_ENDPOINT` if not provided.
|
||||
|
||||
Example: `https://example-resource.azure.openai.com/`
|
||||
"""
|
||||
@@ -129,14 +129,14 @@ class AzureOpenAIEmbeddings(OpenAIEmbeddings): # type: ignore[override]
|
||||
["AZURE_OPENAI_API_KEY", "OPENAI_API_KEY"], default=None
|
||||
),
|
||||
)
|
||||
"""Automatically inferred from env var ``AZURE_OPENAI_API_KEY`` if not provided."""
|
||||
"""Automatically inferred from env var `AZURE_OPENAI_API_KEY` if not provided."""
|
||||
openai_api_version: str | None = Field(
|
||||
default_factory=from_env("OPENAI_API_VERSION", default="2023-05-15"),
|
||||
alias="api_version",
|
||||
)
|
||||
"""Automatically inferred from env var ``OPENAI_API_VERSION`` if not provided.
|
||||
"""Automatically inferred from env var `OPENAI_API_VERSION` if not provided.
|
||||
|
||||
Set to ``'2023-05-15'`` by default if env variable ``OPENAI_API_VERSION`` is not
|
||||
Set to `'2023-05-15'` by default if env variable `OPENAI_API_VERSION` is not
|
||||
set.
|
||||
"""
|
||||
azure_ad_token: SecretStr | None = Field(
|
||||
@@ -144,7 +144,7 @@ class AzureOpenAIEmbeddings(OpenAIEmbeddings): # type: ignore[override]
|
||||
)
|
||||
"""Your Azure Active Directory token.
|
||||
|
||||
Automatically inferred from env var ``AZURE_OPENAI_AD_TOKEN`` if not provided.
|
||||
Automatically inferred from env var `AZURE_OPENAI_AD_TOKEN` if not provided.
|
||||
|
||||
[For more, see this page.](https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id)
|
||||
"""
|
||||
@@ -152,7 +152,7 @@ class AzureOpenAIEmbeddings(OpenAIEmbeddings): # type: ignore[override]
|
||||
"""A function that returns an Azure Active Directory token.
|
||||
|
||||
Will be invoked on every sync request. For async requests,
|
||||
will be invoked if ``azure_ad_async_token_provider`` is not provided.
|
||||
will be invoked if `azure_ad_async_token_provider` is not provided.
|
||||
"""
|
||||
azure_ad_async_token_provider: Callable[[], Awaitable[str]] | None = None
|
||||
"""A function that returns an Azure Active Directory token.
|
||||
|
||||
@@ -82,7 +82,7 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
|
||||
"""OpenAI embedding model integration.
|
||||
|
||||
Setup:
|
||||
Install ``langchain_openai`` and set environment variable ``OPENAI_API_KEY``.
|
||||
Install `langchain_openai` and set environment variable `OPENAI_API_KEY`.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
@@ -94,14 +94,14 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
|
||||
Name of OpenAI model to use.
|
||||
dimensions: int | None = None
|
||||
The number of dimensions the resulting output embeddings should have.
|
||||
Only supported in ``'text-embedding-3'`` and later models.
|
||||
Only supported in `'text-embedding-3'` and later models.
|
||||
|
||||
Key init args — client params:
|
||||
api_key: SecretStr | None = None
|
||||
OpenAI API key.
|
||||
organization: str | None = None
|
||||
OpenAI organization ID. If not passed in will be read
|
||||
from env var ``OPENAI_ORG_ID``.
|
||||
from env var `OPENAI_ORG_ID`.
|
||||
max_retries: int = 2
|
||||
Maximum number of retries to make when generating.
|
||||
request_timeout: float | Tuple[float, float] | Any | None = None
|
||||
@@ -196,14 +196,14 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
|
||||
openai_api_key: SecretStr | None = Field(
|
||||
alias="api_key", default_factory=secret_from_env("OPENAI_API_KEY", default=None)
|
||||
)
|
||||
"""Automatically inferred from env var ``OPENAI_API_KEY`` if not provided."""
|
||||
"""Automatically inferred from env var `OPENAI_API_KEY` if not provided."""
|
||||
openai_organization: str | None = Field(
|
||||
alias="organization",
|
||||
default_factory=from_env(
|
||||
["OPENAI_ORG_ID", "OPENAI_ORGANIZATION"], default=None
|
||||
),
|
||||
)
|
||||
"""Automatically inferred from env var ``OPENAI_ORG_ID`` if not provided."""
|
||||
"""Automatically inferred from env var `OPENAI_ORG_ID` if not provided."""
|
||||
allowed_special: Literal["all"] | set[str] | None = None
|
||||
disallowed_special: Literal["all"] | set[str] | Sequence[str] | None = None
|
||||
chunk_size: int = 1000
|
||||
@@ -213,12 +213,12 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
|
||||
request_timeout: float | tuple[float, float] | Any | None = Field(
|
||||
default=None, alias="timeout"
|
||||
)
|
||||
"""Timeout for requests to OpenAI completion API. Can be float, ``httpx.Timeout`` or
|
||||
"""Timeout for requests to OpenAI completion API. Can be float, `httpx.Timeout` or
|
||||
None."""
|
||||
headers: Any = None
|
||||
tiktoken_enabled: bool = True
|
||||
"""Set this to False for non-OpenAI implementations of the embeddings API, e.g.
|
||||
the ``--extensions openai`` extension for ``text-generation-webui``"""
|
||||
the `--extensions openai` extension for `text-generation-webui`"""
|
||||
tiktoken_model_name: str | None = None
|
||||
"""The model name to pass to tiktoken when using this class.
|
||||
Tiktoken is used to count the number of tokens in documents to constrain
|
||||
@@ -245,13 +245,13 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
|
||||
retry_max_seconds: int = 20
|
||||
"""Max number of seconds to wait between retries"""
|
||||
http_client: Any | None = None
|
||||
"""Optional ``httpx.Client``. Only used for sync invocations. Must specify
|
||||
``http_async_client`` as well if you'd like a custom client for async
|
||||
"""Optional `httpx.Client`. Only used for sync invocations. Must specify
|
||||
`http_async_client` as well if you'd like a custom client for async
|
||||
invocations.
|
||||
"""
|
||||
http_async_client: Any | None = None
|
||||
"""Optional ``httpx.AsyncClient``. Only used for async invocations. Must specify
|
||||
``http_client`` as well if you'd like a custom client for sync invocations."""
|
||||
"""Optional `httpx.AsyncClient`. Only used for async invocations. Must specify
|
||||
`http_client` as well if you'd like a custom client for sync invocations."""
|
||||
check_embedding_ctx_length: bool = True
|
||||
"""Whether to check the token length of inputs and automatically split inputs
|
||||
longer than embedding_ctx_length."""
|
||||
|
||||
@@ -21,7 +21,7 @@ class AzureOpenAI(BaseOpenAI):
|
||||
"""Azure-specific OpenAI large language models.
|
||||
|
||||
To use, you should have the `openai` python package installed, and the
|
||||
environment variable ``OPENAI_API_KEY`` set with your API key.
|
||||
environment variable `OPENAI_API_KEY` set with your API key.
|
||||
|
||||
Any parameters that are valid to be passed to the openai.create call can be passed
|
||||
in, even if not explicitly saved on this class.
|
||||
@@ -40,9 +40,9 @@ class AzureOpenAI(BaseOpenAI):
|
||||
)
|
||||
"""Your Azure endpoint, including the resource.
|
||||
|
||||
Automatically inferred from env var ``AZURE_OPENAI_ENDPOINT`` if not provided.
|
||||
Automatically inferred from env var `AZURE_OPENAI_ENDPOINT` if not provided.
|
||||
|
||||
Example: ``'https://example-resource.azure.openai.com/'``
|
||||
Example: `'https://example-resource.azure.openai.com/'`
|
||||
"""
|
||||
deployment_name: str | None = Field(default=None, alias="azure_deployment")
|
||||
"""A model deployment.
|
||||
@@ -57,7 +57,7 @@ class AzureOpenAI(BaseOpenAI):
|
||||
alias="api_version",
|
||||
default_factory=from_env("OPENAI_API_VERSION", default=None),
|
||||
)
|
||||
"""Automatically inferred from env var ``OPENAI_API_VERSION`` if not provided."""
|
||||
"""Automatically inferred from env var `OPENAI_API_VERSION` if not provided."""
|
||||
# Check OPENAI_KEY for backwards compatibility.
|
||||
# TODO: Remove OPENAI_API_KEY support to avoid possible conflict when using
|
||||
# other forms of azure credentials.
|
||||
@@ -72,7 +72,7 @@ class AzureOpenAI(BaseOpenAI):
|
||||
)
|
||||
"""Your Azure Active Directory token.
|
||||
|
||||
Automatically inferred from env var ``AZURE_OPENAI_AD_TOKEN`` if not provided.
|
||||
Automatically inferred from env var `AZURE_OPENAI_AD_TOKEN` if not provided.
|
||||
|
||||
`For more, see this page <https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id>.`__
|
||||
"""
|
||||
@@ -80,7 +80,7 @@ class AzureOpenAI(BaseOpenAI):
|
||||
"""A function that returns an Azure Active Directory token.
|
||||
|
||||
Will be invoked on every sync request. For async requests,
|
||||
will be invoked if ``azure_ad_async_token_provider`` is not provided.
|
||||
will be invoked if `azure_ad_async_token_provider` is not provided.
|
||||
"""
|
||||
azure_ad_async_token_provider: Callable[[], Awaitable[str]] | None = None
|
||||
"""A function that returns an Azure Active Directory token.
|
||||
@@ -90,7 +90,7 @@ class AzureOpenAI(BaseOpenAI):
|
||||
openai_api_type: str | None = Field(
|
||||
default_factory=from_env("OPENAI_API_TYPE", default="azure")
|
||||
)
|
||||
"""Legacy, for ``openai<1.0.0`` support."""
|
||||
"""Legacy, for `openai<1.0.0` support."""
|
||||
validate_base_url: bool = True
|
||||
"""For backwards compatibility. If legacy val openai_api_base is passed in, try to
|
||||
infer if it is a base_url or azure_endpoint and update accordingly.
|
||||
|
||||
@@ -54,7 +54,7 @@ class BaseOpenAI(BaseLLM):
|
||||
"""Base OpenAI large language model class.
|
||||
|
||||
Setup:
|
||||
Install `langchain-openai` and set environment variable ``OPENAI_API_KEY``.
|
||||
Install `langchain-openai` and set environment variable `OPENAI_API_KEY`.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
@@ -90,13 +90,13 @@ class BaseOpenAI(BaseLLM):
|
||||
Key init args — client params:
|
||||
openai_api_key: SecretStr | None
|
||||
OpenAI API key. If not passed in will be read from env var
|
||||
``OPENAI_API_KEY``.
|
||||
`OPENAI_API_KEY`.
|
||||
openai_api_base: str | None
|
||||
Base URL path for API requests, leave blank if not using a proxy or
|
||||
service emulator.
|
||||
openai_organization: str | None
|
||||
OpenAI organization ID. If not passed in will be read from env
|
||||
var ``OPENAI_ORG_ID``.
|
||||
var `OPENAI_ORG_ID`.
|
||||
request_timeout: Union[float, tuple[float, float], Any, None]
|
||||
Timeout for requests to OpenAI completion API.
|
||||
max_retries: int
|
||||
@@ -191,7 +191,7 @@ class BaseOpenAI(BaseLLM):
|
||||
openai_api_key: SecretStr | None = Field(
|
||||
alias="api_key", default_factory=secret_from_env("OPENAI_API_KEY", default=None)
|
||||
)
|
||||
"""Automatically inferred from env var ``OPENAI_API_KEY`` if not provided."""
|
||||
"""Automatically inferred from env var `OPENAI_API_KEY` if not provided."""
|
||||
openai_api_base: str | None = Field(
|
||||
alias="base_url", default_factory=from_env("OPENAI_API_BASE", default=None)
|
||||
)
|
||||
@@ -203,7 +203,7 @@ class BaseOpenAI(BaseLLM):
|
||||
["OPENAI_ORG_ID", "OPENAI_ORGANIZATION"], default=None
|
||||
),
|
||||
)
|
||||
"""Automatically inferred from env var ``OPENAI_ORG_ID`` if not provided."""
|
||||
"""Automatically inferred from env var `OPENAI_ORG_ID` if not provided."""
|
||||
# to support explicit proxy for OpenAI
|
||||
openai_proxy: str | None = Field(
|
||||
default_factory=from_env("OPENAI_PROXY", default=None)
|
||||
@@ -213,7 +213,7 @@ class BaseOpenAI(BaseLLM):
|
||||
request_timeout: float | tuple[float, float] | Any | None = Field(
|
||||
default=None, alias="timeout"
|
||||
)
|
||||
"""Timeout for requests to OpenAI completion API. Can be float, ``httpx.Timeout`` or
|
||||
"""Timeout for requests to OpenAI completion API. Can be float, `httpx.Timeout` or
|
||||
None."""
|
||||
logit_bias: dict[str, float] | None = None
|
||||
"""Adjust the probability of specific tokens being generated."""
|
||||
@@ -245,13 +245,13 @@ class BaseOpenAI(BaseLLM):
|
||||
# Configure a custom httpx client. See the
|
||||
# [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
|
||||
http_client: Any | None = None
|
||||
"""Optional ``httpx.Client``. Only used for sync invocations. Must specify
|
||||
``http_async_client`` as well if you'd like a custom client for async
|
||||
"""Optional `httpx.Client`. Only used for sync invocations. Must specify
|
||||
`http_async_client` as well if you'd like a custom client for async
|
||||
invocations.
|
||||
"""
|
||||
http_async_client: Any | None = None
|
||||
"""Optional ``httpx.AsyncClient``. Only used for async invocations. Must specify
|
||||
``http_client`` as well if you'd like a custom client for sync invocations."""
|
||||
"""Optional `httpx.AsyncClient`. Only used for async invocations. Must specify
|
||||
`http_client` as well if you'd like a custom client for sync invocations."""
|
||||
extra_body: Mapping[str, Any] | None = None
|
||||
"""Optional additional JSON properties to include in the request parameters when
|
||||
making requests to OpenAI compatible APIs, such as vLLM."""
|
||||
@@ -704,7 +704,7 @@ class OpenAI(BaseOpenAI):
|
||||
"""OpenAI completion model integration.
|
||||
|
||||
Setup:
|
||||
Install `langchain-openai` and set environment variable ``OPENAI_API_KEY``.
|
||||
Install `langchain-openai` and set environment variable `OPENAI_API_KEY`.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
@@ -722,7 +722,7 @@ class OpenAI(BaseOpenAI):
|
||||
Whether to return logprobs.
|
||||
stream_options: Dict
|
||||
Configure streaming outputs, like whether to return token usage when
|
||||
streaming (``{"include_usage": True}``).
|
||||
streaming (`{"include_usage": True}`).
|
||||
|
||||
Key init args — client params:
|
||||
timeout: Union[float, Tuple[float, float], Any, None]
|
||||
@@ -730,13 +730,13 @@ class OpenAI(BaseOpenAI):
|
||||
max_retries: int
|
||||
Max number of retries.
|
||||
api_key: str | None
|
||||
OpenAI API key. If not passed in will be read from env var ``OPENAI_API_KEY``.
|
||||
OpenAI API key. If not passed in will be read from env var `OPENAI_API_KEY`.
|
||||
base_url: str | None
|
||||
Base URL for API requests. Only specify if using a proxy or service
|
||||
emulator.
|
||||
organization: str | None
|
||||
OpenAI organization ID. If not passed in will be read from env
|
||||
var ``OPENAI_ORG_ID``.
|
||||
var `OPENAI_ORG_ID`.
|
||||
|
||||
See full list of supported init args and their descriptions in the params section.
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ def custom_tool(*args: Any, **kwargs: Any) -> Any:
|
||||
step["messages"][-1].pretty_print()
|
||||
|
||||
You can also specify a format for a corresponding context-free grammar using the
|
||||
``format`` kwarg:
|
||||
`format` kwarg:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
||||
Reference in New Issue
Block a user