Skip to content

Commit ab8b290

Browse files
2 parents bdb3c15 + 370b32f commit ab8b290

18 files changed

Lines changed: 2314 additions & 1401 deletions

.github/workflows/docker-build.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Build Docker and Optional Push - Content Generation Solution Accelerator
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
- demo
9+
paths:
10+
- 'content-gen/src/backend/**'
11+
- 'content-gen/src/frontend/**'
12+
- 'content-gen/src/frontend-server/**'
13+
- '.github/workflows/docker-build.yml'
14+
pull_request:
15+
types:
16+
- opened
17+
- ready_for_review
18+
- reopened
19+
- synchronize
20+
branches:
21+
- main
22+
- dev
23+
- demo
24+
paths:
25+
- 'content-gen/src/backend/**'
26+
- 'content-gen/src/frontend/**'
27+
- 'content-gen/src/frontend-server/**'
28+
- '.github/workflows/docker-build.yml'
29+
workflow_dispatch:
30+
31+
permissions:
32+
contents: read
33+
actions: read
34+
jobs:
35+
build-and-push:
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
- name: Log in to Azure Container Registry
46+
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo')) || (github.event_name == 'workflow_dispatch' && (github.ref_name == 'dependabotchanges'||github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo')) }}
47+
uses: azure/docker-login@v2
48+
with:
49+
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
50+
username: ${{ secrets.ACR_USERNAME }}
51+
password: ${{ secrets.ACR_PASSWORD }}
52+
53+
- name: Get current date
54+
id: date
55+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
56+
57+
- name: Output ACR Login Server
58+
run: |
59+
echo "ACR Login Server: ${{ secrets.ACR_LOGIN_SERVER }}"
60+
61+
- name: Determine Tag Name Based on Branch
62+
id: determine_tag
63+
run: |
64+
if [[ "${{ github.ref_name }}" == "main" ]]; then
65+
echo "tagname=latest" >> $GITHUB_OUTPUT
66+
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
67+
echo "tagname=dev" >> $GITHUB_OUTPUT
68+
elif [[ "${{ github.ref_name }}" == "demo" ]]; then
69+
echo "tagname=demo" >> $GITHUB_OUTPUT
70+
elif [[ "${{ github.ref_name }}" == "dependabotchanges" ]]; then
71+
echo "tagname=dependabotchanges" >> $GITHUB_OUTPUT
72+
else
73+
echo "tagname=default" >> $GITHUB_OUTPUT
74+
75+
fi
76+
- name: Build and Push Docker Image for Frontend Server
77+
uses: docker/build-push-action@v6
78+
with:
79+
context: ./content-gen/src
80+
file: ./content-gen/src/WebApp.Dockerfile
81+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'dependabotchanges' }}
82+
tags: |
83+
${{ secrets.ACR_LOGIN_SERVER || 'acrlogin.azurecr.io' }}/content-gen-app:${{ steps.determine_tag.outputs.tagname }}
84+
${{ secrets.ACR_LOGIN_SERVER || 'acrlogin.azurecr.io' }}/content-gen-app:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }}
85+
86+
- name: Build and Push Docker Image for Backend Server
87+
uses: docker/build-push-action@v6
88+
with:
89+
context: ./content-gen/src/backend
90+
file: ./content-gen/src/backend/ApiApp.Dockerfile
91+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'dependabotchanges' }}
92+
tags: |
93+
${{ secrets.ACR_LOGIN_SERVER || 'acrlogin.azurecr.io' }}/content-gen-api:${{ steps.determine_tag.outputs.tagname }}
94+
${{ secrets.ACR_LOGIN_SERVER || 'acrlogin.azurecr.io' }}/content-gen-api:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }}

content-gen/src/backend/app.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ def get_authenticated_user():
4949
Get the authenticated user from EasyAuth headers.
5050
5151
In production (with App Service Auth), the X-Ms-Client-Principal-Id header
52-
contains the user's ID. In development mode, returns empty/None values.
52+
contains the user's ID. In development mode, returns "anonymous".
5353
"""
5454
user_principal_id = request.headers.get("X-Ms-Client-Principal-Id", "")
5555
user_name = request.headers.get("X-Ms-Client-Principal-Name", "")
5656
auth_provider = request.headers.get("X-Ms-Client-Principal-Idp", "")
5757

5858
return {
59-
"user_principal_id": user_principal_id or "",
59+
"user_principal_id": user_principal_id or "anonymous",
6060
"user_name": user_name or "",
6161
"auth_provider": auth_provider or "",
6262
"is_authenticated": bool(user_principal_id)
@@ -216,7 +216,33 @@ async def parse_brief():
216216
logger.warning(f"Failed to save brief message to CosmosDB: {e}")
217217

218218
orchestrator = get_orchestrator()
219-
parsed_brief, clarifying_questions = await orchestrator.parse_brief(brief_text)
219+
parsed_brief, clarifying_questions, rai_blocked = await orchestrator.parse_brief(brief_text)
220+
221+
# Check if request was blocked due to harmful content
222+
if rai_blocked:
223+
# Save the refusal as assistant response
224+
try:
225+
cosmos_service = await get_cosmos_service()
226+
await cosmos_service.add_message_to_conversation(
227+
conversation_id=conversation_id,
228+
user_id=user_id,
229+
message={
230+
"role": "assistant",
231+
"content": clarifying_questions, # This is the refusal message
232+
"agent": "ContentSafety",
233+
"timestamp": datetime.now(timezone.utc).isoformat()
234+
}
235+
)
236+
except Exception as e:
237+
logger.warning(f"Failed to save RAI response to CosmosDB: {e}")
238+
239+
return jsonify({
240+
"rai_blocked": True,
241+
"requires_clarification": False,
242+
"requires_confirmation": False,
243+
"conversation_id": conversation_id,
244+
"message": clarifying_questions
245+
})
220246

221247
# Check if we need clarifying questions
222248
if clarifying_questions:
@@ -1051,14 +1077,13 @@ async def list_conversations():
10511077
List conversations for a user.
10521078
10531079
Uses authenticated user from EasyAuth headers. In development mode
1054-
(when not authenticated), returns conversations where user_id is empty/null.
1080+
(when not authenticated), uses "anonymous" as user_id.
10551081
10561082
Query params:
10571083
limit: Max number of results (default 20)
10581084
"""
1059-
# Get authenticated user from headers
10601085
auth_user = get_authenticated_user()
1061-
user_id = auth_user["user_principal_id"] # Empty string if not authenticated
1086+
user_id = auth_user["user_principal_id"]
10621087

10631088
limit = int(request.args.get("limit", 20))
10641089

0 commit comments

Comments
 (0)