From d5711d3a3ad5d81d02f74d0b5043b5a5c4fdf672 Mon Sep 17 00:00:00 2001 From: Alwin Arrasyid Date: Tue, 19 Sep 2023 01:27:55 +0700 Subject: [PATCH] Python: No more hardcoded Azure OpenAI Service deployment name (#2684) ### Motivation and Context Solve confusion due to hardcoded Azure OpenAI Service deployment name in Python notebooks. ### Description Previously, the deployment name for Azure OpenAI Service in the Python notebooks was hardcoded as "gpt-35-turbo". This PR solves the confusion by using the `deployment` variable loaded from `.env` file. ### Contribution Checklist - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone :smile: --- python/notebooks/02-running-prompts-from-file.ipynb | 2 +- python/notebooks/04-context-variables-chat.ipynb | 2 +- python/notebooks/06-memory-and-embeddings.ipynb | 2 +- python/notebooks/08-native-function-inline.ipynb | 4 ++-- python/notebooks/09-groundedness-checking.ipynb | 2 +- python/notebooks/10-multiple-results-per-prompt.ipynb | 4 ++-- python/notebooks/11-streaming-completions.ipynb | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/python/notebooks/02-running-prompts-from-file.ipynb b/python/notebooks/02-running-prompts-from-file.ipynb index 1ec1390570a7..c41dc0294caf 100644 --- a/python/notebooks/02-running-prompts-from-file.ipynb +++ b/python/notebooks/02-running-prompts-from-file.ipynb @@ -109,7 +109,7 @@ "# Configure AI service used by the kernel\n", "if useAzureOpenAI:\n", " deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n", - " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n", + " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(deployment, endpoint, api_key))\n", "else:\n", " api_key, org_id = sk.openai_settings_from_dot_env()\n", " kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))" diff --git a/python/notebooks/04-context-variables-chat.ipynb b/python/notebooks/04-context-variables-chat.ipynb index 6887c09bb75f..e8a5303a8506 100644 --- a/python/notebooks/04-context-variables-chat.ipynb +++ b/python/notebooks/04-context-variables-chat.ipynb @@ -46,7 +46,7 @@ "# Configure AI service used by the kernel\n", "if useAzureOpenAI:\n", " deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n", - " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n", + " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(deployment, endpoint, api_key))\n", "else:\n", " api_key, org_id = sk.openai_settings_from_dot_env()\n", " kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))\n" diff --git a/python/notebooks/06-memory-and-embeddings.ipynb b/python/notebooks/06-memory-and-embeddings.ipynb index 6f1e4ffc8326..4e43e925be17 100644 --- a/python/notebooks/06-memory-and-embeddings.ipynb +++ b/python/notebooks/06-memory-and-embeddings.ipynb @@ -70,7 +70,7 @@ "# Configure AI service used by the kernel\n", "if useAzureOpenAI:\n", " deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n", - " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n", + " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(deployment, endpoint, api_key))\n", " # next line assumes embeddings deployment name is \"text-embedding-ada-002\", adjust this if appropriate \n", " kernel.add_text_embedding_generation_service(\"ada\", AzureTextEmbedding(\"text-embedding-ada-002\", endpoint, api_key))\n", "else:\n", diff --git a/python/notebooks/08-native-function-inline.ipynb b/python/notebooks/08-native-function-inline.ipynb index 9e9f33e4a8bc..484f43a9a27a 100644 --- a/python/notebooks/08-native-function-inline.ipynb +++ b/python/notebooks/08-native-function-inline.ipynb @@ -69,7 +69,7 @@ "# Configure AI service used by the kernel\n", "if useAzureOpenAI:\n", " deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n", - " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n", + " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(deployment, endpoint, api_key))\n", "else:\n", " api_key, org_id = sk.openai_settings_from_dot_env()\n", " kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))" @@ -235,7 +235,7 @@ "# Configure AI service used by the kernel\n", "if useAzureOpenAI:\n", " deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n", - " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n", + " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(deployment, endpoint, api_key))\n", "else:\n", " api_key, org_id = sk.openai_settings_from_dot_env()\n", " kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))\n" diff --git a/python/notebooks/09-groundedness-checking.ipynb b/python/notebooks/09-groundedness-checking.ipynb index 81d06ad8e679..8dd15ca7e453 100644 --- a/python/notebooks/09-groundedness-checking.ipynb +++ b/python/notebooks/09-groundedness-checking.ipynb @@ -92,7 +92,7 @@ "# Configure AI service used by the kernel\n", "if useAzureOpenAI:\n", " deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n", - " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n", + " kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(deployment, endpoint, api_key))\n", "else:\n", " api_key, org_id = sk.openai_settings_from_dot_env()\n", " kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))" diff --git a/python/notebooks/10-multiple-results-per-prompt.ipynb b/python/notebooks/10-multiple-results-per-prompt.ipynb index d572ee49325a..8934401e7823 100644 --- a/python/notebooks/10-multiple-results-per-prompt.ipynb +++ b/python/notebooks/10-multiple-results-per-prompt.ipynb @@ -61,8 +61,8 @@ "\n", "# Configure Azure LLM service\n", "deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n", - "azure_text_service = AzureTextCompletion(\"text-davinci-003\", endpoint, api_key)\n", - "azure_chat_service = AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key)\n", + "azure_text_service = AzureTextCompletion(deployment, endpoint, api_key)\n", + "azure_chat_service = AzureChatCompletion(deployment, endpoint, api_key)\n", "\n", "# Configure OpenAI service\n", "api_key, org_id = sk.openai_settings_from_dot_env()\n", diff --git a/python/notebooks/11-streaming-completions.ipynb b/python/notebooks/11-streaming-completions.ipynb index ba9572351f87..8179e69e7e36 100644 --- a/python/notebooks/11-streaming-completions.ipynb +++ b/python/notebooks/11-streaming-completions.ipynb @@ -52,8 +52,8 @@ "\n", "# Configure Azure LLM service\n", "deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n", - "azure_text_service = AzureTextCompletion(\"text-davinci-003\", endpoint, api_key)\n", - "azure_chat_service = AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key)\n", + "azure_text_service = AzureTextCompletion(deployment, endpoint, api_key)\n", + "azure_chat_service = AzureChatCompletion(deployment, endpoint, api_key)\n", "\n", "# Configure OpenAI service\n", "api_key, org_id = sk.openai_settings_from_dot_env()\n",