Skip to content

Commit

Permalink
[Sample] Create CI for sample service (#1334)
Browse files Browse the repository at this point in the history
This pull request includes various updates to documentation files and
workflow files for improved organization and triggering conditions. The
most important changes include renaming and updating the content of a
readme file, updating triggering conditions for multiple workflow files,
and adding a new workflow file for running daily and on pull requests.

Documentation updates:

* <a
href="diffhunk://#diff-16d6365d8923a3a8b67448ce0fef412f6c0e48304129f9fc929420c498f5b44cL3-R21">`examples/tutorials/flow-deploy/create-service-with-flow/README.md`</a>:
Renamed `readme.md` to `README.md` and updated its content to include
instructions on starting the service and testing it with a request.
* <a
href="diffhunk://#diff-49aaa2819e35a856818ecec8c9fa7e1c79ad028d3f44bd749736353cfb51bac9R31">`examples/README.md`</a>:
Added a new entry for the `create-service-with-flow` example, including
a badge for the workflow and a brief description.

Workflow updates:

* <a
href="diffhunk://#diff-fb7c6e9c6f259fe228974b302120eae8d6e05762f555a0fcf364c02de1dbdcb8R1-R96">`.github/workflows/samples_tutorials_flow_deploy_create_service_with_flow.yml`</a>:
Added a new workflow file that runs daily and on pull requests, with
various steps including generating config files, setting up
environments, running scripts, and uploading artifacts.
* <a
href="diffhunk://#diff-a44df53d3ec63f6fb804dc7861f8591528dcbe8b2a136fd91c2fa8fa958575f8L12-R12">`.github/workflows/samples_tutorials_flow_deploy_kubernetes.yml`</a>:
Updated triggering conditions to include the
`examples/flows/integrations/**` path on pull requests.
* <a
href="diffhunk://#diff-f7766a5c1b9b58a22fdeac882a0c1cc705d0041af20fd65b2ca1147a5babdc76L12-R12">`.github/workflows/samples_tutorials_flow_deploy_distribute_flow_as_executable_app.yml`</a>:
Updated workflow file to remove the exclusion of the
`examples/flows/integrations/**` path from triggering the workflow on
pull requests.
* <a
href="diffhunk://#diff-3d8d0c1a308ee42c43bc7fb8aa811e2ace33a28370c5fe83e0d2ed5029f0e96eL12-R12">`.github/workflows/samples_tutorials_e2e_development_chat_with_pdf.yml`</a>:
Updated triggering conditions to remove the exclusion of the
`examples/flows/integrations/**` path from triggering the workflow on
pull requests.
* <a
href="diffhunk://#diff-e33d15fd8335c327e5c2bd0c64edf8b9d6ba74d71b46cdcd847b4b46df5de9daL12-R12">`.github/workflows/samples_configuration.yml`</a>:
Updated triggering conditions to remove the exclusion of
`examples/flows/integrations/**` and add an exclusion for files ending
with `requirements.txt`.
* <a
href="diffhunk://#diff-2b597aa0e3ee9c2204912a626cc178ec1936a833fb52e40b38e2f0a8014ad2a5L12-R12">`.github/workflows/samples_tutorials_flow_deploy_azure_app_service.yml`</a>:
Updated triggering conditions to remove the exclusion of the
`examples/flows/integrations/**` path.
* <a
href="diffhunk://#diff-f4d7aa3a413922191317263ca61fa5037e19395db3bd5c5993a8976878c1606dL12-R12">`.github/workflows/samples_tutorials_flow_deploy_docker.yml`</a>:
Updated triggering conditions to remove the exclusion of the
`examples/flows/integrations/**` path from triggering the workflow on
pull requests.
* <a
href="diffhunk://#diff-843ab2b8f6c9bf0a7e795425bd0e414d8bf60d320829a2f42a0329dab8ac140eL12-R12">`.github/workflows/samples_tutorials_flow_fine_tuning_evaluation_promptflow_quality_improvement.yml`</a>:
Updated triggering conditions to remove the exclusion of the
`examples/flows/integrations/**` path from triggering the workflow on
pull requests.# Description

Please add an informative description that covers that changes made by
the pull request and link all relevant issues.

# All Promptflow Contribution checklist:
- [ ] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [ ] Title of the pull request is clear and informative.
- [ ] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.
  • Loading branch information
D-W- authored Dec 7, 2023
1 parent e381b87 commit 449d679
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 19 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"restx",
"httpx",
"tiiuae",
"nohup",
"metagenai"
],
"flagWords": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 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_tutorials_flow_deploy_create_service_with_flow
on:
schedule:
- cron: "49 22 * * *" # Every day starting at 6:49 BJT
pull_request:
branches: [ main ]
paths: [ examples/**, .github/workflows/samples_tutorials_flow_deploy_create_service_with_flow.yml ]
workflow_dispatch:

env:
IS_IN_CI_PIPELINE: "true"

jobs:
samples_readme_ci:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python 3.9 environment
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Generate config.json for canary workspace (scheduled runs only)
if: github.event_name == 'schedule'
run: echo '${{ secrets.TEST_WORKSPACE_CONFIG_JSON_CANARY }}' > ${{ github.workspace }}/examples/config.json
- name: Generate config.json for production workspace
if: github.event_name != 'schedule'
run: echo '${{ secrets.EXAMPLE_WORKSPACE_CONFIG_JSON_PROD }}' > ${{ 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/tutorials/flow-deploy/create-service-with-flow
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/tutorials/flow-deploy/create-service-with-flow
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/tutorials/flow-deploy/create-service-with-flow/README.md
working-directory: ${{ github.workspace }}
run: |
python scripts/readme/extract_steps_from_readme.py -f examples/tutorials/flow-deploy/create-service-with-flow/README.md -o examples/tutorials/flow-deploy/create-service-with-flow
- name: Cat script
working-directory: examples/tutorials/flow-deploy/create-service-with-flow
run: |
cat bash_script.sh
- name: Run scripts
working-directory: examples/tutorials/flow-deploy/create-service-with-flow
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/tutorials/flow-deploy/create-service-with-flow
run: |
pip list
- name: Upload artifact
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: artifact
path: examples/tutorials/flow-deploy/create-service-with-flow/bash_script.sh
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
------|--------|-------------
| [chat-with-pdf](tutorials/e2e-development/chat-with-pdf.md) | [![samples_tutorials_e2e_development_chat_with_pdf](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_e2e_development_chat_with_pdf.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_e2e_development_chat_with_pdf.yml) | Retrieval Augmented Generation (or RAG) has become a prevalent pattern to build intelligent application with Large Language Models (or LLMs) since it can infuse external knowledge into the model, which is not trained with those up-to-date or proprietary information |
| [azure-app-service](tutorials/flow-deploy/azure-app-service/README.md) | [![samples_tutorials_flow_deploy_azure_app_service](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_flow_deploy_azure_app_service.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_flow_deploy_azure_app_service.yml) | This example demos how to deploy a flow using Azure App Service |
| [create-service-with-flow](tutorials/flow-deploy/create-service-with-flow/README.md) | [![samples_tutorials_flow_deploy_create_service_with_flow](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_flow_deploy_create_service_with_flow.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_flow_deploy_create_service_with_flow.yml) | This example shows how to create a simple service with flow |
| [distribute-flow-as-executable-app](tutorials/flow-deploy/distribute-flow-as-executable-app/README.md) | [![samples_tutorials_flow_deploy_distribute_flow_as_executable_app](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_flow_deploy_distribute_flow_as_executable_app.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_flow_deploy_distribute_flow_as_executable_app.yml) | This example demos how to package flow as a executable app |
| [docker](tutorials/flow-deploy/docker/README.md) | [![samples_tutorials_flow_deploy_docker](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_flow_deploy_docker.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_flow_deploy_docker.yml) | This example demos how to deploy flow as a docker app |
| [kubernetes](tutorials/flow-deploy/kubernetes/README.md) | [![samples_tutorials_flow_deploy_kubernetes](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_flow_deploy_kubernetes.yml/badge.svg?branch=main)](https://github.com/microsoft/promptflow/actions/workflows/samples_tutorials_flow_deploy_kubernetes.yml) | This example demos how to deploy flow as a Kubernetes app |
Expand Down Expand Up @@ -122,4 +123,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope

## Reference

* [Promptflow documentation](https://microsoft.github.io/promptflow/)
* [Promptflow documentation](https://microsoft.github.io/promptflow/)
2 changes: 1 addition & 1 deletion examples/dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ black-nb
pypandoc # for markdown reader
pypandoc_binary # pypandoc pandoc backend
panflute # for pandoc filters
jinja2 # for readme generations
jinja2 # for readme generations
38 changes: 38 additions & 0 deletions examples/tutorials/flow-deploy/create-service-with-flow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Create service with flow

This example shows how to create a simple service with flow.

You can create your own service by utilize `flow-as-function`.

This folder contains a example on how to build a service with a flow.
Reference [here](./simple_score.py) for a minimal service example.
The output of score.py will be a json serialized dictionary.
You can use json parser to parse the output.

## 1. Start the service and put in background

```bash
nohup python simple_score.py &
# Note: added this to run in our CI pipeline, not needed for user.
sleep 10
```

## 2. Test the service with request

Executing the following command to send a request to execute a flow.

```bash
curl -X POST http://127.0.0.1:5000/score --header "Content-Type: application/json" --data '{"flow_input": "some_flow_input", "node_input": "some_node_input"}'
```

Sample output of the request:

```json
{
"output": {
"value": "some_flow_input"
}
}
```

Reference [here](./simple_score.py) for more.
12 changes: 0 additions & 12 deletions examples/tutorials/flow-deploy/create-service-with-flow/readme.md

This file was deleted.

15 changes: 10 additions & 5 deletions scripts/readme/ghactions_driver/readme_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,16 @@ def git_base_dir() -> str:
Get the base directory of the git repo
"""
if ReadmeStepsManage.repo_base_dir == "":
ReadmeStepsManage.repo_base_dir = (
subprocess.check_output(["git", "rev-parse", "--show-toplevel"])
.decode("utf-8")
.strip()
)
try:
ReadmeStepsManage.repo_base_dir = (
subprocess.check_output(["git", "rev-parse", "--show-toplevel"])
.decode("utf-8")
.strip()
)
raise Exception("Not in git repo")
except Exception:
ReadmeStepsManage.repo_base_dir = Path(__file__).parent.parent.parent.parent.resolve()
print(ReadmeStepsManage.repo_base_dir)
return ReadmeStepsManage.repo_base_dir

@staticmethod
Expand Down

0 comments on commit 449d679

Please sign in to comment.