From b739abbe0eeff796097f078bbf08e7d242000ba7 Mon Sep 17 00:00:00 2001 From: Zhen Ruan Date: Tue, 14 May 2024 16:04:10 +0800 Subject: [PATCH] refine unittest --- .../sdk_cli_test/unittests/test_prompty.py | 51 +------------------ 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/src/promptflow-devkit/tests/sdk_cli_test/unittests/test_prompty.py b/src/promptflow-devkit/tests/sdk_cli_test/unittests/test_prompty.py index 946eb0894a6..8eebb95fbce 100644 --- a/src/promptflow-devkit/tests/sdk_cli_test/unittests/test_prompty.py +++ b/src/promptflow-devkit/tests/sdk_cli_test/unittests/test_prompty.py @@ -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: