Skip to content

Commit

Permalink
Add flow endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ljtill committed Jan 28, 2025
1 parent 689ee65 commit 1e09551
Show file tree
Hide file tree
Showing 23 changed files with 394 additions and 385 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"image": "mcr.microsoft.com/devcontainers/base:noble",
"features": {
"ghcr.io/ljtill/features/task:latest": {
"version": "3.40.1"
"version": "3.41.0"
}
},
"customizations": {
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ jobs:
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build Flows
id: flow-build
run: task flow-build

- name: Deploy Flows
id: flow-deploy
run: task flow-deploy
Expand Down
58 changes: 12 additions & 46 deletions .task/app.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.40.1"
version: "3.41.0"

tasks:
app-build:
Expand All @@ -8,32 +8,10 @@ tasks:
- task: deps-setup
aliases:
- ab
cmds:
- task: app-build-api
- task: app-build-ui

app-build-api:
desc: Build API service.
silent: true
deps:
- task: deps-setup
aliases:
- aba
dir: app/api
cmds:
- echo -e "\033[0;32mBuilding API...\033[0m"
- python3 -m venv .venv
- .venv/bin/pip3 install -r requirements.txt

app-build-ui:
desc: Build UI service.
silent: true
deps:
- task: deps-setup
aliases:
- abu
dir: app/ui
cmds:
- echo -e "\033[0;32mBuilding UI...\033[0m"
- npm install --no-fund --no-audit
- npm run build
Expand All @@ -45,32 +23,10 @@ tasks:
- task: deps-setup
aliases:
- ac
cmds:
- task: app-clean-api
- task: app-clean-ui

app-clean-api:
desc: Remove API build artifacts.
silent: true
deps:
- task: deps-setup
aliases:
- aca
dir: app/api
cmds:
- echo -e "\033[0;32mRemoving API artifacts...\033[0m"
- rm -rf .venv
- rm -rf www

app-clean-ui:
desc: Remove UI build artifacts.
silent: true
deps:
- task: deps-setup
aliases:
- acu
dir: app/ui
cmds:
- echo -e "\033[0;32mRemoving UI artifacts...\033[0m"
- rm -rf node_modules

Expand Down Expand Up @@ -107,14 +63,24 @@ tasks:
--src-path "$ZIP_PATH" \
--type zip
app-logs:
desc: Show application logs.
silent: true
aliases:
- al
dir: infra
cmds:
- echo -e "\033[0;32mShowing logs...\033[0m"
- az webapp log tail -g $(terraform output -raw resource_group) -n $(terraform output -raw webapp_name)

api-run:
desc: Launch local API instance.
silent: true
dir: app/api
deps:
- task: deps-setup
aliases:
- ar
dir: app/api
cmds:
- echo -e "\033[0;32mLaunching API...\033[0m"
- .venv/bin/python3 -m uvicorn main:app --reload
151 changes: 94 additions & 57 deletions .task/flow.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: "3.40.1"
version: "3.41.0"

tasks:
flow-deploy:
desc: Deploy flows to AI Foundry.
flow-create-review:
desc: Upload and create flows in AI Foundry.
silent: true
deps:
- task: deps-setup
Expand All @@ -12,17 +12,18 @@ tasks:
cmds:
- cmd: |
NAME_ARGUMENT={{if .FLOW_NAME}}"--set display_name="{{.FLOW_NAME}}{{else}}{{end}}
pushd ../infra > /dev/null
eval "$(terraform output -json | jq -r 'to_entries | .[] | "export ADR_" + (.key | ascii_upcase) + "=\"" + .value.value + "\"" ')"
popd > /dev/null
pushd ../infra
RESOURCE_GROUP=$(terraform output -raw resource_group)
APP_NAME=$(terraform output -raw webapp_name)
popd
pfazure flow create \
--flow ai_doc_review \
--workspace-name "$ADR_AI_HUB_PROJECT_NAME" \
--resource-group "$ADR_RESOURCE_GROUP" \
--workspace-name "$AI_HUB_PROJECT_NAME" \
--resource-group "$RESOURCE_GROUP" \
$NAME_ARGUMENT
flow-deploy-agent:
flow-create-agent:
desc: Deploy agent flows to AI Foundry.
silent: true
deps:
Expand All @@ -33,17 +34,18 @@ tasks:
cmds:
- cmd: |
NAME_ARGUMENT={{if .FLOW_NAME}}"--set display_name="{{.FLOW_NAME}}{{else}}{{end}}
pushd ../infra > /dev/null
eval "$(terraform output -json | jq -r 'to_entries | .[] | "export ADR_" + (.key | ascii_upcase) + "=\"" + .value.value + "\"" ')"
popd > /dev/null
pushd ../infra
RESOURCE_GROUP=$(terraform output -raw resource_group)
AI_HUB_PROJECT_NAME=$(terraform output -raw ai_hub_project_name)
popd
pfazure flow create \
--flow ai_doc_review/agent_template \
--workspace-name "$ADR_AI_HUB_PROJECT_NAME" \
--resource-group "$ADR_RESOURCE_GROUP" \
--workspace-name "$AI_HUB_PROJECT_NAME" \
--resource-group "$RESOURCE_GROUP" \
$NAME_ARGUMENT
flow-deploy-eval:
flow-create-eval:
desc: Deploy evaluation flows to AI Foundry.
silent: true
deps:
Expand All @@ -54,62 +56,97 @@ tasks:
cmds:
- cmd: |
NAME_ARGUMENT={{if .FLOW_NAME}}"--set display_name="{{.FLOW_NAME}}{{else}}{{end}}
pushd ../infra > /dev/null
eval "$(terraform output -json | jq -r 'to_entries | .[] | "export ADR_" + (.key | ascii_upcase) + "=\"" + .value.value + "\"" ')"
popd > /dev/null
pushd ../infra
RESOURCE_GROUP=$(terraform output -raw resource_group)
AI_HUB_PROJECT_NAME=$(terraform output -raw ai_hub_project_name)
popd
pfazure flow create \
--flow ai_doc_review_eval \
--workspace-name "$ADR_AI_HUB_PROJECT_NAME" \
--resource-group "$ADR_RESOURCE_GROUP" \
--workspace-name "$AI_HUB_PROJECT_NAME" \
--resource-group "$RESOURCE_GROUP" \
--set type=evaluation
$NAME_ARGUMENT
flow-deploy-endpoint:
desc: Deploy to ML endpoints.
flow-build:
desc: Build flow artifacts.
silent: true
deps:
- task: deps-setup
aliases:
- fb
dir: flows
cmds:
- echo -e "\033[0;32mBuilding flow artifacts...\033[0m"
- python3 -m venv .venv
- .venv/bin/pip3 install -r requirements.txt
- .venv/bin/pip3 install -r ./ai_doc_review/requirements.txt
- .venv/bin/pip3 install -r ./ai_doc_review_eval/requirements.txt
- .venv/bin/pip3 install keyrings.alt

flow-clean:
desc: Remove flow artifacts.
silent: true
deps:
- task: deps-setup
aliases:
- fb
dir: flows
cmds:
- echo -e "\033[0;32mRemoving flow artifacts...\033[0m"
- rm -rf .venv
- rm -rf ai_doc_review/common

flow-deploy:
desc: Deploy flow endpoint to App Service.
silent: true
deps:
- task: deps-setup
aliases:
- fde
dir: flows/ai_doc_review
dir: flows
cmds:
- cmd: |
pushd ../../infra > /dev/null
eval "$(terraform output -json | jq -r 'to_entries | .[] | "export ADR_" + (.key | ascii_upcase) + "=\"" + .value.value + "\"" ')"
popd > /dev/null
echo -e "\033[0;32mUploading flow...\033[0m"
TEMP_DIR=$(mktemp -d)
trap "rm -rf $TEMP_DIR" EXIT
cp -r ../../common/ common/
cp ./deployment.yaml ./sub_deployment.yaml
export MODEL_VERSION=$(az ml model create --workspace-name "$ADR_AI_HUB_PROJECT_NAME" --resource-group "$ADR_RESOURCE_GROUP" --file model.yaml --query version -o tsv)
cp -a ai_doc_review "$TEMP_DIR/"
rm -rf "$TEMP_DIR/ai_doc_review/common"
cp -a ../common "$TEMP_DIR/ai_doc_review/common"
pushd $TEMP_DIR/ai_doc_review
zip -q -r --symlinks "$TEMP_DIR/flow.zip" *
popd
sed -i 's|VAR_MODEL_VERSION|'"$MODEL_VERSION"'|g' sub_deployment.yaml
sed -i 's|VAR_SUBSCRIPTION_ID|'"$ADR_SUBSCRIPTION_ID"'|g' sub_deployment.yaml
sed -i 's|VAR_RESOURCE_GROUP|'"$ADR_RESOURCE_GROUP"'|g' sub_deployment.yaml
sed -i 's|VAR_AI_HUB_PROJECT_NAME|'"$ADR_AI_HUB_PROJECT_NAME"'|g' sub_deployment.yaml
sed -i 's|VAR_ENDPOINT_NAME|'"$ADR_AML_ENDPOINT_NAME"'|g' sub_deployment.yaml
sed -i 's|VAR_AZURE_OPENAI_ENDPOINT|'"$ADR_AZURE_OPENAI_ENDPOINT"'|g' sub_deployment.yaml
sed -i 's|VAR_IDENTITY_CLIENT_ID|'"$ADR_IDENTITY_CLIENT_ID"'|g' sub_deployment.yaml
sed -i 's|VAR_DOCUMENT_INTELLIGENCE_ENDPOINT|'"$ADR_DOCUMENT_INTELLIGENCE_ENDPOINT"'|g' sub_deployment.yaml
sed -i 's|VAR_STORAGE_URL_PREFIX|'"$ADR_STORAGE_URL_PREFIX"'|g' sub_deployment.yaml
pushd ../infra
RESOURCE_GROUP=$(terraform output -raw resource_group)
FLOW_NAME=$(terraform output -raw flowapp_name)
popd
az ml online-deployment show \
--name ai-doc-review-deployment \
--endpoint-name "$ADR_AML_ENDPOINT_NAME" \
--workspace-name "$ADR_AI_HUB_PROJECT_NAME" \
--resource-group "$ADR_RESOURCE_GROUP" \
&& az ml online-deployment update \
--file sub_deployment.yaml \
--workspace-name "$ADR_AI_HUB_PROJECT_NAME" \
--resource-group "$ADR_RESOURCE_GROUP" \
|| az ml online-deployment create \
--file sub_deployment.yaml \
--workspace-name "$ADR_AI_HUB_PROJECT_NAME" \
--resource-group "$ADR_RESOURCE_GROUP" \
--all-traffic
ZIP_PATH="$TEMP_DIR/flow.zip"
az webapp deploy \
-g $RESOURCE_GROUP \
-n $FLOW_NAME \
--src-path "$ZIP_PATH" \
--type zip
flow-run:
desc: Launch local flow instance.
silent: true
deps:
- task: deps-setup
aliases:
- fr
dir: flows/ai_doc_review
cmds:
- echo -e "\033[0;32mLaunching flow...\033[0m"
- pf flow serve --source ./ --port 8080 --host localhost

az ml online-endpoint update \
--name $ADR_AML_ENDPOINT_NAME \
--traffic "ai-doc-review-deployment=100" \
--workspace-name "$ADR_AI_HUB_PROJECT_NAME" \
--resource-group "$ADR_RESOURCE_GROUP"
flow-logs:
desc: Show logs for ML endpoint.
silent: true
aliases:
- fle
dir: infra
cmds:
- az webapp log tail --name $(terraform output -raw flowapp_name) --resource-group $(terraform output -raw resource_group)
39 changes: 8 additions & 31 deletions .task/infra.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.40.1"
version: "3.41.0"

tasks:
infra-init:
Expand Down Expand Up @@ -54,39 +54,16 @@ tasks:
-var-file=environments/local.tfvars
-auto-approve

infra-state-refresh:
desc: Refresh the state of all infrastructure.
infra-clean:
desc: Remove infrastructure artifacts.
silent: true
deps:
- task: deps-setup
aliases:
- isf
- ic
dir: infra
cmds:
- echo -e "\033[0;32mRefreshing state...\033[0m"
- terraform refresh
-var-file=environments/local.tfvars

infra-state-reset:
desc: Reset the state of all infrastructure.
silent: true
deps:
- task: deps-setup
aliases:
- isr
dir: infra
cmds:
- echo -e "\033[0;32mResetting state...\033[0m"
- terraform state rm $(terraform state list) || true && rm -f terraform.tfstate*

infra-state-list:
desc: List all infrastructure state.
silent: true
deps:
- task: deps-setup
aliases:
- isl
dir: infra
cmds:
- echo -e "\033[0;32mListing state...\033[0m"
- terraform state list
- echo -e "\033[0;32mRemoving infrastructure artifacts...\033[0m"
- rm -rf .terraform
- rm -f terraform.tfstate
- rm -f terraform.tfstate.backup
Loading

0 comments on commit 1e09551

Please sign in to comment.