Skip to content

Commit

Permalink
core[patch]: Change structured prompt lc id to match js (langchain-ai…
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos authored Mar 15, 2024
1 parent 7ce81eb commit 508f758
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
12 changes: 6 additions & 6 deletions libs/core/langchain_core/load/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@
"retry",
"RunnableRetry",
),
("langchain_core", "prompts", "structured", "StructuredPrompt"): (
"langchain_core",
"prompts",
"structured",
"StructuredPrompt",
),
}

# Needed for backwards compatibility for old versions of LangChain where things
Expand Down Expand Up @@ -522,12 +528,6 @@
"image",
"ImagePromptTemplate",
),
("langchain", "prompts", "chat", "StructuredPrompt"): (
"langchain_core",
"prompts",
"structured",
"StructuredPrompt",
),
}

# Needed for backwards compatibility for a few versions where we serialized
Expand Down
10 changes: 10 additions & 0 deletions libs/core/langchain_core/prompts/structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Callable,
Dict,
Iterator,
List,
Mapping,
Optional,
Sequence,
Expand Down Expand Up @@ -34,6 +35,15 @@
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,
Expand Down
13 changes: 10 additions & 3 deletions libs/langchain/tests/unit_tests/load/test_serializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 508f758

Please sign in to comment.