promptflow
Basic standard flow
A basic standard flow define using function entry that calls Azure OpenAI with connection info stored in environment variables.
Prerequisites
Install promptflow sdk and other dependencies:
pip install -r requirements.txt
Run flow
-
Prepare your Azure Open AI resource follow this instruction and get your
api_key
if you don't have one. -
Setup environment variables
Ensure you have put your azure open ai endpoint key in .env file. You can create one refer to this example file.
cat ../.env
- Run/Debug as normal Python file
python programmer.py
- Test with flow entry
pf flow test --flow programmer:write_simple_program --inputs text="Java Hello World!"
- Test with flow yaml
# test with sample input value in flow.flex.yamlpf flow test --flow .
# test with UIpf flow test --flow . --ui
- Create run with multiple lines data
# using environment from .env file (loaded in user code: hello.py)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 for default behavior when column-mapping
not provided in CLI.
- List and show run meta
# list created runpf run list
# get a sample run name
name=$(pf run list -r 10 | jq '.[] | select(.name | contains("basic_")) | .name'| head -n 1 | tr -d '"')# show specific run detailpf run show --name $name
# show outputpf run show-details --name $name
# visualize run in browserpf run visualize --name $name
Run flow in cloud with connection
- Assume we already have a connection named
open_ai_connection
in workspace.
# set default workspaceaz account set -s <your_subscription_id>az configure --defaults group=<your_resource_group_name> workspace=<your_workspace_name>
- Create run
# run with environment variable reference connection in azureml workspacepfazure run create --flow . --data ./data.jsonl --column-mapping text='${data.text}' --environment-variables AZURE_OPENAI_API_KEY='${open_ai_connection.api_key}' AZURE_OPENAI_ENDPOINT='${open_ai_connection.api_base}' --stream# run using yaml filepfazure run create --file run.yml --stream
- List and show run meta
# list created runpfazure run list -r 3
# get a sample run namename=$(pfazure run list -r 100 | jq '.[] | select(.name | contains("basic_")) | .name'| head -n 1 | tr -d '"')
# show specific run detailpfazure run show --name $name
# show outputpfazure run show-details --name $name
# visualize run in browserpfazure run visualize --name $name