Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
vblagoje committed Sep 2, 2024
1 parent c829a82 commit ebe3c0d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion test/components/builders/test_chat_prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
from haystack import component
from haystack.core.pipeline.pipeline import Pipeline
from haystack.dataclasses.chat_message import ChatMessage
from haystack.dataclasses.chat_message import ChatMessage, ChatRole
from haystack.dataclasses.document import Document


Expand Down Expand Up @@ -194,6 +194,17 @@ def test_run_overwriting_default_template_with_variables(self):

assert builder.run(template, name="John", var1="Big") == expected_result

def test_run_with_meta(self):
"""
Test that the ChatPromptBuilder correctly handles meta data.
It should render the message and copy the meta data from the original message.
"""
m = ChatMessage(content="This is a {{ variable }}", role=ChatRole.USER, name=None, meta={"test": "test"})
builder = ChatPromptBuilder(template=[m])
res = builder.run(variable="test")
res_msg = ChatMessage(content="This is a test", role=ChatRole.USER, name=None, meta={"test": "test"})
assert res == {"prompt": [res_msg]}

def test_run_with_invalid_template(self):
builder = ChatPromptBuilder()

Expand Down

0 comments on commit ebe3c0d

Please sign in to comment.