mirror of https://github.com/hwchase17/langchain
manual mapping (#14422)
parent
c24f277b7c
commit
f5befe3b89
@ -0,0 +1,478 @@
|
|||||||
|
# First value is the value that it is serialized as
|
||||||
|
# Second value is the path to load it from
|
||||||
|
SERIALIZABLE_MAPPING = {
|
||||||
|
("langchain", "schema", "messages", "AIMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"ai",
|
||||||
|
"AIMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "AIMessageChunk"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"ai",
|
||||||
|
"AIMessageChunk",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "BaseMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"base",
|
||||||
|
"BaseMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "BaseMessageChunk"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"base",
|
||||||
|
"BaseMessageChunk",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "ChatMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"chat",
|
||||||
|
"ChatMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "FunctionMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"function",
|
||||||
|
"FunctionMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "HumanMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"human",
|
||||||
|
"HumanMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "SystemMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"system",
|
||||||
|
"SystemMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "ToolMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"tool",
|
||||||
|
"ToolMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "agent", "AgentAction"): (
|
||||||
|
"langchain_core",
|
||||||
|
"agents",
|
||||||
|
"AgentAction",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "agent", "AgentFinish"): (
|
||||||
|
"langchain_core",
|
||||||
|
"agents",
|
||||||
|
"AgentFinish",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "prompt_template", "BasePromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"base",
|
||||||
|
"BasePromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "chains", "llm", "LLMChain"): (
|
||||||
|
"langchain",
|
||||||
|
"chains",
|
||||||
|
"llm",
|
||||||
|
"LLMChain",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "prompt", "PromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"prompt",
|
||||||
|
"PromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "chat", "MessagesPlaceholder"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"chat",
|
||||||
|
"MessagesPlaceholder",
|
||||||
|
),
|
||||||
|
("langchain", "llms", "openai", "OpenAI"): (
|
||||||
|
"langchain",
|
||||||
|
"llms",
|
||||||
|
"openai",
|
||||||
|
"OpenAI",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "chat", "ChatPromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"chat",
|
||||||
|
"ChatPromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "chat", "HumanMessagePromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"chat",
|
||||||
|
"HumanMessagePromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "chat", "SystemMessagePromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"chat",
|
||||||
|
"SystemMessagePromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "agent", "AgentActionMessageLog"): (
|
||||||
|
"langchain_core",
|
||||||
|
"agents",
|
||||||
|
"AgentActionMessageLog",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "agent", "OpenAIToolAgentAction"): (
|
||||||
|
"langchain",
|
||||||
|
"agents",
|
||||||
|
"output_parsers",
|
||||||
|
"openai_tools",
|
||||||
|
"OpenAIToolAgentAction",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "chat", "BaseMessagePromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"chat",
|
||||||
|
"BaseMessagePromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "output", "ChatGeneration"): (
|
||||||
|
"langchain_core",
|
||||||
|
"outputs",
|
||||||
|
"chat_generation",
|
||||||
|
"ChatGeneration",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "output", "Generation"): (
|
||||||
|
"langchain_core",
|
||||||
|
"outputs",
|
||||||
|
"generation",
|
||||||
|
"Generation",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "document", "Document"): (
|
||||||
|
"langchain_core",
|
||||||
|
"documents",
|
||||||
|
"base",
|
||||||
|
"Document",
|
||||||
|
),
|
||||||
|
("langchain", "output_parsers", "fix", "OutputFixingParser"): (
|
||||||
|
"langchain",
|
||||||
|
"output_parsers",
|
||||||
|
"fix",
|
||||||
|
"OutputFixingParser",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "chat", "AIMessagePromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"chat",
|
||||||
|
"AIMessagePromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "output_parsers", "regex", "RegexParser"): (
|
||||||
|
"langchain",
|
||||||
|
"output_parsers",
|
||||||
|
"regex",
|
||||||
|
"RegexParser",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "DynamicRunnable"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"configurable",
|
||||||
|
"DynamicRunnable",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "prompt", "PromptValue"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompt_values",
|
||||||
|
"PromptValue",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableBinding"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"base",
|
||||||
|
"RunnableBinding",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableBranch"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"branch",
|
||||||
|
"RunnableBranch",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableWithFallbacks"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"fallbacks",
|
||||||
|
"RunnableWithFallbacks",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "output_parser", "StrOutputParser"): (
|
||||||
|
"langchain_core",
|
||||||
|
"output_parsers",
|
||||||
|
"string",
|
||||||
|
"StrOutputParser",
|
||||||
|
),
|
||||||
|
("langchain", "chat_models", "openai", "ChatOpenAI"): (
|
||||||
|
"langchain",
|
||||||
|
"chat_models",
|
||||||
|
"openai",
|
||||||
|
"ChatOpenAI",
|
||||||
|
),
|
||||||
|
("langchain", "output_parsers", "list", "CommaSeparatedListOutputParser"): (
|
||||||
|
"langchain_core",
|
||||||
|
"output_parsers",
|
||||||
|
"list",
|
||||||
|
"CommaSeparatedListOutputParser",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableParallel"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"base",
|
||||||
|
"RunnableParallel",
|
||||||
|
),
|
||||||
|
("langchain", "chat_models", "azure_openai", "AzureChatOpenAI"): (
|
||||||
|
"langchain",
|
||||||
|
"chat_models",
|
||||||
|
"azure_openai",
|
||||||
|
"AzureChatOpenAI",
|
||||||
|
),
|
||||||
|
("langchain", "chat_models", "bedrock", "BedrockChat"): (
|
||||||
|
"langchain",
|
||||||
|
"chat_models",
|
||||||
|
"bedrock",
|
||||||
|
"BedrockChat",
|
||||||
|
),
|
||||||
|
("langchain", "chat_models", "anthropic", "ChatAnthropic"): (
|
||||||
|
"langchain",
|
||||||
|
"chat_models",
|
||||||
|
"anthropic",
|
||||||
|
"ChatAnthropic",
|
||||||
|
),
|
||||||
|
("langchain", "chat_models", "fireworks", "ChatFireworks"): (
|
||||||
|
"langchain",
|
||||||
|
"chat_models",
|
||||||
|
"fireworks",
|
||||||
|
"ChatFireworks",
|
||||||
|
),
|
||||||
|
("langchain", "chat_models", "google_palm", "ChatGooglePalm"): (
|
||||||
|
"langchain",
|
||||||
|
"chat_models",
|
||||||
|
"google_palm",
|
||||||
|
"ChatGooglePalm",
|
||||||
|
),
|
||||||
|
("langchain", "chat_models", "vertexai", "ChatVertexAI"): (
|
||||||
|
"langchain",
|
||||||
|
"chat_models",
|
||||||
|
"vertexai",
|
||||||
|
"ChatVertexAI",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "output", "ChatGenerationChunk"): (
|
||||||
|
"langchain_core",
|
||||||
|
"outputs",
|
||||||
|
"chat_generation",
|
||||||
|
"ChatGenerationChunk",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "ChatMessageChunk"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"chat",
|
||||||
|
"ChatMessageChunk",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "HumanMessageChunk"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"human",
|
||||||
|
"HumanMessageChunk",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "FunctionMessageChunk"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"function",
|
||||||
|
"FunctionMessageChunk",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "SystemMessageChunk"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"system",
|
||||||
|
"SystemMessageChunk",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "messages", "ToolMessageChunk"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"tool",
|
||||||
|
"ToolMessageChunk",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "output", "GenerationChunk"): (
|
||||||
|
"langchain_core",
|
||||||
|
"outputs",
|
||||||
|
"generation",
|
||||||
|
"GenerationChunk",
|
||||||
|
),
|
||||||
|
("langchain", "llms", "openai", "BaseOpenAI"): (
|
||||||
|
"langchain",
|
||||||
|
"llms",
|
||||||
|
"openai",
|
||||||
|
"BaseOpenAI",
|
||||||
|
),
|
||||||
|
("langchain", "llms", "bedrock", "Bedrock"): (
|
||||||
|
"langchain",
|
||||||
|
"llms",
|
||||||
|
"bedrock",
|
||||||
|
"Bedrock",
|
||||||
|
),
|
||||||
|
("langchain", "llms", "fireworks", "Fireworks"): (
|
||||||
|
"langchain",
|
||||||
|
"llms",
|
||||||
|
"fireworks",
|
||||||
|
"Fireworks",
|
||||||
|
),
|
||||||
|
("langchain", "llms", "google_palm", "GooglePalm"): (
|
||||||
|
"langchain",
|
||||||
|
"llms",
|
||||||
|
"google_palm",
|
||||||
|
"GooglePalm",
|
||||||
|
),
|
||||||
|
("langchain", "llms", "openai", "AzureOpenAI"): (
|
||||||
|
"langchain",
|
||||||
|
"llms",
|
||||||
|
"openai",
|
||||||
|
"AzureOpenAI",
|
||||||
|
),
|
||||||
|
("langchain", "llms", "replicate", "Replicate"): (
|
||||||
|
"langchain",
|
||||||
|
"llms",
|
||||||
|
"replicate",
|
||||||
|
"Replicate",
|
||||||
|
),
|
||||||
|
("langchain", "llms", "vertexai", "VertexAI"): (
|
||||||
|
"langchain",
|
||||||
|
"llms",
|
||||||
|
"vertexai",
|
||||||
|
"VertexAI",
|
||||||
|
),
|
||||||
|
("langchain", "output_parsers", "combining", "CombiningOutputParser"): (
|
||||||
|
"langchain",
|
||||||
|
"output_parsers",
|
||||||
|
"combining",
|
||||||
|
"CombiningOutputParser",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "prompt_template", "BaseChatPromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"chat",
|
||||||
|
"BaseChatPromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "chat", "ChatMessagePromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"chat",
|
||||||
|
"ChatMessagePromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "few_shot_with_templates", "FewShotPromptWithTemplates"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"few_shot_with_templates",
|
||||||
|
"FewShotPromptWithTemplates",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "pipeline", "PipelinePromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"pipeline",
|
||||||
|
"PipelinePromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "base", "StringPromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"string",
|
||||||
|
"StringPromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "base", "StringPromptValue"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompt_values",
|
||||||
|
"StringPromptValue",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "chat", "BaseStringMessagePromptTemplate"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompts",
|
||||||
|
"chat",
|
||||||
|
"BaseStringMessagePromptTemplate",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "chat", "ChatPromptValue"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompt_values",
|
||||||
|
"ChatPromptValue",
|
||||||
|
),
|
||||||
|
("langchain", "prompts", "chat", "ChatPromptValueConcrete"): (
|
||||||
|
"langchain_core",
|
||||||
|
"prompt_values",
|
||||||
|
"ChatPromptValueConcrete",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "HubRunnable"): (
|
||||||
|
"langchain",
|
||||||
|
"runnables",
|
||||||
|
"hub",
|
||||||
|
"HubRunnable",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableBindingBase"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"base",
|
||||||
|
"RunnableBindingBase",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "OpenAIFunctionsRouter"): (
|
||||||
|
"langchain",
|
||||||
|
"runnables",
|
||||||
|
"openai_functions",
|
||||||
|
"OpenAIFunctionsRouter",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RouterRunnable"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"router",
|
||||||
|
"RouterRunnable",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnablePassthrough"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"passthrough",
|
||||||
|
"RunnablePassthrough",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableSequence"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"base",
|
||||||
|
"RunnableSequence",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableEach"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"base",
|
||||||
|
"RunnableEach",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableEachBase"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"base",
|
||||||
|
"RunnableEachBase",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableConfigurableAlternatives"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"configurable",
|
||||||
|
"RunnableConfigurableAlternatives",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableConfigurableFields"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"configurable",
|
||||||
|
"RunnableConfigurableFields",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableWithMessageHistory"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"history",
|
||||||
|
"RunnableWithMessageHistory",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableAssign"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"passthrough",
|
||||||
|
"RunnableAssign",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "runnable", "RunnableRetry"): (
|
||||||
|
"langchain_core",
|
||||||
|
"runnables",
|
||||||
|
"retry",
|
||||||
|
"RunnableRetry",
|
||||||
|
),
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,55 @@
|
|||||||
|
import importlib
|
||||||
|
import pkgutil
|
||||||
|
|
||||||
|
from langchain_core.load.mapping import SERIALIZABLE_MAPPING
|
||||||
|
|
||||||
|
|
||||||
|
def import_all_modules(package_name: str) -> dict:
|
||||||
|
package = importlib.import_module(package_name)
|
||||||
|
classes: dict = {}
|
||||||
|
|
||||||
|
for attribute_name in dir(package):
|
||||||
|
attribute = getattr(package, attribute_name)
|
||||||
|
if hasattr(attribute, "is_lc_serializable") and isinstance(attribute, type):
|
||||||
|
if (
|
||||||
|
isinstance(attribute.is_lc_serializable(), bool) # type: ignore
|
||||||
|
and attribute.is_lc_serializable() # type: ignore
|
||||||
|
):
|
||||||
|
key = tuple(attribute.lc_id()) # type: ignore
|
||||||
|
value = tuple(attribute.__module__.split(".") + [attribute.__name__])
|
||||||
|
if key in classes and classes[key] != value:
|
||||||
|
raise ValueError
|
||||||
|
classes[key] = value
|
||||||
|
if hasattr(package, "__path__"):
|
||||||
|
for loader, module_name, is_pkg in pkgutil.walk_packages(
|
||||||
|
package.__path__, package_name + "."
|
||||||
|
):
|
||||||
|
if module_name not in (
|
||||||
|
"langchain.chains.llm_bash",
|
||||||
|
"langchain.chains.llm_symbolic_math",
|
||||||
|
"langchain.tools.python",
|
||||||
|
"langchain.vectorstores._pgvector_data_models",
|
||||||
|
):
|
||||||
|
importlib.import_module(module_name)
|
||||||
|
new_classes = import_all_modules(module_name)
|
||||||
|
for k, v in new_classes.items():
|
||||||
|
if k in classes and classes[k] != v:
|
||||||
|
raise ValueError
|
||||||
|
classes[k] = v
|
||||||
|
return classes
|
||||||
|
|
||||||
|
|
||||||
|
def test_serializable_mapping() -> None:
|
||||||
|
serializable_modules = import_all_modules("langchain")
|
||||||
|
missing = set(SERIALIZABLE_MAPPING).difference(serializable_modules)
|
||||||
|
assert missing == set()
|
||||||
|
extra = set(serializable_modules).difference(SERIALIZABLE_MAPPING)
|
||||||
|
assert extra == set()
|
||||||
|
|
||||||
|
for k, import_path in serializable_modules.items():
|
||||||
|
import_dir, import_obj = import_path[:-1], import_path[-1]
|
||||||
|
# Import module
|
||||||
|
mod = importlib.import_module(".".join(import_dir))
|
||||||
|
# Import class
|
||||||
|
cls = getattr(mod, import_obj)
|
||||||
|
assert list(k) == cls.lc_id()
|
Loading…
Reference in New Issue