Skip to content

Commit

Permalink
change doc name and refine
Browse files Browse the repository at this point in the history
update

update
  • Loading branch information
jiazengcindy committed Oct 30, 2023
1 parent 4c20521 commit 2385567
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ Alternatively, you can test your tool package using the script below to ensure t
[Customize your tool icon](add-a-tool-icon.md)
[Add category and tags for tool](add-category-and-tags-for-tool.md)
[Use file path as tool input](use-file-path-as-tool-input.md)
[Create Custom LLM Tool](create-custom-llm-tool.md)
[Customize an LLM Tool](customize_an_llm_tool.md)
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# 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.

A 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 others to increase its impact.
# Customize an LLM Tool
In this document, we will guide you through the process of customizing an LLM tool, allowing users to seamlessly connect with a large language model while fine-tuning their prompts using a `PromptTemplate`.

## Prerequisites
- Please ensure that your [Prompt flow for VS Code](https://marketplace.visualstudio.com/items?itemName=prompt-flow.prompt-flow) is updated to version 1.2.0 or later.

## How to create a custom LLM tool
## How to customize an LLM tool
Here we use [an existing tool package](https://github.com/microsoft/promptflow/tree/main/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).

1. Develop the tool code as in [this example](https://github.com/microsoft/promptflow/blob/main/examples/tools/tool-package-quickstart/my_tool_package/tools/tool_with_custom_llm_type.py).
- Add a `CustomConnection` input to the tool, which is used to authenticate and establish a connection to the customized large language model.
- Add a `PromptTemplate` input to the tool, which serves as an argument to be passed into the customized large language model.
- Add a `CustomConnection` input to the tool, which is used to authenticate and establish a connection to the large language model.
- Add a `PromptTemplate` input to the tool, which serves as an argument to be passed into the large language model.

```python
from jinja2 import Template
Expand All @@ -36,14 +34,14 @@ Here we use [an existing tool package](https://github.com/microsoft/promptflow/t
```
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 "My 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 how to customize an LLM tool with a PromptTemplate." -t "custom_llm"
```
This command will generate a YAML file as follows:

```yaml
my_tool_package.tools.tool_with_custom_llm_type.my_tool:
name: My Custom LLM Tool
description: This is a tool to demonstrate the custom_llm tool type
description: This is a tool to demonstrate how to customize an LLM tool with a PromptTemplate.
# The type is custom_llm.
type: custom_llm
module: my_tool_package.tools.tool_with_custom_llm_type
Expand All @@ -54,7 +52,7 @@ Here we use [an existing tool package](https://github.com/microsoft/promptflow/t
- CustomConnection
```

## Use custom LLM tool in VS Code extension
## Use the custom LLM tool in VS Code extension
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](https://github.com/microsoft/promptflow/blob/main/examples/tools/use-cases/custom_llm_tool_showcase/flow.dag.yaml) in VS Code extension.
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to-guides/develop-a-tool/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ create-and-use-tool-package
add-a-tool-icon
add-category-and-tags-for-tool
use-file-path-as-tool-input
create-custom-llm-tool
customize_a_llm_tool
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
| [cascading-inputs-tool-showcase](tools/use-cases/cascading-inputs-tool-showcase/README.md) | [![samples_tools_use_cases_cascading_inputs_tool_showcase](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_cascading_inputs_tool_showcase.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_cascading_inputs_tool_showcase.yml) | This is a flow demonstrating the use of a tool with cascading inputs which frequently used in situations where the selection in one input field determines what subsequent inputs should be shown, and it helps in creating a more efficient, user-friendly, and error-free input process |
| [custom-strong-type-connection-package-tool-showcase](tools/use-cases/custom-strong-type-connection-package-tool-showcase/README.md) | [![samples_tools_use_cases_custom_strong_type_connection_package_tool_showcase](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_custom_strong_type_connection_package_tool_showcase.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_custom_strong_type_connection_package_tool_showcase.yml) | This is a flow demonstrating the use of a package tool with custom string type connection which provides a secure way to manage credentials for external APIs and data sources, and it offers an improved user-friendly and intellisense experience compared to custom connections |
| [custom-strong-type-connection-script-tool-showcase](tools/use-cases/custom-strong-type-connection-script-tool-showcase/README.md) | [![samples_tools_use_cases_custom_strong_type_connection_script_tool_showcase](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_custom_strong_type_connection_script_tool_showcase.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_custom_strong_type_connection_script_tool_showcase.yml) | This is a flow demonstrating the use of a script tool with custom string type connection which provides a secure way to manage credentials for external APIs and data sources, and it offers an improved user-friendly and intellisense experience compared to custom connections |
| [custom_llm_tool_showcase](tools/use-cases/custom_llm_tool_showcase/README.md) | [![samples_tools_use_cases_custom_llm_tool_showcase](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_custom_llm_tool_showcase.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_custom_llm_tool_showcase.yml) | This is a flow demonstrating how to use a `custom_llm` tool, `custom_llm` tool allows users to connect to a customized large language model which is fine-tuned by tool developer |
| [custom_llm_tool_showcase](tools/use-cases/custom_llm_tool_showcase/README.md) | [![samples_tools_use_cases_custom_llm_tool_showcase](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_custom_llm_tool_showcase.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_custom_llm_tool_showcase.yml) | This is a flow demonstrating how to use a `custom_llm` tool, which enables users to seamlessly connect with a large language model while fine-tuning their prompts using a `PromptTemplate` |


### Connections ([connections](connections))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
my_tool_package.tools.tool_with_custom_llm_type.my_tool:
name: My Custom LLM Tool
description: This is a tool to demonstrate the custom_llm tool type
description: This is a tool to demonstrate how to customize an LLM tool with a PromptTemplate.
type: custom_llm
module: my_tool_package.tools.tool_with_custom_llm_type
function: my_tool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Flow with custom_llm tool
This is a flow demonstrating how to use a `custom_llm` tool, `custom_llm` tool allows users to connect to a customized large language model which is fine-tuned by tool developer.
This is a flow demonstrating how to use a `custom_llm` tool, which enables users to seamlessly connect with a large language model while fine-tuning their prompts using a `PromptTemplate`.

Tools used in this flow:
- `custom_llm` Tool
Expand Down
10 changes: 9 additions & 1 deletion examples/tools/use-cases/custom_llm_tool_showcase/flow.dag.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
inputs: {}
inputs:
website_name:
type: string
default: Microsoft
user_name:
type: string
default: ""
outputs:
output:
type: string
Expand All @@ -12,3 +18,5 @@ nodes:
path: prompt_template.jinja2
inputs:
connection: basic_custom_connection
website_name: ${inputs.website_name}
user_name: ${inputs.user_name}
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
This is the prompt for my custom LLM tool.
Welcome to {{ website_name }}!
{% if user_name %}
Hello, {{ user_name }}!
{% else %}
Hello there!
{% endif %}

0 comments on commit 2385567

Please sign in to comment.