Skip to content

Commit

Permalink
feat(tests): add unit test for Message schema serialization and promp…
Browse files Browse the repository at this point in the history
…t loading
  • Loading branch information
ogabrielluiz committed Jul 30, 2024
1 parent 61194e5 commit 85c9703
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/backend/tests/unit/schema/test_schema_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
from langchain_core.prompts.chat import ChatPromptTemplate

from langflow.schema.message import Message


@pytest.fixture
def client():
pass


@pytest.mark.asyncio
async def test_message_async_prompt_serialization():
template = "Hello, {name}!"
message = await Message.async_from_template_and_variables(template, name="Langflow")
assert message.text == "Hello, Langflow!"

prompt = message.load_lc_prompt()
assert isinstance(prompt, ChatPromptTemplate)
assert prompt.messages[0].content == "Hello, Langflow!"


def test_message_prompt_serialization():
template = "Hello, {name}!"
message = Message.from_template_and_variables(template, name="Langflow")
assert message.text == "Hello, Langflow!"

prompt = message.load_lc_prompt()
assert isinstance(prompt, ChatPromptTemplate)
assert prompt.messages[0].content == "Hello, Langflow!"

0 comments on commit 85c9703

Please sign in to comment.