e768098d0e
Flake8 Lint / flake8 (push) Waiting to run
Spell check CI / Spell_Check (push) Waiting to run
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
109 lines
3.1 KiB
Markdown
109 lines
3.1 KiB
Markdown
# Basic flow with custom connection
|
||
A basic standard flow that using custom python tool calls Azure OpenAI with connection info stored in custom connection.
|
||
|
||
Tools used in this flow:
|
||
- `prompt` tool
|
||
- custom `python` Tool
|
||
|
||
Connections used in this flow:
|
||
- None
|
||
|
||
## Prerequisites
|
||
|
||
Install promptflow sdk and other dependencies:
|
||
```bash
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
## Setup connection
|
||
Prepare your Azure OpenAI resource follow this [instruction](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal) and get your `api_key` if you don't have one.
|
||
|
||
Create connection if you haven't done that.
|
||
```bash
|
||
# Override keys with --set to avoid yaml file changes
|
||
pf connection create -f custom.yml --set secrets.api_key=<your_api_key> configs.api_base=<your_api_base>
|
||
```
|
||
|
||
Ensure you have created `basic_custom_connection` connection.
|
||
```bash
|
||
pf connection show -n basic_custom_connection
|
||
```
|
||
|
||
## Run flow
|
||
|
||
### Run with single line input
|
||
|
||
```bash
|
||
# test with default input value in flow.dag.yaml
|
||
pf flow test --flow .
|
||
|
||
# test with flow inputs
|
||
pf flow test --flow . --inputs text="Hello World!"
|
||
|
||
# test node with inputs
|
||
pf flow test --flow . --node llm --inputs prompt="Write a simple Hello World! program that displays the greeting message."
|
||
|
||
```
|
||
|
||
### Run with multiple lines data
|
||
|
||
- create run
|
||
```bash
|
||
pf run create --flow . --data ./data.jsonl --column-mapping text='${data.text}' --stream
|
||
```
|
||
|
||
You can also skip providing `column-mapping` if provided data has same column name as the flow.
|
||
Reference [here](https://aka.ms/pf/column-mapping) for default behavior when `column-mapping` not provided in CLI.
|
||
|
||
- list and show run meta
|
||
```bash
|
||
# list created run
|
||
pf run list -r 3
|
||
|
||
# get a sample run name
|
||
name=$(pf run list -r 10 | jq '.[] | select(.name | contains("basic_with_connection")) | .name'| head -n 1 | tr -d '"')
|
||
|
||
# show specific run detail
|
||
pf run show --name $name
|
||
|
||
# show output
|
||
pf run show-details --name $name
|
||
|
||
# visualize run in browser
|
||
pf run visualize --name $name
|
||
```
|
||
|
||
### Run with connection override
|
||
|
||
Ensure you have created `open_ai_connection` connection before.
|
||
|
||
```bash
|
||
pf connection show -n open_ai_connection
|
||
```
|
||
|
||
Create connection if you haven't done that.
|
||
```bash
|
||
# Override keys with --set to avoid yaml file changes
|
||
pf connection create --file ../../../connections/azure_openai.yml --set api_key=<your_api_key> api_base=<your_api_base>
|
||
```
|
||
|
||
Run flow with newly created connection.
|
||
|
||
```bash
|
||
pf run create --flow . --data ./data.jsonl --connections llm.connection=open_ai_connection --column-mapping text='${data.text}' --stream
|
||
```
|
||
|
||
### Run in cloud with connection override
|
||
|
||
Ensure you have created `open_ai_connection` connection in cloud. Reference [this notebook](../../../tutorials/get-started/quickstart-azure.ipynb) on how to create connections in cloud with UI.
|
||
|
||
Run flow with connection `open_ai_connection`.
|
||
|
||
```bash
|
||
# set default workspace
|
||
az account set -s <your_subscription_id>
|
||
az configure --defaults group=<your_resource_group_name> workspace=<your_workspace_name>
|
||
|
||
pfazure run create --flow . --data ./data.jsonl --connections llm.connection=open_ai_connection --column-mapping text='${data.text}' --stream
|
||
```
|