From 1d469b3263270262be73f4c66371e669740992d6 Mon Sep 17 00:00:00 2001 From: Corina <14900841+corinagum@users.noreply.github.com> Date: Thu, 13 Jun 2024 10:07:47 -0700 Subject: [PATCH] [JS] fix: Update citations sample (#1732) ## Linked issues #minor Co-authored-by: Corina Gum <> --- .../h.datasource-azureOpenAI/README.md | 2 + .../h.datasource-azureOpenAI/src/app.ts | 40 +++++++++++-------- .../teamsapp.local.yml | 1 + 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/js/samples/04.ai-apps/h.datasource-azureOpenAI/README.md b/js/samples/04.ai-apps/h.datasource-azureOpenAI/README.md index 30b740285..4539391de 100644 --- a/js/samples/04.ai-apps/h.datasource-azureOpenAI/README.md +++ b/js/samples/04.ai-apps/h.datasource-azureOpenAI/README.md @@ -67,6 +67,8 @@ This sample shows how to integrate your search index as a data source into promp 1. Fill the `AZURE_OPENAI_ENDPOINT`, `AZURE_SEARCH_ENDPOINT`, and `AZURE_SEARCH_INDEX` variables appropriately. +1. Verify you are logged into azure cli. This is required because this sample uses managed identity. You can download and install Azure CLI from [Azure CLI docs](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli). For more information on setting up environment variables, see the [Azure SDK documentation](https://github.com/Azure/azure-sdk-for-go/wiki/Set-up-Your-Environment-for-Authentication). + 1. Follow the [use your data quickstart instructions](https://learn.microsoft.com/en-us/azure/ai-services/openai/use-your-data-quickstart?tabs=command-line%2Cpython-new&pivots=programming-language-studio#add-your-data-using-azure-openai-studio) to add your data using Azure OpenAI Studio. Select `Upload files` as the data source. You can upload the `nba.pdf` file. Take note of the index name. ## Testing the sample diff --git a/js/samples/04.ai-apps/h.datasource-azureOpenAI/src/app.ts b/js/samples/04.ai-apps/h.datasource-azureOpenAI/src/app.ts index a38b6bea0..32d640144 100644 --- a/js/samples/04.ai-apps/h.datasource-azureOpenAI/src/app.ts +++ b/js/samples/04.ai-apps/h.datasource-azureOpenAI/src/app.ts @@ -41,23 +41,27 @@ const planner = new ActionPlanner({ prompt.config.completion.model = 'gpt-4o'; if (process.env.AZURE_SEARCH_ENDPOINT) { - (prompt.config.completion as any).data_sources = [{ - type: 'azure_search', - parameters: { - endpoint: process.env.AZURE_SEARCH_ENDPOINT, - index_name: process.env.AZURE_SEARCH_INDEX, - semantic_configuration: 'default', - query_type: 'simple', - fields_mapping: { }, - in_scope: true, - strictness: 3, - top_n_documents: 5, - role_information: fs.readFileSync(path.join(__dirname, '../src/prompts/chat/skprompt.txt')).toString('utf-8'), - authentication: { - type: 'system_assigned_managed_identity' + (prompt.config.completion as any).data_sources = [ + { + type: 'azure_search', + parameters: { + endpoint: process.env.AZURE_SEARCH_ENDPOINT, + index_name: process.env.AZURE_SEARCH_INDEX, + semantic_configuration: 'default', + query_type: 'simple', + fields_mapping: {}, + in_scope: true, + strictness: 3, + top_n_documents: 5, + role_information: fs + .readFileSync(path.join(__dirname, '../src/prompts/chat/skprompt.txt')) + .toString('utf-8'), + authentication: { + type: 'system_assigned_managed_identity' + } } } - }]; + ]; } return prompt; @@ -83,12 +87,14 @@ export const app = new Application({ }); app.conversationUpdate('membersAdded', async (context) => { - await context.sendActivity('Welcome! I\'m a conversational bot that can tell you about your data. You can also type `/clear` to clear the conversation history.'); + await context.sendActivity( + "Welcome! I'm a conversational bot that can tell you about your data. You can also type `/clear` to clear the conversation history." + ); }); app.message('/clear', async (context, state) => { state.deleteConversationState(); - await context.sendActivity('New chat session started: Previous messages won\'t be used as context for new queries.'); + await context.sendActivity("New chat session started: Previous messages won't be used as context for new queries."); }); app.error(async (context: TurnContext, err: any) => { diff --git a/js/samples/04.ai-apps/h.datasource-azureOpenAI/teamsapp.local.yml b/js/samples/04.ai-apps/h.datasource-azureOpenAI/teamsapp.local.yml index 58a736acb..3db1954e0 100644 --- a/js/samples/04.ai-apps/h.datasource-azureOpenAI/teamsapp.local.yml +++ b/js/samples/04.ai-apps/h.datasource-azureOpenAI/teamsapp.local.yml @@ -57,3 +57,4 @@ deploy: AZURE_OPENAI_ENDPOINT: ${{AZURE_OPENAI_ENDPOINT}} AZURE_SEARCH_ENDPOINT: ${{AZURE_SEARCH_ENDPOINT}} AZURE_SEARCH_INDEX: ${{AZURE_SEARCH_INDEX}} + AZURE_TENANT_ID: ${{TEAMS_APP_TENANT_ID}}