chore: import upstream snapshot with attribution
tools_continuous_delivery / Private PyPI non-main branch release (push) Has been skipped
tools_continuous_delivery / Private PyPI main branch release (push) Failing after 2m42s
Publish Promptflow Doc / Build (push) Has been cancelled
Publish Promptflow Doc / Deploy (push) Has been cancelled
Flake8 Lint / flake8 (push) Has been cancelled
Spell check CI / Spell_Check (push) Has been cancelled
tools_continuous_delivery / Private PyPI non-main branch release (push) Has been skipped
tools_continuous_delivery / Private PyPI main branch release (push) Failing after 2m42s
Publish Promptflow Doc / Build (push) Has been cancelled
Publish Promptflow Doc / Deploy (push) Has been cancelled
Flake8 Lint / flake8 (push) Has been cancelled
Spell check CI / Spell_Check (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from promptflow.connections import CustomConnection
|
||||
from my_tool_package.tools.my_tool_1 import my_tool
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def my_custom_connection() -> CustomConnection:
|
||||
my_custom_connection = CustomConnection(
|
||||
{
|
||||
"api-key" : "my-api-key",
|
||||
"api-secret" : "my-api-secret",
|
||||
"api-url" : "my-api-url"
|
||||
}
|
||||
)
|
||||
return my_custom_connection
|
||||
|
||||
|
||||
class TestMyTool1:
|
||||
def test_my_tool_1(self, my_custom_connection):
|
||||
result = my_tool(my_custom_connection, input_text="Microsoft")
|
||||
assert result == "Hello Microsoft"
|
||||
|
||||
|
||||
# Run the unit tests
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from promptflow.connections import CustomConnection
|
||||
from my_tool_package.tools.my_tool_2 import MyTool
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def my_custom_connection() -> CustomConnection:
|
||||
my_custom_connection = CustomConnection(
|
||||
{
|
||||
"api-key" : "my-api-key",
|
||||
"api-secret" : "my-api-secret",
|
||||
"api-url" : "my-api-url"
|
||||
}
|
||||
)
|
||||
return my_custom_connection
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def my_tool_provider(my_custom_connection) -> MyTool:
|
||||
my_tool_provider = MyTool(my_custom_connection)
|
||||
return my_tool_provider
|
||||
|
||||
|
||||
class TestMyTool2:
|
||||
def test_my_tool_2(self, my_tool_provider: MyTool):
|
||||
result = my_tool_provider.my_tool(input_text="Microsoft")
|
||||
assert result == "Hello Microsoft"
|
||||
|
||||
|
||||
# Run the unit tests
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,6 @@
|
||||
from my_tool_package.tools.tool_with_cascading_inputs import my_tool
|
||||
|
||||
|
||||
def test_my_tool():
|
||||
result = my_tool(user_type="student", student_id="student_id")
|
||||
assert result == '123'
|
||||
@@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from promptflow.connections import CustomConnection
|
||||
from my_tool_package.tools.tool_with_custom_llm_type import my_tool
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def my_custom_connection() -> CustomConnection:
|
||||
my_custom_connection = CustomConnection(
|
||||
{
|
||||
"api-key" : "my-api-key",
|
||||
"api-secret" : "my-api-secret",
|
||||
"api-url" : "my-api-url"
|
||||
}
|
||||
)
|
||||
return my_custom_connection
|
||||
|
||||
|
||||
class TestToolWithCustomLLMType:
|
||||
def test_tool_with_custom_llm_type(self, my_custom_connection):
|
||||
result = my_tool(
|
||||
my_custom_connection,
|
||||
"my-api",
|
||||
"my-deployment-name",
|
||||
0,
|
||||
"Hello {{text}}",
|
||||
text="Microsoft")
|
||||
assert result == "Hello Microsoft"
|
||||
|
||||
|
||||
# Run the unit tests
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from my_tool_package.tools.tool_with_custom_strong_type_connection import MyCustomConnection, my_tool
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def my_custom_connection() -> MyCustomConnection:
|
||||
my_custom_connection = MyCustomConnection(
|
||||
{
|
||||
"api_key" : "my-api-key",
|
||||
"api_base" : "my-api-base"
|
||||
}
|
||||
)
|
||||
return my_custom_connection
|
||||
|
||||
|
||||
class TestMyToolWithCustomStrongTypeConnection:
|
||||
def test_my_tool(self, my_custom_connection):
|
||||
result = my_tool(my_custom_connection, input_text="Microsoft")
|
||||
assert result == "Hello Microsoft"
|
||||
|
||||
|
||||
# Run the unit tests
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,12 @@
|
||||
from my_tool_package.tools.tool_with_dynamic_list_input import my_tool, my_list_func
|
||||
|
||||
|
||||
def test_my_tool():
|
||||
result = my_tool(input_text=["apple", "banana"], input_prefix="My")
|
||||
assert result == 'Hello My apple,banana'
|
||||
|
||||
|
||||
def test_my_list_func():
|
||||
result = my_list_func(prefix="My")
|
||||
assert len(result) == 10
|
||||
assert "value" in result[0]
|
||||
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from promptflow.contracts.types import FilePath
|
||||
from my_tool_package.tools.tool_with_file_path_input import my_tool
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def my_file_path_input() -> FilePath:
|
||||
my_file_path_input = FilePath("tests.test_utils.hello_method.py")
|
||||
return my_file_path_input
|
||||
|
||||
|
||||
class TestToolWithFilePathInput:
|
||||
def test_tool_with_file_path_input(self, my_file_path_input):
|
||||
result = my_tool(my_file_path_input, input_text="Microsoft")
|
||||
assert result == "Hello Microsoft"
|
||||
|
||||
|
||||
# Run the unit tests
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,89 @@
|
||||
import json
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from my_tool_package.tools.tool_with_generated_by_input import (
|
||||
generate_index_json,
|
||||
list_embedding_deployment,
|
||||
list_fields,
|
||||
list_indexes,
|
||||
list_index_types,
|
||||
list_semantic_configuration,
|
||||
my_tool,
|
||||
reverse_generate_index_json,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("index_type", ["Azure Cognitive Search", "Workspace MLIndex"])
|
||||
def test_my_tool(index_type):
|
||||
index_json = generate_index_json(index_type=index_type)
|
||||
result = my_tool(index_json, "", "")
|
||||
assert result == f'Hello {index_json}'
|
||||
|
||||
|
||||
def test_generate_index_json():
|
||||
index_type = "Azure Cognitive Search"
|
||||
index_json = generate_index_json(index_type=index_type)
|
||||
indexes = json.loads(index_json)
|
||||
assert indexes["index_type"] == index_type
|
||||
|
||||
|
||||
def test_reverse_generate_index_json():
|
||||
index_type = "Workspace MLIndex"
|
||||
index = list_indexes("", "", "")
|
||||
inputs = {
|
||||
"index_type": index_type,
|
||||
"index": index,
|
||||
"index_connection": "retrieved_index_connection",
|
||||
"index_name": "retrieved_index_name",
|
||||
"content_field": "retrieved_content_field",
|
||||
"embedding_field": "retrieved_embedding_field",
|
||||
"metadata_field": "retrieved_metadata_field",
|
||||
"semantic_configuration": "retrieved_semantic_configuration",
|
||||
"embedding_connection": "retrieved_embedding_connection",
|
||||
"embedding_deployment": "retrieved_embedding_deployment"
|
||||
}
|
||||
|
||||
input_json = json.dumps(inputs)
|
||||
result = reverse_generate_index_json(input_json)
|
||||
for k, v in inputs.items():
|
||||
assert result[k] == v
|
||||
|
||||
|
||||
def test_list_index_types():
|
||||
result = list_index_types("", "", "")
|
||||
assert isinstance(result, list)
|
||||
assert len(result) == 5
|
||||
|
||||
|
||||
def test_list_indexes():
|
||||
result = list_indexes("", "", "")
|
||||
assert isinstance(result, list)
|
||||
assert len(result) == 10
|
||||
for item in result:
|
||||
assert isinstance(item, dict)
|
||||
|
||||
|
||||
def test_list_fields():
|
||||
result = list_fields("", "", "")
|
||||
assert isinstance(result, list)
|
||||
assert len(result) == 9
|
||||
for item in result:
|
||||
assert isinstance(item, dict)
|
||||
|
||||
|
||||
def test_list_semantic_configuration():
|
||||
result = list_semantic_configuration("", "", "")
|
||||
assert len(result) == 1
|
||||
assert isinstance(result[0], dict)
|
||||
|
||||
|
||||
def test_list_embedding_deployment():
|
||||
result = list_embedding_deployment("")
|
||||
assert len(result) == 2
|
||||
for item in result:
|
||||
assert isinstance(item, dict)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,3 @@
|
||||
def hello(input_text: str) -> str:
|
||||
# Replace with your own code.
|
||||
return "Hello " + input_text
|
||||
Reference in New Issue
Block a user