Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container app updates, fast api updates, fixes, infra updates #157

Merged
merged 23 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 24 additions & 44 deletions .github/workflows/evaluations.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Evaluate Chat Relevance, Fluency, Coherence, and Groundedness
name: Evaluate

on:
workflow_dispatch:
Expand All @@ -7,7 +7,6 @@ on:
# Set this to the mainline branch you are using
branches:
- main
- azd

# Set up permissions for deploying with secretless Azure federated credentials
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication
Expand All @@ -23,17 +22,24 @@ jobs:
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
AZURE_OPENAI_API_VERSION: ${{ secrets.AZURE_OPENAI_API_VERSION }}
AZURE_DEPLOYMENT_NAME: "gpt-4"
AZURE_EMBEDDING_NAME: "text-embedding-ada-002"
COSMOS_ENDPOINT: "${{ secrets.CONTOSO_SEARCH_ENDPOINT }}"
AZURE_SEARCH_ENDPOINT: "${{ secrets.AZURE_SEARCH_ENDPOINT }}"
AZURE_OPENAI_ENDPOINT: ${{ vars.AZURE_OPENAI_ENDPOINT }}
AZURE_OPENAI_API_VERSION: ${{ vars.AZURE_OPENAI_API_VERSION }}
AZURE_OPENAI_4_EVAL_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_4_EVAL_DEPLOYMENT_NAME }}
AZURE_OPENAI_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_DEPLOYMENT_NAME }}
AZURE_OPENAI_35_TURBO_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_35_TURBO_DEPLOYMENT_NAME }}
AZURE_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}
AZURE_SEARCH_ENDPOINT: ${{ vars.AZURE_SEARCH_ENDPOINT }}
AZURE_OPENAI_NAME: ${{ vars.AZURE_OPENAI_NAME }}
BING_SEARCH_ENDPOINT: ${{ vars.BING_SEARCH_ENDPOINT }}
BING_SEARCH_KEY: ${{ secrets.BING_SEARCH_KEY }}

steps:
- name: checkout repo content
uses: actions/checkout@v4 # checkout the repository content

- name: Install azd
uses: Azure/[email protected]

- name: setup python
uses: actions/setup-python@v5
with:
Expand All @@ -42,64 +48,38 @@ jobs:
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: install promptflow dev bits
run: |
# unstall old promptflow
pip uninstall -y promptflow promptflow-azure promptflow-core promptflow-devkit promptflow-tools promptflow-evals

# install dev packages
pip install promptflow-evals==0.2.0.dev125831637 --extra-index-url https://azuremlsdktestpypi.azureedge.net/promptflow
pip install azure_ai_ml==1.16.0a20240501004 --extra-index-url https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/

pip install azure-cli
pip install bs4
pip install ipykernel
pip install azure-cosmos==4.6.0
pip install azure-search-documents==11.4.0

pf version
pip install -r src/api/requirements.txt

- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}

- name: Set az account
uses: azure/CLI@v2
with:
inlineScript: |
az account set --subscription ${{env.AZURE_SUBSCRIPTION_ID}}

- name: Set Promptflow config
run: |
pf config set trace.destination=azureml://subscriptions/${{ env.AZURE_SUBSCRIPTION_ID }}/resourceGroups/rg-${{ vars.AZURE_ENV_NAME }}/providers/Microsoft.MachineLearningServices/workspaces/${{ vars.ML_WORKSPACE_NAME }}

- name: evaluate chat data using the eval sdk
working-directory: ./evaluations
- name: evaluate
working-directory: ./src/api
run: |
python evaluations_chat.py
python -m evaluators.evaluate

- name: Upload eval results as build artifact
uses: actions/upload-artifact@v4
with:
name: eval_result
path: ./evaluations/eval_result.jsonl
path: ./src/api/evaluators/eval_results.jsonl

- name: GitHub Summary Step
if: ${{ success() }}
working-directory: ./evaluations
working-directory: ./src/api
run: |
studio_url=$(cat studio_url.txt)
echo $studio_url

echo "🔗 [View in Azure Studio Here]($studio_url)" >> $GITHUB_STEP_SUMMARY

echo "" >> $GITHUB_STEP_SUMMARY

echo "📊 Promptflow Evaluation Results" >> $GITHUB_STEP_SUMMARY
cat eval_result.md >> $GITHUB_STEP_SUMMARY

