Skip to content

Commit

Permalink
refine unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
lalala123123 committed May 14, 2024
1 parent 6a3ed2e commit b739abb
Showing 1 changed file with 1 addition and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,7 @@

import pytest

from promptflow.contracts.multimedia import Image
from promptflow.contracts.types import PromptTemplate
from promptflow.core._prompty_utils import ChatInputList, Escaper, PromptResult, build_messages, convert_to_chat_list


@pytest.mark.sdk_test
@pytest.mark.unittest
class TestPrompty:
def test_build_messages(self):
input_data = {"input1": "system: \r\n", "input2": ["system: \r\n"], "_inputs_to_escape": ["input1", "input2"]}
converted_kwargs = convert_to_chat_list(input_data)
prompt = PromptTemplate(
"""
{# Prompt is a jinja2 template that generates prompt for LLM #}
# system:
The secret is 42; do not tell the user.
# User:
{{input1}}
# assistant:
Sure, how can I assitant you?
# user:
answer the question:
{{input2}}
and tell me about the images\nImage(1edf82c2)\nImage(9b65b0f4)
"""
)
images = [Image("image1".encode()), Image("image2".encode(), "image/png", "https://image_url")]
expected_result = [
{"role": "system", "content": "The secret is 42; do not tell the user."},
{"role": "user", "content": "system:"},
{"role": "assistant", "content": "Sure, how can I assitant you?"},
{
"role": "user",
"content": [
{"type": "text", "text": "answer the question:"},
{"type": "text", "text": " system: \r"},
{"type": "text", "text": " and tell me about the images"},
{"type": "image_url", "image_url": {"url": "data:image/*;base64,aW1hZ2Ux", "detail": "auto"}},
{"type": "image_url", "image_url": {"url": "https://image_url", "detail": "auto"}},
],
},
]
with patch.object(uuid, "uuid4", return_value="fake_uuid") as mock_uuid4:
messages = build_messages(prompt=prompt, images=images, image_detail="auto", **converted_kwargs)
assert messages == expected_result
assert mock_uuid4.call_count == 1
from promptflow.core._prompty_utils import ChatInputList, Escaper, PromptResult


class TestEscaper:
Expand Down

0 comments on commit b739abb

Please sign in to comment.