From 310bf7c0a3be45293ef52fd393585b9e11f9fdb7 Mon Sep 17 00:00:00 2001 From: davidm00 <43946287+davidm00@users.noreply.github.com> Date: Mon, 23 Oct 2023 13:53:58 -0700 Subject: [PATCH] embedding model name changes (#335) Co-authored-by: David Moses --- .env.sample | 3 +-- README.md | 6 ++---- app.py | 10 +++++----- infra/main.bicep | 3 +-- infrastructure/deployment.json | 19 ++++--------------- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/.env.sample b/.env.sample index 08dd49c188..9058b24c50 100644 --- a/.env.sample +++ b/.env.sample @@ -26,8 +26,7 @@ AZURE_OPENAI_SYSTEM_MESSAGE=You are an AI assistant that helps people find infor AZURE_OPENAI_PREVIEW_API_VERSION=2023-06-01-preview AZURE_OPENAI_STREAM=True AZURE_OPENAI_ENDPOINT= -AZURE_OPENAI_EMBEDDING_ENDPOINT= -AZURE_OPENAI_EMBEDDING_KEY= +AZURE_OPENAI_EMBEDDING_NAME= AZURE_COSMOSDB_ACCOUNT= AZURE_COSMOSDB_DATABASE= AZURE_COSMOSDB_CONVERSATIONS_CONTAINER= diff --git a/README.md b/README.md index d89c91b48f..c7b0f4ed92 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,7 @@ Please see the [section below](#add-an-identity-provider) for important informat - `AZURE_SEARCH_QUERY_TYPE` - `AZURE_SEARCH_PERMITTED_GROUPS_COLUMN` - `AZURE_SEARCH_STRICTNESS` - - `AZURE_OPENAI_EMBEDDING_ENDPOINT` - - `AZURE_OPENAI_EMBEDDING_KEY` + - `AZURE_OPENAI_EMBEDDING_NAME` 3. Start the app with `start.cmd`. This will build the frontend, install backend dependencies, and then start the app. 4. You can see the local running app at http://127.0.0.1:5000. @@ -198,8 +197,7 @@ Note: settings starting with `AZURE_SEARCH` are only needed when using Azure Ope |AZURE_OPENAI_SYSTEM_MESSAGE|You are an AI assistant that helps people find information.|A brief description of the role and tone the model should use| |AZURE_OPENAI_PREVIEW_API_VERSION|2023-06-01-preview|API version when using Azure OpenAI on your data| |AZURE_OPENAI_STREAM|True|Whether or not to use streaming for the response| -|AZURE_OPENAI_EMBEDDING_ENDPOINT||The endpoint for your Ada embedding model deployment if using vector search. -|AZURE_OPENAI_EMBEDDING_KEY||The key for the Azure OpenAI resource with the Ada deployment to use with vector search.| +|AZURE_OPENAI_EMBEDDING_NAME||The name of your embedding model deployment if using vector search. ## Contributing diff --git a/app.py b/app.py index 8c1851ecb6..f5ab6fe553 100644 --- a/app.py +++ b/app.py @@ -60,6 +60,7 @@ def assets(path): AZURE_OPENAI_MODEL_NAME = os.environ.get("AZURE_OPENAI_MODEL_NAME", "gpt-35-turbo-16k") # Name of the model, e.g. 'gpt-35-turbo-16k' or 'gpt-4' AZURE_OPENAI_EMBEDDING_ENDPOINT = os.environ.get("AZURE_OPENAI_EMBEDDING_ENDPOINT") AZURE_OPENAI_EMBEDDING_KEY = os.environ.get("AZURE_OPENAI_EMBEDDING_KEY") +AZURE_OPENAI_EMBEDDING_NAME = os.environ.get("AZURE_OPENAI_EMBEDDING_NAME", "") SHOULD_STREAM = True if AZURE_OPENAI_STREAM.lower() == "true" else False @@ -186,8 +187,9 @@ def prepare_body_headers_with_data(request): "queryType": query_type, "semanticConfiguration": AZURE_SEARCH_SEMANTIC_SEARCH_CONFIG if AZURE_SEARCH_SEMANTIC_SEARCH_CONFIG else "", "roleInformation": AZURE_OPENAI_SYSTEM_MESSAGE, - "embeddingEndpoint": AZURE_OPENAI_EMBEDDING_ENDPOINT, - "embeddingKey": AZURE_OPENAI_EMBEDDING_KEY, + "embeddingDeploymentName": AZURE_OPENAI_EMBEDDING_NAME, + "embeddingEndpoint": AZURE_OPENAI_EMBEDDING_ENDPOINT if len(AZURE_OPENAI_EMBEDDING_NAME) == 0 else "", + "embeddingKey": AZURE_OPENAI_EMBEDDING_KEY if len(AZURE_OPENAI_EMBEDDING_NAME) == 0 else "", "filter": filter, "strictness": int(AZURE_SEARCH_STRICTNESS) } @@ -346,11 +348,9 @@ def conversation_with_data(request_body): result['history_metadata'] = history_metadata return Response(format_as_ndjson(result), status=status_code) - else: return Response(stream_with_data(body, headers, endpoint, history_metadata), mimetype='text/event-stream') - def stream_without_data(response, history_metadata={}): responseText = "" for line in response: @@ -707,4 +707,4 @@ def generate_title(conversation_messages): return messages[-2]['content'] if __name__ == "__main__": - app.run() + app.run() \ No newline at end of file diff --git a/infra/main.bicep b/infra/main.bicep index 520fb72d42..64834df77e 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -315,8 +315,7 @@ output AZURE_OPENAI_MODEL string = openAIModel output AZURE_OPENAI_MODEL_NAME string = openAIModelName output AZURE_OPENAI_SKU_NAME string = openAi.outputs.skuName output AZURE_OPENAI_KEY string = openAi.outputs.key -output AZURE_OPENAI_EMBEDDING_KEY string = openAi.outputs.key -output AZURE_OPENAI_EMBEDDING_ENDPOINT string = '${openAi.outputs.endpoint}/openai/deployments/${embeddingDeploymentName}/embeddings?api-version=2023-06-01-preview' +output AZURE_OPENAI_EMBEDDING_NAME string = '${embeddingDeploymentName}' output AZURE_OPENAI_TEMPERATURE int = openAITemperature output AZURE_OPENAI_TOP_P int = openAITopP output AZURE_OPENAI_MAX_TOKENS int = openAIMaxTokens diff --git a/infrastructure/deployment.json b/infrastructure/deployment.json index 255a769291..2a21d7e1de 100644 --- a/infrastructure/deployment.json +++ b/infrastructure/deployment.json @@ -244,18 +244,11 @@ "description": "Azure Search Strictness" } }, - "AzureOpenAIEmbeddingEndpoint": { + "AzureOpenAIEmbeddingName": { "type": "string", "defaultValue": "", "metadata": { - "description": "Azure OpenAI Embedding Endpoint" - } - }, - "AzureOpenAIEmbeddingKey": { - "type": "securestring", - "defaultValue": "", - "metadata": { - "description": "Azure OpenAI Embedding Key" + "description": "Azure OpenAI Embedding Deployment Name" } }, "WebAppEnableChatHistory": { @@ -417,12 +410,8 @@ "value": "[parameters('AzureSearchStrictness')]" }, { - "name": "AZURE_OPENAI_EMBEDDING_ENDPOINT", - "value": "[parameters('AzureOpenAIEmbeddingEndpoint')]" - }, - { - "name": "AZURE_OPENAI_EMBEDDING_KEY", - "value": "[parameters('AzureOpenAIEmbeddingKey')]" + "name": "AZURE_OPENAI_EMBEDDING_NAME", + "value": "[parameters('AzureOpenAIEmbeddingName')]" }, { "name": "SCM_DO_BUILD_DURING_DEPLOYMENT",