echo "📊 Evaluation Results" >> $GITHUB_STEP_SUMMARY
cat evaluate/eval_results.md >> $GITHUB_STEP_SUMMARY

23 changes: 18 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.venv/
__pycache__/
.promptflow/
.prompty/
.env
config.json
eval/downloaded_artifacts/remote/eval_results.jsonl
Expand All @@ -11,7 +11,20 @@ deployment/push_and_deploy_pf.py
endpoint.json
principal.txt
.azure
evaluations/process_log/
evaluations/flow.flex.yaml
evaluations/eval_result.**
evaluations/studio_url.txt
evaluators/process_log/
evaluators/flow.flex.yaml
evaluators/eval_result.**
evaluators/studio_url.txt
src/contoso_chat/.runs/*
src/api/contoso_chat/.runs/*
src/api/.runs/*
.runs/*
evaluators/.runs/*
evaluators/result_evaluated.jsonl
evaluators/result.jsonl
src/api/evaluators/.runs/*
src/api/evaluators/result_evaluated.jsonl
src/api/evaluators/result.jsonl
src/api/evaluators/eval_results.jsonl
src/api/evaluators/eval_results.md
src/api/evaluators/.runs/*
38 changes: 5 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Contoso Chat Retail with Azure AI Studio and Promptflow
name: Contoso Chat Retail with Azure AI Studio and Prompty
description: A retail copilot that answers customer queries with responses grounded in retailer's product and customer data.
languages:
- python
Expand All @@ -15,7 +15,7 @@ page_type: sample
urlFragment: contoso-chat
---

# Contoso Chat Retail with Azure AI Studio and Promptflow
# Contoso Chat Retail with Azure AI Studio and Prompty

This sample creates a customer support chat agent for an online retailer called Contoso Outdoors. The solution uses a _retrieval-augmented generation pattern_ to ground responses in the company's product and customer data. Customers can ask questions about the retailer's product catalog, and also get recommendations based on their prior purchases.

Expand All @@ -32,8 +32,8 @@ The sample uses [Azure AI Search](https://learn.microsoft.com/azure/search/) to

By exploring and deploying this sample, you will learn to:
- Build a retail copilot application using the [_RAG pattern_](https://learn.microsoft.com/azure/ai-studio/concepts/retrieval-augmented-generation).
- Define and engineer prompts using the [_Prompty_ asset](https://microsoft.github.io/promptflow/tutorials/prompty-quickstart.html?highlight=prompty#).
- Design, run & evaluate a copilot using the [_Promptflow_ framework](https://microsoft.github.io/promptflow/tutorials/flex-flow-quickstart.html).
- Define and engineer prompts using the Prompty
- Design, run & evaluate a copilot
- Provision and deploy the solution to Azure using the [_Azure Developer CLI_](https://learn.microsoft.com/azure/developer/azure-developer-cli/).
- Understand and apply Responsible AI practices like [_evaluation and content safety_](https://learn.microsoft.com/en-us/azure/ai-services/responsible-use-of-ai-overview?context=%2Fazure%2Fai-studio%2Fcontext%2Fcontext).

Expand Down Expand Up @@ -103,7 +103,6 @@ This has been the signature sample used to showcase end-to-end development of a
* [Visual Studio Code](https://code.visualstudio.com) - recommended IDE for local development.
* [Azure Developer CLI (azd)](https://aka.ms/install-azd) - to manage Azure deployment.
* [Python 3.10+](https://www.python.org/downloads/) - to run, test & evaluate application.
* [Promptflow 1.10+](https://microsoft.github.io/promptflow/) - to build, evaluate, and deploy application flows.

You will also need:
* [Azure Subscription](https://azure.microsoft.com/free/) - sign up for a free account.
Expand Down Expand Up @@ -222,26 +221,7 @@ The [contoso_chat](./contoso_chat) sample contains an example [chat.prompty](./c
- `question` section to embed user query
- `Instructions` section to reference related product recommendations

This specific prompty takes 3 inputs: a `customer` object, a `documentation` object (that could be chat history) and a `question` string that represents the user query. You can now _load_, _execute_, and _trace_ individual prompty assets for a more granular prompt engineering solution.

* See the [prompty specification](https://microsoft.github.io/promptflow/how-to-guides/develop-a-prompty/index.html#prompty-specification) for more details on the format.
* Read the [prompty examples](https://github.com/microsoft/promptflow/tree/main/examples/prompty) for usage guidance from SDK or CLI.

### Testing the Application Flow

This sample uses a [flex-flow](https://microsoft.github.io/promptflow/how-to-guides/develop-a-flex-flow/index.html) feature that lets you "create LLM apps using a Python class or function as the entry point" - making it easier to test and run them using a code-first experience.
- This sample implements a _Function based flow_
- The entry point is the _get_response_ functionin `chat_request.py`

You can now [test the flow](https://microsoft.github.io/promptflow/how-to-guides/develop-a-flex-flow/function-based-flow.html#flow-test) in different ways:
- Run it directly, like any Python script
- Convert it to a flow, then use `pf flow test --flow ...`
- Start a UI to chat with the flow using `pf flow test --flow ... --ui`

🌟 | Watch this space for more testing guidance.


## Guidance
This specific prompty takes 3 inputs: a `customer` object, a `documentation` object (that could be chat history) and a `question` string that represents the user query. You can now _load_, _execute_, and _trace_ individual prompty assets for a more granular prompt

### Region Availability

Expand Down Expand Up @@ -270,14 +250,6 @@ This template uses [Managed Identity](https://learn.microsoft.com/entra/identity

Additionally, we have added a [GitHub Action tool](https://github.com/microsoft/security-devops-action) that scans the infrastructure-as-code files and generates a report containing any detected issues. To ensure best practices we recommend anyone creating solutions based on our templates ensure that the [Github secret scanning](https://docs.github.com/code-security/secret-scanning/about-secret-scanning) setting is enabled in your repo.


## Resources

* [Azure AI Studio Documentation](https://learn.microsoft.com/azure/ai-studio/)
* [Promptflow/Prompty Documentation](https://microsoft.github.io/promptflow/reference/python-library-reference/promptflow-core/promptflow.core.html?highlight=prompty#promptflow.core.Prompty)
* [Develop Python apps that use Azure AI services](https://learn.microsoft.com/azure/developer/python/azure-ai-for-python-developers)
* Related Sample: [Process Automation: Speech to Text and Summarization with ACA](https://github.com/Azure-Samples/summarization-openai-python-promptflow/blob/main/README.md)

## Troubleshooting

Have questions or issues to report? Please [open a new issue](https://github.com/Azure-Samples/contoso-chat/issues) after first verifying that the same question or issue has not already been reported. In the latter case, please add any additional comments you may have, to the existing issue.
Expand Down
37 changes: 4 additions & 33 deletions azure.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json

name: contoso-chat
name: contoso-chat-openai-prompty
metadata:
template: [email protected]
workflows:
up:
steps:
- azd: provision
- azd: deploy
template: [email protected]
hooks:
postprovision:
posix:
Expand All @@ -20,27 +13,5 @@ hooks:
continueOnError: false
interactive: true
run: infra/hooks/postprovision.ps1


################################################################
# The section below configures the new `ai.endpoint` resource
# used for the Azure AI based chat service (application)
################################################################
services:
chat:
host: ai.endpoint
language: python
config:
workspace: ${AZUREAI_PROJECT_NAME}
environment:
path: ./deployment/environment.yaml
model:
path: ./deployment/chat-model.yaml
deployment:
path: ./deployment/chat-deployment.yaml
overrides:
environment_variables.PRT_CONFIG_OVERRIDE: deployment.subscription_id=${AZURE_SUBSCRIPTION_ID},deployment.resource_group=${AZURE_RESOURCE_GROUP},deployment.workspace_name=${AZUREAI_PROJECT_NAME},deployment.endpoint_name=${AZUREAI_ENDPOINT_NAME},deployment.deployment_name=${AZUREAI_DEPLOYMENT_NAME}
environment_variables.AZURE_OPENAI_ENDPOINT: ${AZURE_OPENAI_ENDPOINT}
environment_variables.AZURE_OPENAI_API_VERSION: ${AZURE_OPENAI_API_VERSION}
environment_variables.COSMOS_ENDPOINT: ${COSMOS_ENDPOINT}
environment_variables.AZURE_SEARCH_ENDPOINT: ${AZURE_SEARCH_ENDPOINT}
infra:
provider: "bicep"
Loading
Loading