Skip to content

Commit

Permalink
add workflow for example flows
Browse files Browse the repository at this point in the history
  • Loading branch information
yalu4 committed Oct 20, 2023
1 parent 84c8279 commit 2c6a3c3
Show file tree
Hide file tree
Showing 14 changed files with 383 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# This code is autogenerated.
# Code is generated by running custom script: python3 readme.py
# Any manual changes to this file may cause incorrect behavior.
# Any manual changes will be overwritten if the code is regenerated.

name: samples_flows_standard_flow_with_package_tool_using_custom_strong_type_connection
on:
schedule:
- cron: "38 19 * * *" # Every day starting at 3:38 BJT
pull_request:
branches: [ main ]
paths: [ examples/flows/standard/flow-with-package-tool-using-custom-strong-type-connection/**, examples/*requirements.txt, .github/workflows/samples_flows_standard_flow_with_package_tool_using_custom_strong_type_connection.yml ]
workflow_dispatch:

jobs:
samples_readme_ci:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.9 environment
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Generate config.json
run: echo '${{ secrets.TEST_WORKSPACE_CONFIG_JSON_CANARY }}' > ${{ github.workspace }}/examples/config.json
- name: Prepare requirements
working-directory: examples
run: |
if [[ -e requirements.txt ]]; then
python -m pip install --upgrade pip
pip install -r requirements.txt
fi
- name: Prepare dev requirements
working-directory: examples
run: |
python -m pip install --upgrade pip
pip install -r dev_requirements.txt
- name: Refine .env file
working-directory: examples/flows/standard/flow-with-package-tool-using-custom-strong-type-connection
run: |
AOAI_API_KEY=${{ secrets.AOAI_API_KEY_TEST }}
AOAI_API_ENDPOINT=${{ secrets.AOAI_API_ENDPOINT_TEST }}
AOAI_API_ENDPOINT=$(echo ${AOAI_API_ENDPOINT//\//\\/})
if [[ -e .env.example ]]; then
echo "env replacement"
sed -i -e "s/<your_AOAI_key>/$AOAI_API_KEY/g" -e "s/<your_AOAI_endpoint>/$AOAI_API_ENDPOINT/g" .env.example
mv .env.example .env
fi
- name: Create run.yml
working-directory: examples/flows/standard/flow-with-package-tool-using-custom-strong-type-connection
run: |
gpt_base=${{ secrets.AOAI_API_ENDPOINT_TEST }}
gpt_base=$(echo ${gpt_base//\//\\/})
if [[ -e run.yml ]]; then
sed -i -e "s/\${azure_open_ai_connection.api_key}/${{ secrets.AOAI_API_KEY_TEST }}/g" -e "s/\${azure_open_ai_connection.api_base}/$gpt_base/g" run.yml
fi
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Extract Steps examples/flows/standard/flow-with-package-tool-using-custom-strong-type-connection/README.md
working-directory: ${{ github.workspace }}
run: |
python scripts/readme/extract_steps_from_readme.py -f examples/flows/standard/flow-with-package-tool-using-custom-strong-type-connection/README.md -o examples/flows/standard/flow-with-package-tool-using-custom-strong-type-connection
- name: Cat script
working-directory: examples/flows/standard/flow-with-package-tool-using-custom-strong-type-connection
run: |
cat bash_script.sh
- name: Run scripts
working-directory: examples/flows/standard/flow-with-package-tool-using-custom-strong-type-connection
run: |
export aoai_api_key=${{secrets.AOAI_API_KEY_TEST }}
export aoai_api_endpoint=${{ secrets.AOAI_API_ENDPOINT_TEST }}
export test_workspace_sub_id=${{ secrets.TEST_WORKSPACE_SUB_ID }}
export test_workspace_rg=${{ secrets.TEST_WORKSPACE_RG }}
export test_workspace_name=${{ secrets.TEST_WORKSPACE_NAME_CANARY }}
bash bash_script.sh
- name: Pip List for Debug
if : ${{ always() }}
working-directory: examples/flows/standard/flow-with-package-tool-using-custom-strong-type-connection
run: |
pip list
- name: Upload artifact
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: artifact
path: examples/flows/standard/flow-with-package-tool-using-custom-strong-type-connection/bash_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# This code is autogenerated.
# Code is generated by running custom script: python3 readme.py
# Any manual changes to this file may cause incorrect behavior.
# Any manual changes will be overwritten if the code is regenerated.

name: samples_flows_standard_flow_with_script_tool_using_custom_strong_type_connection
on:
schedule:
- cron: "13 20 * * *" # Every day starting at 4:13 BJT
pull_request:
branches: [ main ]
paths: [ examples/flows/standard/flow-with-script-tool-using-custom-strong-type-connection/**, examples/*requirements.txt, .github/workflows/samples_flows_standard_flow_with_script_tool_using_custom_strong_type_connection.yml ]
workflow_dispatch:

jobs:
samples_readme_ci:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.9 environment
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Generate config.json
run: echo '${{ secrets.TEST_WORKSPACE_CONFIG_JSON_CANARY }}' > ${{ github.workspace }}/examples/config.json
- name: Prepare requirements
working-directory: examples
run: |
if [[ -e requirements.txt ]]; then
python -m pip install --upgrade pip
pip install -r requirements.txt
fi
- name: Prepare dev requirements
working-directory: examples
run: |
python -m pip install --upgrade pip
pip install -r dev_requirements.txt
- name: Refine .env file
working-directory: examples/flows/standard/flow-with-script-tool-using-custom-strong-type-connection
run: |
AOAI_API_KEY=${{ secrets.AOAI_API_KEY_TEST }}
AOAI_API_ENDPOINT=${{ secrets.AOAI_API_ENDPOINT_TEST }}
AOAI_API_ENDPOINT=$(echo ${AOAI_API_ENDPOINT//\//\\/})
if [[ -e .env.example ]]; then
echo "env replacement"
sed -i -e "s/<your_AOAI_key>/$AOAI_API_KEY/g" -e "s/<your_AOAI_endpoint>/$AOAI_API_ENDPOINT/g" .env.example
mv .env.example .env
fi
- name: Create run.yml
working-directory: examples/flows/standard/flow-with-script-tool-using-custom-strong-type-connection
run: |
gpt_base=${{ secrets.AOAI_API_ENDPOINT_TEST }}
gpt_base=$(echo ${gpt_base//\//\\/})
if [[ -e run.yml ]]; then
sed -i -e "s/\${azure_open_ai_connection.api_key}/${{ secrets.AOAI_API_KEY_TEST }}/g" -e "s/\${azure_open_ai_connection.api_base}/$gpt_base/g" run.yml
fi
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Extract Steps examples/flows/standard/flow-with-script-tool-using-custom-strong-type-connection/README.md
working-directory: ${{ github.workspace }}
run: |
python scripts/readme/extract_steps_from_readme.py -f examples/flows/standard/flow-with-script-tool-using-custom-strong-type-connection/README.md -o examples/flows/standard/flow-with-script-tool-using-custom-strong-type-connection
- name: Cat script
working-directory: examples/flows/standard/flow-with-script-tool-using-custom-strong-type-connection
run: |
cat bash_script.sh
- name: Run scripts
working-directory: examples/flows/standard/flow-with-script-tool-using-custom-strong-type-connection
run: |
export aoai_api_key=${{secrets.AOAI_API_KEY_TEST }}
export aoai_api_endpoint=${{ secrets.AOAI_API_ENDPOINT_TEST }}
export test_workspace_sub_id=${{ secrets.TEST_WORKSPACE_SUB_ID }}
export test_workspace_rg=${{ secrets.TEST_WORKSPACE_RG }}
export test_workspace_name=${{ secrets.TEST_WORKSPACE_NAME_CANARY }}
bash bash_script.sh
- name: Pip List for Debug
if : ${{ always() }}
working-directory: examples/flows/standard/flow-with-script-tool-using-custom-strong-type-connection
run: |
pip list
- name: Upload artifact
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: artifact
path: examples/flows/standard/flow-with-script-tool-using-custom-strong-type-connection/bash_script.sh
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
| [conditional-flow-for-switch](flows/standard/conditional-flow-for-switch/README.md) | [![samples_flows_standard_conditional_flow_for_switch](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_conditional_flow_for_switch.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_conditional_flow_for_switch.yml) | This example is a conditional flow for switch scenario |
| [customer-intent-extraction](flows/standard/customer-intent-extraction/README.md) | [![samples_flows_standard_customer_intent_extraction](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_customer_intent_extraction.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_customer_intent_extraction.yml) | This sample is using OpenAI chat model(ChatGPT/GPT4) to identify customer intent from customer's question |
| [flow-with-additional-includes](flows/standard/flow-with-additional-includes/README.md) | [![samples_flows_standard_flow_with_additional_includes](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_flow_with_additional_includes.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_flow_with_additional_includes.yml) | User sometimes need to reference some common files or folders, this sample demos how to solve the problem using additional_includes |
| [flow-with-package-tool-using-custom-strong-type-connection](flows/standard/flow-with-package-tool-using-custom-strong-type-connection/README.md) | [![samples_flows_standard_flow_with_package_tool_using_custom_strong_type_connection](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_flow_with_package_tool_using_custom_strong_type_connection.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_flow_with_package_tool_using_custom_strong_type_connection.yml) | A basic standard flow that using custom python tool calls Azure OpenAI with connection info stored in custom connection |
| [flow-with-script-tool-using-custom-strong-type-connection](flows/standard/flow-with-script-tool-using-custom-strong-type-connection/README.md) | [![samples_flows_standard_flow_with_script_tool_using_custom_strong_type_connection](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_flow_with_script_tool_using_custom_strong_type_connection.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_flow_with_script_tool_using_custom_strong_type_connection.yml) | A basic standard flow that using custom python tool calls Azure OpenAI with connection info stored in custom connection |
| [flow-with-symlinks](flows/standard/flow-with-symlinks/README.md) | [![samples_flows_standard_flow_with_symlinks](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_flow_with_symlinks.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_flow_with_symlinks.yml) | User sometimes need to reference some common files or folders, this sample demos how to solve the problem using symlinks |
| [gen-docstring](flows/standard/gen-docstring/README.md) | [![samples_flows_standard_gen_docstring](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_gen_docstring.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_gen_docstring.yml) | This example can help you automatically generate Python code's docstring and return the modified code |
| [maths-to-code](flows/standard/maths-to-code/README.md) | [![samples_flows_standard_maths_to_code](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_maths_to_code.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_flows_standard_maths_to_code.yml) | Math to Code is a project that utilizes the power of the chatGPT model to generate code that models math questions and then executes the generated code to obtain the final numerical answer |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Basic flow with package tool using custom strong type 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:
- custom package Tool

Connections used in this flow:
- custom strong type connection

## Prerequisites

Install promptflow sdk and other dependencies:
```bash
pip install -r requirements.txt
```

## Setup connection
Create connection if you haven't done that.
```bash
# Override keys with --set to avoid yaml file changes
pf connection create -f my_custom_connection.yml --set secrets.api_key=<your_api_key> configs.api_base=<your_api_base>
```

Ensure you have created `my_custom_connection` connection.
```bash
pf connection show -n my_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="Promptflow"


### Run with multiple lines data

- create run
```bash
pf run create --flow . --data ./data.jsonl --stream
```

- 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("custom_strong_type")) | .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

Run flow with newly created connection.

```bash
pf run create --flow . --data ./data.jsonl --connections my_package_tool.connection=my_custom_connection --stream
```

### Run in cloud with connection override

Ensure you have created `my_custom_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 `my_custom_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 my_package_tool.connection=my_custom_connection --stream --runtime demo-mir
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ nodes:
type: package
tool: my_tool_package.tools.my_tool_2.MyTool.my_tool
inputs:
connection: custom_connection_2
connection: my_first_custom_connection
input_text: ${inputs.my_input}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "to_replace_with_connection_name"
type: custom
custom_type: MyCustomConnection
module: my_tool_package.tools.my_tool_with_custom_strong_type_connection
package: test-custom-tools
package_version: 0.0.2
configs:
api_url: "This is a fake api url." # String, The api url.
secrets:
api_key: <user-input> # Don't replace the '<user-input>' placeholder. The application will prompt you to enter a value when it runs.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Basic flow with script tool using custom strong type 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:
- custom `python` Tool

Connections used in this flow:
- custom strong type connection

## Prerequisites

Install promptflow sdk and other dependencies:
```bash
pip install -r requirements.txt
```

## Setup connection
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 `normal_custom_connection` connection.
```bash
pf connection show -n normal_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="Promptflow"


### Run with multiple lines data

- create run
```bash
pf run create --flow . --data ./data.jsonl --stream
```

- 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("custom_strong_type")) | .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

Run flow with newly created connection.

```bash
pf run create --flow . --data ./data.jsonl --connections my_script_tool.connection=normal_custom_connection --stream
```

### Run in cloud with connection override

Ensure you have created `normal_custom_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 `normal_custom_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 my_script_tool.connection=normal_custom_connection --stream --runtime demo-mir
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$schema: https://azuremlschemas.azureedge.net/promptflow/latest/CustomConnection.schema.json
name: normal_custom_connection
type: custom
configs:
api_base: test
secrets: # must-have
api_key: <to-be-replaced>
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{"my_input": "hello world!"}
{"text": "Python Hello World!"}
{"text": "C Hello World!"}
{"text": "C# Hello World!"}
Loading

0 comments on commit 2c6a3c3

Please sign in to comment.