From 8a731aa1a72a1f54f67264b1e3cc9c7341f01587 Mon Sep 17 00:00:00 2001 From: jiazeng Date: Thu, 26 Oct 2023 10:30:44 +0800 Subject: [PATCH] delete flow and tool --- .../create-and-use-tool-package.md | 2 +- .../develop-a-tool/create-custom-llm-tool.md | 17 ++++++----- .../custom_llm_tool_showcase/flow.dag.yaml | 18 ------------ .../prompt_template.jinja2 | 1 - .../custom_llm_tool_showcase/requirements.txt | 3 -- .../tools/tool_with_custom_llm_type.py | 13 --------- .../yamls/tool_with_custom_llm_type.yaml | 10 ------- .../tests/test_tool_with_custom_llm_type.py | 28 ------------------- 8 files changed, 9 insertions(+), 83 deletions(-) delete mode 100644 examples/flows/standard/custom_llm_tool_showcase/flow.dag.yaml delete mode 100644 examples/flows/standard/custom_llm_tool_showcase/prompt_template.jinja2 delete mode 100644 examples/flows/standard/custom_llm_tool_showcase/requirements.txt delete mode 100644 examples/tools/tool-package-quickstart/my_tool_package/tools/tool_with_custom_llm_type.py delete mode 100644 examples/tools/tool-package-quickstart/my_tool_package/yamls/tool_with_custom_llm_type.yaml delete mode 100644 examples/tools/tool-package-quickstart/tests/test_tool_with_custom_llm_type.py diff --git a/docs/how-to-guides/develop-a-tool/create-and-use-tool-package.md b/docs/how-to-guides/develop-a-tool/create-and-use-tool-package.md index 2e5213387480..0e317b702417 100644 --- a/docs/how-to-guides/develop-a-tool/create-and-use-tool-package.md +++ b/docs/how-to-guides/develop-a-tool/create-and-use-tool-package.md @@ -164,4 +164,4 @@ Alternatively, you can test your tool package using the script below to ensure t ## Advanced features [Customize your tool icon](add-a-tool-icon.md) [Add category and tags for tool](add-category-and-tags-for-tool.md) -[Use custom LLM tool](use-custom-llm-tool.md) \ No newline at end of file +[Create Custom LLM Tool](create-custom-llm-tool.md) \ No newline at end of file diff --git a/docs/how-to-guides/develop-a-tool/create-custom-llm-tool.md b/docs/how-to-guides/develop-a-tool/create-custom-llm-tool.md index 5e11d8a69e47..93440f6eea5e 100644 --- a/docs/how-to-guides/develop-a-tool/create-custom-llm-tool.md +++ b/docs/how-to-guides/develop-a-tool/create-custom-llm-tool.md @@ -1,7 +1,7 @@ # Create Custom LLM Tool In this document, we will guide you through the process of developing a tool with `custom_llm` type which can connect to a customized large language model with prompt. -Custom LLM is a fine-tuned large language model by yourself. If you find it has good performance and is useful, then you can follow this guidance to make it a tool so that it can be shared with other people to have more impact. +Custom LLM is a large language model fine-tuned by yourself. If you find it has good performance and is useful, then you can follow this guidance to make it a tool so that it can be shared with other people to have more impact. ## Prerequisites - Please ensure that your `Prompt flow` for VS Code is updated to version 1.2.0 or later. @@ -9,7 +9,7 @@ Custom LLM is a fine-tuned large language model by yourself. If you find it has ## How to create a custom LLM tool Here we use [an existing tool package](../../../examples/tools/tool-package-quickstart/my_tool_package) as an example. If you want to create your own tool, please refer to [create and use tool package](create-and-use-tool-package.md). -### Add a `PromptTemplate` input for your tool, like in [this example](../../../examples/tools/tool-package-quickstart/my_tool_package/tools/tool_with_custom_llm_type.py) +### Add a `PromptTemplate` input to your tool, like in [this example](../../../examples/tools/tool-package-quickstart/my_tool_package/tools/tool_with_custom_llm_type.py) ```python from jinja2 import Template @@ -22,7 +22,7 @@ from promptflow.contracts.types import PromptTemplate # 2. Add a PromptTemplate input for your tool method. @tool def my_tool(connection: CustomConnection, prompt: PromptTemplate, **kwargs) -> str: - # 3. The prompt is used for your custom LLM to do inference, customise your own code to handle and use the prompt here. + # 3. The prompt is used for your custom LLM to do inference, customize your own code to handle and use the prompt here. message = Template(prompt, trim_blocks=True, keep_trailing_newline=True).render(**kwargs) return message ``` @@ -37,13 +37,13 @@ Here we use [an existing tool](../../../examples/tools/tool-package-quickstart/m ``` cd D:\proj\github\promptflow\examples\tools\tool-package-quickstart -python D:\proj\github\promptflow\scripts\tool\generate_package_tool_meta.py -m my_tool_package.tools.tool_with_custom_llm_type -o my_tool_package\yamls\tool_with_custom_llm_type.yaml -n "Custom LLM Tool" -d "This is a tool to demonstrate the custom_llm tool type" -t "custom_llm" +python D:\proj\github\promptflow\scripts\tool\generate_package_tool_meta.py -m my_tool_package.tools.tool_with_custom_llm_type -o my_tool_package\yamls\tool_with_custom_llm_type.yaml -n "My Custom LLM Tool" -d "This is a tool to demonstrate the custom_llm tool type" -t "custom_llm" ``` -This command will generate YAML as follows: +This command will generate a YAML file as follows: ```yaml my_tool_package.tools.tool_with_custom_llm_type.my_tool: -name: Custom LLM Tool +name: My Custom LLM Tool description: This is a tool to demonstrate the custom_llm tool type # The type is custom_llm. type: custom_llm @@ -59,6 +59,5 @@ inputs: Follow the steps to [build and install your tool package](create-and-use-tool-package.md#build-and-share-the-tool-package) and [use your tool from VS Code extension](create-and-use-tool-package.md#use-your-tool-from-vscode-extension). Here we use an existing flow to demonstrate the experience, open [this flow](../../../examples/flows/standard/custom_llm_tool_showcase/flow.dag.yaml) in VS Code extension. -- There is a node named "custom_llm_tool" with a prompt template file. You have the option to either use an existing file or create a new one as the prompt template file. - -![use_custom_llm_tool](../../media/how-to-guides/develop-a-tool/use_custom_llm_tool.png) \ No newline at end of file +- There is a node named "custom_llm_tool" with a prompt template file. You can either use an existing file or create a new one as the prompt template file. +![use_custom_llm_tool](../../media/how-to-guides/develop-a-tool/use_custom_llm_tool.png) diff --git a/examples/flows/standard/custom_llm_tool_showcase/flow.dag.yaml b/examples/flows/standard/custom_llm_tool_showcase/flow.dag.yaml deleted file mode 100644 index f51f5c5e5f83..000000000000 --- a/examples/flows/standard/custom_llm_tool_showcase/flow.dag.yaml +++ /dev/null @@ -1,18 +0,0 @@ -inputs: - text: - type: string - default: Microsoft -outputs: - output: - type: string - reference: ${cumstome_llm_tool.output} -nodes: -- name: cumstome_llm_tool - type: custom_llm - source: - type: package_with_prompt - tool: my_tool_package.tools.tool_with_custom_llm_type.my_tool - path: prompt_template.jinja2 - inputs: - connection: open_ai_connection - text: ${inputs.text} diff --git a/examples/flows/standard/custom_llm_tool_showcase/prompt_template.jinja2 b/examples/flows/standard/custom_llm_tool_showcase/prompt_template.jinja2 deleted file mode 100644 index b8ec99b1a892..000000000000 --- a/examples/flows/standard/custom_llm_tool_showcase/prompt_template.jinja2 +++ /dev/null @@ -1 +0,0 @@ -Hello {{text}}. \ No newline at end of file diff --git a/examples/flows/standard/custom_llm_tool_showcase/requirements.txt b/examples/flows/standard/custom_llm_tool_showcase/requirements.txt deleted file mode 100644 index 0310b74813b7..000000000000 --- a/examples/flows/standard/custom_llm_tool_showcase/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -promptflow -promptflow-tools -my-tools-package \ No newline at end of file diff --git a/examples/tools/tool-package-quickstart/my_tool_package/tools/tool_with_custom_llm_type.py b/examples/tools/tool-package-quickstart/my_tool_package/tools/tool_with_custom_llm_type.py deleted file mode 100644 index b9535467ffed..000000000000 --- a/examples/tools/tool-package-quickstart/my_tool_package/tools/tool_with_custom_llm_type.py +++ /dev/null @@ -1,13 +0,0 @@ -from jinja2 import Template -from promptflow import tool -from promptflow.connections import CustomConnection -from promptflow.contracts.types import PromptTemplate - - -@tool -def my_tool(connection: CustomConnection, prompt: PromptTemplate, **kwargs) -> str: - # Replace with your tool code, customise your own code to handle and use the prompt here. - # Usually connection contains configs to connect to an API. - # Not all tools need a connection. You can remove it if you don't need it. - message = Template(prompt, trim_blocks=True, keep_trailing_newline=True).render(**kwargs) - return message \ No newline at end of file diff --git a/examples/tools/tool-package-quickstart/my_tool_package/yamls/tool_with_custom_llm_type.yaml b/examples/tools/tool-package-quickstart/my_tool_package/yamls/tool_with_custom_llm_type.yaml deleted file mode 100644 index 8b90501802e7..000000000000 --- a/examples/tools/tool-package-quickstart/my_tool_package/yamls/tool_with_custom_llm_type.yaml +++ /dev/null @@ -1,10 +0,0 @@ -my_tool_package.tools.tool_with_custom_llm_type.my_tool: - description: This is a tool to demonstrate the custom_llm tool type - function: my_tool - inputs: - connection: - type: - - CustomConnection - module: my_tool_package.tools.tool_with_custom_llm_type - name: Custom LLM Tool - type: custom_llm diff --git a/examples/tools/tool-package-quickstart/tests/test_tool_with_custom_llm_type.py b/examples/tools/tool-package-quickstart/tests/test_tool_with_custom_llm_type.py deleted file mode 100644 index 08c2af8d672c..000000000000 --- a/examples/tools/tool-package-quickstart/tests/test_tool_with_custom_llm_type.py +++ /dev/null @@ -1,28 +0,0 @@ -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, "Hello {{text}}", text="Microsoft") - assert result == "Hello Microsoft" - - -# Run the unit tests -if __name__ == "__main__": - unittest.main()