mirror of
https://github.com/hwchase17/langchain
synced 2024-11-11 19:11:02 +00:00
783397eacb
## Description In `langchain_prompty`, messages are templated by Prompty. However, a call to `ChatPromptTemplate` was initiating a second templating. We now convert parsed messages to `Message` objects before calling `ChatPromptTemplate`, signifying clearly that they are already templated. We also revert #25739 , which applied to this second templating, which we now avoid, and did not fix the original issue. ## Issue Closes #25703
24 lines
665 B
Python
24 lines
665 B
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from langchain_prompty import create_chat_prompt
|
|
|
|
PROMPT_DIR = Path(__file__).parent / "prompts"
|
|
|
|
|
|
def test_double_templating() -> None:
|
|
"""
|
|
Assess whether double templating occurs when invoking a chat prompt.
|
|
If it does, an error is thrown and the test fails.
|
|
"""
|
|
|
|
prompt_path = PROMPT_DIR / "double_templating.prompty"
|
|
templated_prompt = create_chat_prompt(str(prompt_path))
|
|
query = "What do you think of this JSON object: {'key': 7}?"
|
|
|
|
try:
|
|
templated_prompt.invoke(input={"user_input": query})
|
|
except KeyError as e:
|
|
pytest.fail("Double templating occurred: " + str(e))
|