Skip to content

Commit

Permalink
Merge branch 'main' into jiazeng/template
Browse files Browse the repository at this point in the history
  • Loading branch information
jiazengcindy authored Oct 27, 2023
2 parents 9e33794 + addda06 commit 23e2e13
Show file tree
Hide file tree
Showing 34 changed files with 506 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Any manual changes to this file may cause incorrect behavior.
# Any manual changes will be overwritten if the code is regenerated.

name: samples_tools_use_cases_flow_with_enabled_by_value
name: samples_tools_use_cases_cascading_inputs_tool_showcase
on:
schedule:
- cron: "13 22 * * *" # Every day starting at 6:13 BJT
- cron: "41 20 * * *" # Every day starting at 4:41 BJT
pull_request:
branches: [ main ]
paths: [ examples/tools/use-cases/flow-with-enabled-by-value/**, examples/*requirements.txt, .github/workflows/samples_tools_use_cases_flow_with_enabled_by_value.yml ]
paths: [ examples/tools/use-cases/cascading-inputs-tool-showcase/**, examples/*requirements.txt, .github/workflows/samples_tools_use_cases_cascading_inputs_tool_showcase.yml ]
workflow_dispatch:

env:
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r dev_requirements.txt
- name: Refine .env file
working-directory: examples/tools/use-cases/flow-with-enabled-by-value
working-directory: examples/tools/use-cases/cascading-inputs-tool-showcase
run: |
AOAI_API_KEY=${{ secrets.AOAI_API_KEY_TEST }}
AOAI_API_ENDPOINT=${{ secrets.AOAI_API_ENDPOINT_TEST }}
Expand All @@ -51,7 +51,7 @@ jobs:
mv .env.example .env
fi
- name: Create run.yml
working-directory: examples/tools/use-cases/flow-with-enabled-by-value
working-directory: examples/tools/use-cases/cascading-inputs-tool-showcase
run: |
gpt_base=${{ secrets.AOAI_API_ENDPOINT_TEST }}
gpt_base=$(echo ${gpt_base//\//\\/})
Expand All @@ -62,16 +62,16 @@ jobs:
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Extract Steps examples/tools/use-cases/flow-with-enabled-by-value/README.md
- name: Extract Steps examples/tools/use-cases/cascading-inputs-tool-showcase/README.md
working-directory: ${{ github.workspace }}
run: |
python scripts/readme/extract_steps_from_readme.py -f examples/tools/use-cases/flow-with-enabled-by-value/README.md -o examples/tools/use-cases/flow-with-enabled-by-value
python scripts/readme/extract_steps_from_readme.py -f examples/tools/use-cases/cascading-inputs-tool-showcase/README.md -o examples/tools/use-cases/cascading-inputs-tool-showcase
- name: Cat script
working-directory: examples/tools/use-cases/flow-with-enabled-by-value
working-directory: examples/tools/use-cases/cascading-inputs-tool-showcase
run: |
cat bash_script.sh
- name: Run scripts
working-directory: examples/tools/use-cases/flow-with-enabled-by-value
working-directory: examples/tools/use-cases/cascading-inputs-tool-showcase
run: |
export aoai_api_key=${{secrets.AOAI_API_KEY_TEST }}
export aoai_api_endpoint=${{ secrets.AOAI_API_ENDPOINT_TEST }}
Expand All @@ -81,12 +81,12 @@ jobs:
bash bash_script.sh
- name: Pip List for Debug
if : ${{ always() }}
working-directory: examples/tools/use-cases/flow-with-enabled-by-value
working-directory: examples/tools/use-cases/cascading-inputs-tool-showcase
run: |
pip list
- name: Upload artifact
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: artifact
path: examples/tools/use-cases/flow-with-enabled-by-value/bash_script.sh
path: examples/tools/use-cases/cascading-inputs-tool-showcase/bash_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# 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_tools_use_cases_custom_strong_type_connection_package_tool_showcase
on:
schedule:
- cron: "0 20 * * *" # Every day starting at 4:0 BJT
pull_request:
branches: [ main ]
paths: [ examples/tools/use-cases/custom-strong-type-connection-package-tool-showcase/**, examples/*requirements.txt, .github/workflows/samples_tools_use_cases_custom_strong_type_connection_package_tool_showcase.yml ]
workflow_dispatch:

env:
IS_IN_CI_PIPELINE: "true"

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/tools/use-cases/custom-strong-type-connection-package-tool-showcase
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/tools/use-cases/custom-strong-type-connection-package-tool-showcase
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/tools/use-cases/custom-strong-type-connection-package-tool-showcase/README.md
working-directory: ${{ github.workspace }}
run: |
python scripts/readme/extract_steps_from_readme.py -f examples/tools/use-cases/custom-strong-type-connection-package-tool-showcase/README.md -o examples/tools/use-cases/custom-strong-type-connection-package-tool-showcase
- name: Cat script
working-directory: examples/tools/use-cases/custom-strong-type-connection-package-tool-showcase
run: |
cat bash_script.sh
- name: Run scripts
working-directory: examples/tools/use-cases/custom-strong-type-connection-package-tool-showcase
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/tools/use-cases/custom-strong-type-connection-package-tool-showcase
run: |
pip list
- name: Upload artifact
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: artifact
path: examples/tools/use-cases/custom-strong-type-connection-package-tool-showcase/bash_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# 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_tools_use_cases_custom_strong_type_connection_script_tool_showcase
on:
schedule:
- cron: "58 20 * * *" # Every day starting at 4:58 BJT
pull_request:
branches: [ main ]
paths: [ examples/tools/use-cases/custom-strong-type-connection-script-tool-showcase/**, examples/*requirements.txt, .github/workflows/samples_tools_use_cases_custom_strong_type_connection_script_tool_showcase.yml ]
workflow_dispatch:

env:
IS_IN_CI_PIPELINE: "true"

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/tools/use-cases/custom-strong-type-connection-script-tool-showcase
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/tools/use-cases/custom-strong-type-connection-script-tool-showcase
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/tools/use-cases/custom-strong-type-connection-script-tool-showcase/README.md
working-directory: ${{ github.workspace }}
run: |
python scripts/readme/extract_steps_from_readme.py -f examples/tools/use-cases/custom-strong-type-connection-script-tool-showcase/README.md -o examples/tools/use-cases/custom-strong-type-connection-script-tool-showcase
- name: Cat script
working-directory: examples/tools/use-cases/custom-strong-type-connection-script-tool-showcase
run: |
cat bash_script.sh
- name: Run scripts
working-directory: examples/tools/use-cases/custom-strong-type-connection-script-tool-showcase
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/tools/use-cases/custom-strong-type-connection-script-tool-showcase
run: |
pip list
- name: Upload artifact
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: artifact
path: examples/tools/use-cases/custom-strong-type-connection-script-tool-showcase/bash_script.sh
6 changes: 3 additions & 3 deletions docs/how-to-guides/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,19 @@ The return value of `test` function is the flow/node outputs.
```python
from promptflow import PFClient

pf_client = PFClient()
pf = PFClient()

flow_path = "web-classification" # "web-classification" is the directory name

# Test flow
flow_inputs = {"url": "https://www.youtube.com/watch?v=o5ZQyXaAv1g", "answer": "Channel", "evidence": "Url"} # The inputs of the flow.
flow_result = pf_client.test(flow=flow_path, inputs=inputs)
flow_result = pf.test(flow=flow_path, inputs=inputs)
print(f"Flow outputs: {flow_result}")

# Test node in the flow
node_name = "fetch_text_content_from_url" # The node name in the flow.
node_inputs = {"url": "https://www.youtube.com/watch?v=o5ZQyXaAv1g"} # The inputs of the node.
node_result = pf_client.test(flow=flow_path, inputs=node_inputs, node=node_name)
node_result = pf.test(flow=flow_path, inputs=node_inputs, node=node_name)
print(f"Node outputs: {node_result}")
```

Expand Down
15 changes: 13 additions & 2 deletions docs/how-to-guides/run-and-evaluate-a-flow/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ A bulk test allows you to run your flow with a large dataset and generate output

Let's create a run with flow [web-classification](https://github.com/microsoft/promptflow/tree/main/examples/flows/standard/web-classification). It is a flow demonstrating multi-class classification with LLM. Given an url, it will classify the url into one web category with just a few shots, simple summarization and classification prompts.

To begin with the guide, git clone the sample repository(above flow link) and set the working directory to `<path-to-the-sample-repo>/examples/flows/`.

To begin with the guide, you need:
- Git clone the sample repository(above flow link) and set the working directory to `<path-to-the-sample-repo>/examples/flows/`.
- Make sure you have already created the necessary connection following [Create necessary connections](../quick-start.md#create-necessary-connections).
::::{tab-set}

:::{tab-item} CLI
Expand Down Expand Up @@ -57,6 +58,11 @@ More details can be found with `pf run --help`
:sync: SDK

```python
from promptflow import PFClient

# PFClient can help manage your runs and connections.
pf = PFClient()

# Set flow path and run input data
flow = "standard/web-classification" # set the flow directory
data= "standard/web-classification/data.jsonl" # set the data file
Expand Down Expand Up @@ -164,6 +170,11 @@ After the run is finished, you can evaluate the run with below command, compared
More details can be found in [Use column mapping](https://aka.ms/pf/column-mapping).

```python
from promptflow import PFClient

# PFClient can help manage your runs and connections.
pf = PFClient()

# set eval flow path
eval_flow = "evaluation/eval-classification-accuracy"
data= "standard/web-classification/data.jsonl"
Expand Down
4 changes: 3 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@

| path | status | description |
------|--------|-------------
| [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 |
| [flow-with-enabled-by-value](tools/use-cases/flow-with-enabled-by-value/README.md) | [![samples_tools_use_cases_flow_with_enabled_by_value](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_flow_with_enabled_by_value.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tools_use_cases_flow_with_enabled_by_value.yml) | A standard flow using "enabled_by_value" python tool |


### Connections ([connections](connections))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UserType(str, Enum):

@tool
def my_tool(user_type: Enum, student_id: str = "", teacher_id: str = "") -> str:
"""This is a dummy function to support enabled by feature.
"""This is a dummy function to support cascading inputs.
:param user_type: user type, student or teacher.
:param student_id: student id.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
my_tool_package.tools.tool_with_enabled_by_value.my_tool:
my_tool_package.tools.tool_with_cascading_inputs.my_tool:
function: my_tool
inputs:
user_type:
Expand All @@ -17,7 +17,7 @@ my_tool_package.tools.tool_with_enabled_by_value.my_tool:
- string
enabled_by: user_type
enabled_by_value: [teacher]
module: my_tool_package.tools.tool_with_enabled_by_value
name: My Tool with Enabled By Value
description: This is my tool with enabled by value
module: my_tool_package.tools.tool_with_cascading_inputs
name: My Tool with Cascading Inputs
description: This is my tool with cascading inputs
type: python
2 changes: 1 addition & 1 deletion examples/tools/tool-package-quickstart/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name=PACKAGE_NAME,
version="0.0.6",
version="0.0.7",
description="This is my tools package",
packages=find_packages(),
entry_points={
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from my_tool_package.tools.tool_with_cascading_inputs import my_tool


def test_my_tool():
result = my_tool(user_type="student", student_id="student_id")
assert result == '123'

This file was deleted.

Loading

0 comments on commit 23e2e13

Please sign in to comment.