langchain[patch]: de-beta init_chat_model (#27558)

This commit is contained in:
Bagatur 2024-10-23 08:35:15 -07:00 committed by GitHub
parent 4466caadba
commit 217de4e6a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,7 +19,6 @@ from typing import (
overload, overload,
) )
from langchain_core._api import beta
from langchain_core.language_models import ( from langchain_core.language_models import (
BaseChatModel, BaseChatModel,
LanguageModelInput, LanguageModelInput,
@ -83,7 +82,6 @@ def init_chat_model(
# FOR CONTRIBUTORS: If adding support for a new provider, please append the provider # FOR CONTRIBUTORS: If adding support for a new provider, please append the provider
# name to the supported list in the docstring below. Do *not* change the order of the # name to the supported list in the docstring below. Do *not* change the order of the
# existing providers. # existing providers.
@beta()
def init_chat_model( def init_chat_model(
model: Optional[str] = None, model: Optional[str] = None,
*, *,
@ -96,38 +94,39 @@ def init_chat_model(
) -> Union[BaseChatModel, _ConfigurableModel]: ) -> Union[BaseChatModel, _ConfigurableModel]:
"""Initialize a ChatModel from the model name and provider. """Initialize a ChatModel from the model name and provider.
Must have the integration package corresponding to the model provider installed. **Note:** Must have the integration package corresponding to the model provider
installed.
Args: Args:
model: The name of the model, e.g. "gpt-4o", "claude-3-opus-20240229". model: The name of the model, e.g. "gpt-4o", "claude-3-opus-20240229".
model_provider: The model provider. Supported model_provider values and the model_provider: The model provider. Supported model_provider values and the
corresponding integration package: corresponding integration package are:
- openai (langchain-openai) - 'openai' -> langchain-openai
- anthropic (langchain-anthropic) - 'anthropic' -> langchain-anthropic
- azure_openai (langchain-openai) - 'azure_openai' -> langchain-openai
- google_vertexai (langchain-google-vertexai) - 'google_vertexai' -> langchain-google-vertexai
- google_genai (langchain-google-genai) - 'google_genai' -> langchain-google-genai
- bedrock (langchain-aws) - 'bedrock' -> langchain-aws
- bedrock_converse (langchain-aws) - 'bedrock_converse' -> langchain-aws
- cohere (langchain-cohere) - 'cohere' -> langchain-cohere
- fireworks (langchain-fireworks) - 'fireworks' -> langchain-fireworks
- together (langchain-together) - 'together' -> langchain-together
- mistralai (langchain-mistralai) - 'mistralai' -> langchain-mistralai
- huggingface (langchain-huggingface) - 'huggingface' -> langchain-huggingface
- groq (langchain-groq) - 'groq' -> langchain-groq
- ollama (langchain-ollama) [support added in langchain==0.2.12] - 'ollama' -> langchain-ollama
Will attempt to infer model_provider from model if not specified. The Will attempt to infer model_provider from model if not specified. The
following providers will be inferred based on these model prefixes: following providers will be inferred based on these model prefixes:
- gpt-3..., gpt-4..., or o1... -> openai - 'gpt-3...' | 'gpt-4...' | 'o1...' -> 'openai'
- claude... -> anthropic - 'claude...' -> 'anthropic'
- amazon.... -> bedrock - 'amazon....' -> 'bedrock'
- gemini... -> google_vertexai - 'gemini...' -> 'google_vertexai'
- command... -> cohere - 'command...' -> 'cohere'
- accounts/fireworks... -> fireworks - 'accounts/fireworks...' -> 'fireworks'
- mistral... -> mistralai - 'mistral...' -> 'mistralai'
configurable_fields: Which model parameters are configurable_fields: Which model parameters are
configurable: configurable:
@ -286,6 +285,10 @@ def init_chat_model(
Support for langchain_aws.ChatBedrockConverse added Support for langchain_aws.ChatBedrockConverse added
(model_provider="bedrock_converse"). (model_provider="bedrock_converse").
.. versionchanged:: 0.3.5
Out of beta.
""" # noqa: E501 """ # noqa: E501
if not model and not configurable_fields: if not model and not configurable_fields:
configurable_fields = ("model", "model_provider") configurable_fields = ("model", "model_provider")