Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions libs/core/langchain_core/prompts/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,13 +1300,6 @@ def _prompt_type(self) -> str:
"""Name of prompt type. Used for serialization."""
return "chat"

def save(self, file_path: Union[Path, str]) -> None:
"""Save prompt to file.

Args:
file_path: path to file.
"""
raise NotImplementedError

@override
def pretty_repr(self, html: bool = False) -> str:
Expand Down
38 changes: 38 additions & 0 deletions tests/unit_tests/prompts/test_chat_prompt_template_save.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Test ChatPromptTemplate save method."""

import json
import tempfile
from pathlib import Path
from langchain_core.prompts import ChatPromptTemplate


def test_chat_prompt_template_save() -> None:
"""Test that ChatPromptTemplate can be saved to a file."""
# Create a simple chat prompt template
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant."),
("user", "{input}")
])

# Save to a temporary file
with tempfile.NamedTemporaryFile(suffix=".json", delete=False) as tmp_file:
temp_path = Path(tmp_file.name)

try:
# This should not raise NotImplementedError anymore
prompt.save(temp_path)

# Verify the file was created and contains valid JSON
assert temp_path.exists()

with open(temp_path, "r") as f:
data = json.load(f)

# Verify basic structure
assert "_type" in data
assert data["_type"] == "chat"

finally:
# Clean up
if temp_path.exists():
temp_path.unlink()
Loading