mirror of
https://github.com/hwchase17/langchain.git
synced 2026-02-21 06:33:41 +00:00
core[patch]: Change structured prompt lc id to match js (#19099)
This commit is contained in:
@@ -481,6 +481,12 @@ SERIALIZABLE_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
|
||||
"retry",
|
||||
"RunnableRetry",
|
||||
),
|
||||
("langchain_core", "prompts", "structured", "StructuredPrompt"): (
|
||||
"langchain_core",
|
||||
"prompts",
|
||||
"structured",
|
||||
"StructuredPrompt",
|
||||
),
|
||||
}
|
||||
|
||||
# Needed for backwards compatibility for old versions of LangChain where things
|
||||
@@ -522,12 +528,6 @@ _OG_SERIALIZABLE_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
|
||||
"image",
|
||||
"ImagePromptTemplate",
|
||||
),
|
||||
("langchain", "prompts", "chat", "StructuredPrompt"): (
|
||||
"langchain_core",
|
||||
"prompts",
|
||||
"structured",
|
||||
"StructuredPrompt",
|
||||
),
|
||||
}
|
||||
|
||||
# Needed for backwards compatibility for a few versions where we serialized
|
||||
|
||||
@@ -3,6 +3,7 @@ from typing import (
|
||||
Callable,
|
||||
Dict,
|
||||
Iterator,
|
||||
List,
|
||||
Mapping,
|
||||
Optional,
|
||||
Sequence,
|
||||
@@ -34,6 +35,15 @@ from langchain_core.runnables.base import (
|
||||
class StructuredPrompt(ChatPromptTemplate):
|
||||
schema_: Union[Dict, Type[BaseModel]]
|
||||
|
||||
@classmethod
|
||||
def get_lc_namespace(cls) -> List[str]:
|
||||
"""Get the namespace of the langchain object.
|
||||
|
||||
For example, if the class is `langchain.llms.openai.OpenAI`, then the
|
||||
namespace is ["langchain", "llms", "openai"]
|
||||
"""
|
||||
return cls.__module__.split(".")
|
||||
|
||||
@classmethod
|
||||
def from_messages_and_schema(
|
||||
cls,
|
||||
|
||||
@@ -40,16 +40,23 @@ def import_all_modules(package_name: str) -> dict:
|
||||
|
||||
|
||||
def test_serializable_mapping() -> None:
|
||||
# This should have had a different namespace, as it was never
|
||||
# exported from the langchain module, but we keep for whoever has
|
||||
# already serialized it.
|
||||
to_skip = {
|
||||
# This should have had a different namespace, as it was never
|
||||
# exported from the langchain module, but we keep for whoever has
|
||||
# already serialized it.
|
||||
("langchain", "prompts", "image", "ImagePromptTemplate"): (
|
||||
"langchain_core",
|
||||
"prompts",
|
||||
"image",
|
||||
"ImagePromptTemplate",
|
||||
),
|
||||
# This is not exported from langchain, only langchain_core
|
||||
("langchain_core", "prompts", "structured", "StructuredPrompt"): (
|
||||
"langchain_core",
|
||||
"prompts",
|
||||
"structured",
|
||||
"StructuredPrompt",
|
||||
),
|
||||
}
|
||||
serializable_modules = import_all_modules("langchain")
|
||||
missing = set(SERIALIZABLE_MAPPING).difference(
|
||||
|
||||
Reference in New Issue
Block a user