2023-12-11 21:53:30 +00:00
|
|
|
"""**Chat Models** are a variation on language models.
|
|
|
|
|
|
|
|
While Chat Models use language models under the hood, the interface they expose
|
|
|
|
is a bit different. Rather than expose a "text in, text out" API, they expose
|
|
|
|
an interface where "chat messages" are the inputs and outputs.
|
|
|
|
|
|
|
|
**Class hierarchy:**
|
|
|
|
|
|
|
|
.. code-block::
|
|
|
|
|
|
|
|
BaseLanguageModel --> BaseChatModel --> <name> # Examples: ChatOpenAI, ChatGooglePalm
|
|
|
|
|
|
|
|
**Main helpers:**
|
|
|
|
|
|
|
|
.. code-block::
|
|
|
|
|
|
|
|
AIMessage, BaseMessage, HumanMessage
|
|
|
|
""" # noqa: E501
|
|
|
|
|
2024-03-11 20:37:36 +00:00
|
|
|
import importlib
|
2024-04-10 17:01:19 +00:00
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from langchain_community.chat_models.anthropic import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatAnthropic,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.anyscale import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatAnyscale,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.azure_openai import (
|
2024-04-30 17:13:48 +00:00
|
|
|
AzureChatOpenAI,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.baichuan import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatBaichuan,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.baidu_qianfan_endpoint import (
|
2024-04-30 17:13:48 +00:00
|
|
|
QianfanChatEndpoint,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.bedrock import (
|
2024-04-30 17:13:48 +00:00
|
|
|
BedrockChat,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.cohere import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatCohere,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
2024-04-29 16:26:16 +00:00
|
|
|
from langchain_community.chat_models.coze import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatCoze,
|
2024-04-29 16:26:16 +00:00
|
|
|
)
|
2024-04-10 17:01:19 +00:00
|
|
|
from langchain_community.chat_models.databricks import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatDatabricks,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.deepinfra import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatDeepInfra,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.ernie import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ErnieBotChat,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.everlyai import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatEverlyAI,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.fake import (
|
2024-04-30 17:13:48 +00:00
|
|
|
FakeListChatModel,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.fireworks import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatFireworks,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.friendli import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatFriendli,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.gigachat import (
|
2024-04-30 17:13:48 +00:00
|
|
|
GigaChat,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.google_palm import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatGooglePalm,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.gpt_router import (
|
2024-04-30 17:13:48 +00:00
|
|
|
GPTRouter,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.huggingface import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatHuggingFace,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.human import (
|
2024-04-30 17:13:48 +00:00
|
|
|
HumanInputChatModel,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.hunyuan import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatHunyuan,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.javelin_ai_gateway import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatJavelinAIGateway,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.jinachat import (
|
2024-04-30 17:13:48 +00:00
|
|
|
JinaChat,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.kinetica import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatKinetica,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.konko import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatKonko,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.litellm import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatLiteLLM,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.litellm_router import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatLiteLLMRouter,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.llama_edge import (
|
2024-04-30 17:13:48 +00:00
|
|
|
LlamaEdgeChatService,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.maritalk import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatMaritalk,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.minimax import (
|
2024-04-30 17:13:48 +00:00
|
|
|
MiniMaxChat,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.mlflow import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatMlflow,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.mlflow_ai_gateway import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatMLflowAIGateway,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.mlx import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatMLX,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.ollama import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatOllama,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.openai import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatOpenAI,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.pai_eas_endpoint import (
|
2024-04-30 17:13:48 +00:00
|
|
|
PaiEasChatEndpoint,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.perplexity import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatPerplexity,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.premai import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatPremAI,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.promptlayer_openai import (
|
2024-04-30 17:13:48 +00:00
|
|
|
PromptLayerChatOpenAI,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.solar import (
|
2024-04-30 17:13:48 +00:00
|
|
|
SolarChat,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.sparkllm import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatSparkLLM,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.tongyi import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatTongyi,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.vertexai import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatVertexAI,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.volcengine_maas import (
|
2024-04-30 17:13:48 +00:00
|
|
|
VolcEngineMaasChat,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.yandex import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatYandexGPT,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.yuan2 import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatYuan2,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_models.zhipuai import (
|
2024-04-30 17:13:48 +00:00
|
|
|
ChatZhipuAI,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
"AzureChatOpenAI",
|
|
|
|
"BedrockChat",
|
|
|
|
"ChatAnthropic",
|
|
|
|
"ChatAnyscale",
|
|
|
|
"ChatBaichuan",
|
|
|
|
"ChatCohere",
|
2024-04-29 16:26:16 +00:00
|
|
|
"ChatCoze",
|
2024-04-10 17:01:19 +00:00
|
|
|
"ChatDatabricks",
|
|
|
|
"ChatDeepInfra",
|
|
|
|
"ChatEverlyAI",
|
|
|
|
"ChatFireworks",
|
|
|
|
"ChatFriendli",
|
|
|
|
"ChatGooglePalm",
|
|
|
|
"ChatHuggingFace",
|
|
|
|
"ChatHunyuan",
|
|
|
|
"ChatJavelinAIGateway",
|
|
|
|
"ChatKinetica",
|
|
|
|
"ChatKonko",
|
|
|
|
"ChatLiteLLM",
|
|
|
|
"ChatLiteLLMRouter",
|
|
|
|
"ChatMLX",
|
|
|
|
"ChatMLflowAIGateway",
|
|
|
|
"ChatMaritalk",
|
|
|
|
"ChatMlflow",
|
|
|
|
"ChatOllama",
|
|
|
|
"ChatOpenAI",
|
|
|
|
"ChatPerplexity",
|
|
|
|
"ChatPremAI",
|
|
|
|
"ChatSparkLLM",
|
|
|
|
"ChatTongyi",
|
|
|
|
"ChatVertexAI",
|
|
|
|
"ChatYandexGPT",
|
|
|
|
"ChatYuan2",
|
|
|
|
"ChatZhipuAI",
|
|
|
|
"ErnieBotChat",
|
|
|
|
"FakeListChatModel",
|
|
|
|
"GPTRouter",
|
|
|
|
"GigaChat",
|
|
|
|
"HumanInputChatModel",
|
|
|
|
"JinaChat",
|
|
|
|
"LlamaEdgeChatService",
|
|
|
|
"MiniMaxChat",
|
|
|
|
"PaiEasChatEndpoint",
|
|
|
|
"PromptLayerChatOpenAI",
|
|
|
|
"QianfanChatEndpoint",
|
|
|
|
"SolarChat",
|
|
|
|
"VolcEngineMaasChat",
|
|
|
|
]
|
|
|
|
|
2023-12-11 21:53:30 +00:00
|
|
|
|
2024-03-11 20:37:36 +00:00
|
|
|
_module_lookup = {
|
|
|
|
"AzureChatOpenAI": "langchain_community.chat_models.azure_openai",
|
|
|
|
"BedrockChat": "langchain_community.chat_models.bedrock",
|
|
|
|
"ChatAnthropic": "langchain_community.chat_models.anthropic",
|
|
|
|
"ChatAnyscale": "langchain_community.chat_models.anyscale",
|
|
|
|
"ChatBaichuan": "langchain_community.chat_models.baichuan",
|
|
|
|
"ChatCohere": "langchain_community.chat_models.cohere",
|
2024-04-29 16:26:16 +00:00
|
|
|
"ChatCoze": "langchain_community.chat_models.coze",
|
2024-03-11 20:37:36 +00:00
|
|
|
"ChatDatabricks": "langchain_community.chat_models.databricks",
|
|
|
|
"ChatDeepInfra": "langchain_community.chat_models.deepinfra",
|
|
|
|
"ChatEverlyAI": "langchain_community.chat_models.everlyai",
|
|
|
|
"ChatFireworks": "langchain_community.chat_models.fireworks",
|
|
|
|
"ChatFriendli": "langchain_community.chat_models.friendli",
|
|
|
|
"ChatGooglePalm": "langchain_community.chat_models.google_palm",
|
|
|
|
"ChatHuggingFace": "langchain_community.chat_models.huggingface",
|
|
|
|
"ChatHunyuan": "langchain_community.chat_models.hunyuan",
|
|
|
|
"ChatJavelinAIGateway": "langchain_community.chat_models.javelin_ai_gateway",
|
|
|
|
"ChatKinetica": "langchain_community.chat_models.kinetica",
|
|
|
|
"ChatKonko": "langchain_community.chat_models.konko",
|
|
|
|
"ChatLiteLLM": "langchain_community.chat_models.litellm",
|
|
|
|
"ChatLiteLLMRouter": "langchain_community.chat_models.litellm_router",
|
|
|
|
"ChatMLflowAIGateway": "langchain_community.chat_models.mlflow_ai_gateway",
|
2024-04-09 14:17:07 +00:00
|
|
|
"ChatMLX": "langchain_community.chat_models.mlx",
|
2024-03-11 20:37:36 +00:00
|
|
|
"ChatMaritalk": "langchain_community.chat_models.maritalk",
|
|
|
|
"ChatMlflow": "langchain_community.chat_models.mlflow",
|
2024-04-17 10:20:56 +00:00
|
|
|
"ChatOctoAI": "langchain_community.chat_models.octoai",
|
2024-03-11 20:37:36 +00:00
|
|
|
"ChatOllama": "langchain_community.chat_models.ollama",
|
|
|
|
"ChatOpenAI": "langchain_community.chat_models.openai",
|
|
|
|
"ChatPerplexity": "langchain_community.chat_models.perplexity",
|
|
|
|
"ChatSparkLLM": "langchain_community.chat_models.sparkllm",
|
|
|
|
"ChatTongyi": "langchain_community.chat_models.tongyi",
|
|
|
|
"ChatVertexAI": "langchain_community.chat_models.vertexai",
|
|
|
|
"ChatYandexGPT": "langchain_community.chat_models.yandex",
|
|
|
|
"ChatYuan2": "langchain_community.chat_models.yuan2",
|
|
|
|
"ChatZhipuAI": "langchain_community.chat_models.zhipuai",
|
|
|
|
"ErnieBotChat": "langchain_community.chat_models.ernie",
|
|
|
|
"FakeListChatModel": "langchain_community.chat_models.fake",
|
|
|
|
"GPTRouter": "langchain_community.chat_models.gpt_router",
|
|
|
|
"GigaChat": "langchain_community.chat_models.gigachat",
|
|
|
|
"HumanInputChatModel": "langchain_community.chat_models.human",
|
|
|
|
"JinaChat": "langchain_community.chat_models.jinachat",
|
|
|
|
"LlamaEdgeChatService": "langchain_community.chat_models.llama_edge",
|
|
|
|
"MiniMaxChat": "langchain_community.chat_models.minimax",
|
|
|
|
"PaiEasChatEndpoint": "langchain_community.chat_models.pai_eas_endpoint",
|
|
|
|
"PromptLayerChatOpenAI": "langchain_community.chat_models.promptlayer_openai",
|
2024-04-10 17:01:19 +00:00
|
|
|
"SolarChat": "langchain_community.chat_models.solar",
|
2024-03-11 20:37:36 +00:00
|
|
|
"QianfanChatEndpoint": "langchain_community.chat_models.baidu_qianfan_endpoint",
|
|
|
|
"VolcEngineMaasChat": "langchain_community.chat_models.volcengine_maas",
|
2024-03-26 01:37:19 +00:00
|
|
|
"ChatPremAI": "langchain_community.chat_models.premai",
|
2024-03-11 20:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def __getattr__(name: str) -> Any:
|
|
|
|
if name in _module_lookup:
|
|
|
|
module = importlib.import_module(_module_lookup[name])
|
|
|
|
return getattr(module, name)
|
|
|
|
raise AttributeError(f"module {__name__} has no attribute {name}")
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = list(_module_lookup.keys())
|