Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
yalu4 committed Apr 25, 2024
1 parent 1c88c1d commit 91a1509
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/promptflow-tools/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from promptflow.tools.common import ChatAPIInvalidFunctions, validate_functions, process_function_call, \
parse_chat, find_referenced_image_set, preprocess_template_string, convert_to_chat_list, ChatInputList, \
ParseConnectionError, _parse_resource_id, list_deployment_connections, normalize_connection_config, \
validate_tools, process_tool_choice, init_azure_openai_client, \
validate_tools, process_tool_choice, init_azure_openai_client, try_parse_tool_calls, \
Escaper, PromptResult, render_jinja_template, build_messages
from promptflow.tools.exception import (
ListDeploymentsError,
Expand Down Expand Up @@ -235,6 +235,23 @@ def test_try_parse_chat_with_tools(self, example_prompt_template_with_tool, pars
actual_result = parse_chat(example_prompt_template_with_tool)
assert actual_result == parsed_chat_with_tools

@pytest.mark.parametrize(
"role_prompt, expected_result",
[("## tool_calls:\n[]", []),
("## tool_calls:\r\n[]", []),
("## tool_calls: \n[]", []),
("## tool_calls :\r\n[]", []),
("tool_calls:\r\n[]", []),
("some text", None),
("tool_calls:\r\n[", None),
("tool_calls:\r\n[{'id': 'tool_call_id', 'type': 'function', 'function': {'name': 'func1', 'arguments': ''}}]",
[{'id': 'tool_call_id', 'type': 'function', 'function': {'name': 'func1', 'arguments': ''}}]),
("tool_calls:\n[{'id': 'tool_call_id', 'type': 'function', 'function': {'name': 'func1', 'arguments': ''}}]",
[{'id': 'tool_call_id', 'type': 'function', 'function': {'name': 'func1', 'arguments': ''}}])])
def test_try_parse_tool_calls(self, role_prompt, expected_result):
actual = try_parse_tool_calls(role_prompt)
assert actual == expected_result

@pytest.mark.parametrize(
"kwargs, expected_result",
[
Expand Down

0 comments on commit 91a1509

Please sign in to comment.