Skip to content

Commit

Permalink
Python: No more hardcoded Azure OpenAI Service deployment name (#2684)
Browse files Browse the repository at this point in the history
### Motivation and Context

Solve confusion due to hardcoded Azure OpenAI Service deployment name in
Python notebooks.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### 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.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [ ] 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 😄
  • Loading branch information
alwint3r authored Sep 18, 2023
1 parent 6c999c0 commit d5711d3
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion python/notebooks/02-running-prompts-from-file.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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))"
Expand Down
2 changes: 1 addition & 1 deletion python/notebooks/04-context-variables-chat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion python/notebooks/06-memory-and-embeddings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions python/notebooks/08-native-function-inline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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))"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion python/notebooks/09-groundedness-checking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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))"
Expand Down
4 changes: 2 additions & 2 deletions python/notebooks/10-multiple-results-per-prompt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions python/notebooks/11-streaming-completions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d5711d3

Please sign in to comment.