Skip to content

Commit cba7632

Browse files
Pavan-MicrosoftRoopan-MicrosoftAjitPadhi-Microsoftross-p-smithgpickett
authored
fix: Teams citation issue and add user to postgresdb (#1921)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Roopan-Microsoft <[email protected]> Co-authored-by: Ajit Padhi <[email protected]> Co-authored-by: Roopan P M <[email protected]> Co-authored-by: Ross Smith <[email protected]> Co-authored-by: gpickett <[email protected]> Co-authored-by: Francia Riesco <[email protected]> Co-authored-by: Francia Riesco <[email protected]> Co-authored-by: Prajwal D C <[email protected]> Co-authored-by: Harmanpreet-Microsoft <[email protected]> Co-authored-by: UtkarshMishra-Microsoft <[email protected]> Co-authored-by: Priyanka-Microsoft <[email protected]> Co-authored-by: Prasanjeet-Microsoft <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kiran-Siluveru-Microsoft <[email protected]> Co-authored-by: Prashant-Microsoft <[email protected]> Co-authored-by: Rohini-Microsoft <[email protected]> Co-authored-by: Avijit-Microsoft <[email protected]> Co-authored-by: RaviKiran-Microsoft <[email protected]> Co-authored-by: Somesh Joshi <[email protected]> Co-authored-by: Himanshi Agrawal <[email protected]> Co-authored-by: pradeepjha-microsoft <[email protected]> Co-authored-by: Harmanpreet Kaur <[email protected]> Co-authored-by: Bangarraju-Microsoft <[email protected]> Co-authored-by: Harsh-Microsoft <[email protected]> Co-authored-by: Kanchan-Microsoft <[email protected]> Co-authored-by: Cristopher Coronado <[email protected]> Co-authored-by: Cristopher Coronado Moreira <[email protected]> Co-authored-by: Vamshi-Microsoft <[email protected]> Co-authored-by: Thanusree-Microsoft <[email protected]> Co-authored-by: Niraj Chaudhari (Persistent Systems Inc) <[email protected]> Co-authored-by: Rohini-Microsoft <[email protected]>
1 parent c069f0c commit cba7632

19 files changed

+164
-80
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
2626
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
2727
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
28+
AZURE_PRINCIPAL_ID: ${{ secrets.AZURE_PRINCIPAL_ID }}
29+
AZURE_PRINCIPAL_NAME: ${{ secrets.AZURE_PRINCIPAL_NAME }}
30+
AZURE_PRINCIPAL_TYPE: 'ServicePrincipal'
2831

2932
outputs:
3033
imageTag: ${{ steps.set-image-tag.outputs.imageTag }}
@@ -203,6 +206,9 @@ jobs:
203206
DISABLE_AUTHENTICATION=true
204207
NO_AUTH=true
205208
SKIP_AUTH=true
209+
AZURE_PRINCIPAL_ID
210+
AZURE_PRINCIPAL_NAME
211+
AZURE_PRINCIPAL_TYPE
206212
207213
- name: Extract URLs from deployment
208214
id: extract-urls
@@ -299,8 +305,6 @@ jobs:
299305
300306
echo "=== PostgreSQL Configuration Summary ==="
301307
echo "Host Endpoint: $PG_HOST_DESTINATION"
302-
echo "Username: admintest (hardcoded)"
303-
echo "Password: Initial_0524 (hardcoded)"
304308
echo "Database: postgres (hardcoded)"
305309
echo "Port: 5432 (hardcoded)"
306310
@@ -311,19 +315,28 @@ jobs:
311315

312316
- name: Install Python dependencies
313317
run: |
314-
pip install psycopg2-binary python-dotenv
315-
318+
pip install psycopg2-binary python-dotenv azure-identity
316319
317320
- name: Populate PostgreSQL Database
318321
run: |
319322
python - <<EOF
320323
import os
321324
import psycopg2
325+
from azure.identity import ClientSecretCredential
326+
327+
tenant_id = os.environ["AZURE_TENANT_ID"]
328+
client_id = os.environ["AZURE_CLIENT_ID"]
329+
client_secret = os.environ["AZURE_CLIENT_SECRET"]
330+
pg_host = os.environ.get("PG_HOST_DESTINATION", "localhost")
331+
332+
# Acquire Azure AD access token for PostgreSQL
333+
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
334+
token = credential.get_token("https://ossrdbms-aad.database.windows.net/.default").token
322335
323336
db_params = {
324-
"user": "admintest",
325-
"password": "Initial_0524",
326-
"host": os.environ.get("PG_HOST_DESTINATION", "localhost"),
337+
"user": client_id, # Use service principal clientId
338+
"password": token, # Use AAD token instead of password
339+
"host": pg_host,
327340
"port": "5432",
328341
"dbname": "postgres",
329342
"sslmode": "require"
@@ -343,8 +356,10 @@ jobs:
343356
except Exception as e:
344357
print(f"❌ Error during import: {e}")
345358
EOF
346-
347-
359+
env:
360+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
361+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
362+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
348363

349364
- name: Final Status Check
350365
id: final-status

docs/LOCAL_DEPLOYMENT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ Execute the above [shell command](#L81) to run the function locally. You may nee
280280
|AZURE_SEARCH_TITLE_COLUMN||Field from your Azure AI Search index that gives a relevant title or header for your data content to display in the UI.|
281281
|AZURE_SEARCH_TOP_K|5|The number of documents to retrieve from Azure AI Search.|
282282
|AZURE_SEARCH_URL_COLUMN||Field from your Azure AI Search index that contains a URL for the document, e.g. an Azure Blob Storage URI. This value is not currently used.|
283-
|AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION ||Whether to use [Integrated Vectorization](https://learn.microsoft.com/en-us/azure/search/vector-search-integrated-vectorization)|
283+
|AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION ||Whether to use [Integrated Vectorization](https://learn.microsoft.com/en-us/azure/search/vector-search-integrated-vectorization). If the database type is PostgreSQL, set this to false.|
284284
|AZURE_SEARCH_USE_SEMANTIC_SEARCH|False|Whether or not to use semantic search|
285285
|AZURE_SPEECH_RECOGNIZER_LANGUAGES | en-US,fr-FR,de-DE,it-IT | Comma-separated list of languages to recognize from speech input|
286286
|AZURE_SPEECH_REGION_ENDPOINT | | The regional endpoint of the Azure Speech service|
@@ -299,7 +299,7 @@ Execute the above [shell command](#L81) to run the function locally. You may nee
299299
|OPEN_AI_FUNCTIONS_SYSTEM_PROMPT | | System prompt for OpenAI functions orchestration|
300300
|ORCHESTRATION_STRATEGY | openai_function | Orchestration strategy. Use Azure OpenAI Functions (openai_function), Semantic Kernel (semantic_kernel), LangChain (langchain) or Prompt Flow (prompt_flow) for messages orchestration. If you are using a new model version 0613 select any strategy, if you are using a 0314 model version select "langchain". Note that both `openai_function` and `semantic_kernel` use OpenAI function calling. Prompt Flow option is still in development and does not support RBAC or integrated vectorization as of yet.|
301301
|SEMANTIC_KERNEL_SYSTEM_PROMPT | | System prompt used by the Semantic Kernel orchestration|
302-
|USE_ADVANCED_IMAGE_PROCESSING | false | Whether to enable the use of a vision LLM and Computer Vision for embedding images|
302+
|USE_ADVANCED_IMAGE_PROCESSING | false | Whether to enable the use of a vision LLM and Computer Vision for embedding images. If the database type is PostgreSQL, set this to false.|
303303
|USE_KEY_VAULT | true | Whether to use Azure Key Vault for storing secrets|
304304

305305
## Bicep

docs/advanced_image_processing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ azd env set ADVANCED_IMAGE_PROCESSING_MAX_IMAGES 2
4646
```
4747

4848
Advanced image processing is only used in the `custom` conversation flow and not the `byod` flow, as Azure OpenAI On Your Data only supports Ada embeddings. It is currently not possible to use advanced image processing when integrated vectorization is enabled.
49+
50+
Advanced image processing is not supported when deploying with PostgreSQL as the database type.

docs/integrated_vectorization.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ If you have a deployment with Integrated Vectorization enabled, and you want to
4949
![Delete Search Index](images/delete-search-datasource.png)
5050
1. Run the command `azd env set AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION false`
5151
1. Run `azd up`
52+
53+
**NOTE**: Integrated vectorization is not supported when deploying with PostgreSQL as the database type.

docs/teams_extension.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ This extension enables users to experience Chat with your data within Teams, wit
3232

3333
![ENV](images/teams-1.png)
3434

35-
4. Locate the environment variable _AZURE_FUNCTION_URL_.
36-
5. Replace the `<FUNCTION_APP_NAME>` and `<FUNCTION_KEY>` with your actual Function App name and function key
35+
4. Locate the environment variables _AZURE_FUNCTION_URL_ and _AZURE_APP_API_BASE_URL_.
36+
5. Replace the `<FUNCTION_APP_NAME>` and `<FUNCTION_KEY>` with your actual Function App name and function key, and replace `<APP-NAME>` with your actual App Service name
3737
```env
3838
AZURE_FUNCTION_URL=https://<FUNCTION_APP_NAME>.azurewebsites.net/api/GetConversationResponse?code=<FUNCTION_KEY>
39-
39+
AZURE_APP_API_BASE_URL=https://<APP-NAME>.azurewebsites.net/
4040
```
4141
![Env](images/teams-deploy-env.png)
4242
6. Save the file.

extensions/teams/cards/cardBuilder.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Attachment, CardFactory } from "botbuilder";
22
import { Citation, CardType } from "../model";
3+
import config from "../config";
34

45
export function actionBuilder(citation: Citation, docId: number): any {
56

6-
const urlParts = citation.url.split("]");
7-
let url = urlParts[urlParts.length - 1].replaceAll("(", "").replaceAll(")", "");
87
let title = citation.title.replaceAll("/documents/", "");
8+
const filename = title;
9+
let fileApiUrl = `${config.getFileEndpoint}/${filename}`;
910
let content = citation.content.replaceAll(citation.title, "").replaceAll("url", "");
1011
content = content.replaceAll(/(<([^>]+)>)/ig, "\n").replaceAll("<>", "");
1112
let citationCardAction = {
@@ -37,7 +38,7 @@ export function actionBuilder(citation: Citation, docId: number): any {
3738
{
3839
type: CardType.OpenUrl,
3940
title: "Go to the source",
40-
url: decodeURI(url),
41+
url: decodeURI(fileApiUrl),
4142
}
4243
]
4344
}

extensions/teams/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ const config = {
22
botId: process.env.BOT_ID,
33
botPassword: process.env.BOT_PASSWORD,
44
azureFunctionUrl: process.env.AZURE_FUNCTION_URL,
5+
azureAppApiBaseUrl: process.env.AZURE_APP_API_BASE_URL,
56
tenantId: process.env.TEAMS_APP_TENANT_ID,
7+
getFileEndpoint: process.env.AZURE_APP_API_BASE_URL ?
8+
`${process.env.AZURE_APP_API_BASE_URL}api/files` :
9+
null,
610
};
711

812
export default config;

extensions/teams/env/.env.dev

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ BOT_ID=
1414
TEAMS_APP_ID=
1515
BOT_AZURE_APP_SERVICE_RESOURCE_ID=
1616
BOT_DOMAIN=
17-
AZURE_FUNCTION_URL=https://backend-<RESOURCE_TOKEN>.azurewebsites.net/api/GetConversationResponse?code=<FUNCTION_APP_CLIENT_KEY>&clientId=clientKey
17+
AZURE_FUNCTION_URL=https://<FUNCTION_APP_NAME>.azurewebsites.net/api/GetConversationResponse?code=<FUNCTION_KEY>
18+
AZURE_APP_API_BASE_URL=https://<APP-NAME>.azurewebsites.net/

extensions/teams/env/.env.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ BOT_ID=
1414
TEAMS_APP_ID=
1515
BOT_AZURE_APP_SERVICE_RESOURCE_ID=
1616
BOT_DOMAIN=
17-
AZURE_FUNCTION_URL=https://backend-<RESOURCE_TOKEN>.azurewebsites.net/api/GetConversationResponse?code=<FUNCTION_APP_CLIENT_KEY>&clientId=clientKey
17+
AZURE_FUNCTION_URL=https://<FUNCTION_APP_NAME>.azurewebsites.net/api/GetConversationResponse?code=<FUNCTION_KEY>
18+
AZURE_APP_API_BASE_URL=https://<APP-NAME>.azurewebsites.net/
1819
TEAMS_APP_TENANT_ID=
1920
TEAMS_APP_PUBLISHED_APP_ID=

extensions/teams/env/.env.testtool

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ TEAMSFX_ENV=testtool
66
# Environment variables used by test tool
77
TEAMSAPPTESTER_PORT=56150
88
TEAMSFX_NOTIFICATION_STORE_FILENAME=.notification.testtoolstore.json
9-
AZURE_FUNCTION_URL=https://backend-<RESOURCE_TOKEN>.azurewebsites.net/api/GetConversationResponse?code=<FUNCTION_APP_CLIENT_KEY>&clientId=clientKey
9+
AZURE_FUNCTION_URL=https://<FUNCTION_APP_NAME>.azurewebsites.net/api/GetConversationResponse?code=<FUNCTION_KEY>
10+
AZURE_APP_API_BASE_URL=https://<APP-NAME>.azurewebsites.net/

0 commit comments

Comments
 (0)