mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
Python: Update examples and notebooks to stop using text-davinci-003 (#2359)
### Motivation and Context text-davinci-003 is being retired by Azure OpenAI and is no longer supported for new deployments Resolves - https://github.com/microsoft/semantic-kernel/issues/2309 <!-- 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 Update examples and notebooks to use gpt-35-turbo / gpt-3.5-turbo instead <!-- 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 😄 Signed-off-by: karthikmurali60 <[email protected]> Co-authored-by: Lee Miller <[email protected]> Co-authored-by: Gil LaHaye <[email protected]>
This commit is contained in:
co-authored by
Lee Miller
Gil LaHaye
parent
ae521f3d3c
commit
0a477b198c
+1
-1
@@ -32,7 +32,7 @@ kernel = sk.Kernel()
|
||||
|
||||
# Prepare OpenAI service using credentials stored in the `.env` file
|
||||
api_key, org_id = sk.openai_settings_from_dot_env()
|
||||
kernel.add_text_completion_service("dv", OpenAITextCompletion("text-davinci-003", api_key, org_id))
|
||||
kernel.add_chat_service("chat-gpt", OpenAIChatCompletion("gpt-3.5-turbo", api_key, org_id))
|
||||
|
||||
# Alternative using Azure:
|
||||
# deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"OPENAI_ORG_ID=\"\"\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"and add OpenAI Text Completion to the kernel:"
|
||||
"and add OpenAI Chat Completion to the kernel:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -53,11 +53,11 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantic_kernel.connectors.ai.open_ai import OpenAITextCompletion\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion\n",
|
||||
"\n",
|
||||
"api_key, org_id = sk.openai_settings_from_dot_env()\n",
|
||||
"\n",
|
||||
"kernel.add_text_completion_service(\"dv\", OpenAITextCompletion(\"text-davinci-003\", api_key, org_id))"
|
||||
"kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -75,7 +75,7 @@
|
||||
"AZURE_OPENAI_DEPLOYMENT_NAME=\"...\"\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"and add Azure OpenAI Text Completion to the kernel:"
|
||||
"and add Azure OpenAI Chat Completion to the kernel:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -84,11 +84,11 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion\n",
|
||||
"\n",
|
||||
"deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
|
||||
"\n",
|
||||
"kernel.add_text_completion_service(\"dv\", AzureTextCompletion(deployment, endpoint, api_key))"
|
||||
"kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import semantic_kernel as sk\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion, OpenAITextCompletion"
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -87,19 +87,19 @@
|
||||
"source": [
|
||||
"kernel = sk.Kernel()\n",
|
||||
"\n",
|
||||
"kernel.add_text_completion_service( # We are adding a text service\n",
|
||||
"kernel.add_chat_service( # We are adding a text service\n",
|
||||
" \"Azure_curie\", # The alias we can use in prompt templates' config.json\n",
|
||||
" AzureTextCompletion(\n",
|
||||
" AzureChatCompletion(\n",
|
||||
" \"my-finetuned-Curie\", # Azure OpenAI *Deployment name*\n",
|
||||
" \"https://contoso.openai.azure.com/\", # Azure OpenAI *Endpoint*\n",
|
||||
" \"...your Azure OpenAI Key...\" # Azure OpenAI *Key*\n",
|
||||
" )\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"kernel.add_text_completion_service( # We are adding a text service\n",
|
||||
" \"OpenAI_davinci\", # The alias we can use in prompt templates' config.json\n",
|
||||
" OpenAITextCompletion(\n",
|
||||
" \"text-davinci-003\", # OpenAI Model Name\n",
|
||||
"kernel.add_chat_service( # We are adding a text service\n",
|
||||
" \"OpenAI_chat_gpt\", # The alias we can use in prompt templates' config.json\n",
|
||||
" OpenAIChatCompletion(\n",
|
||||
" \"gpt-3.5-turbo\", # OpenAI Model Name\n",
|
||||
" \"...your OpenAI API Key...\", # OpenAI API key\n",
|
||||
" \"...your OpenAI Org ID...\" # *optional* OpenAI Organization ID\n",
|
||||
" )\n",
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import semantic_kernel as sk\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion, OpenAITextCompletion\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
|
||||
"\n",
|
||||
"kernel = sk.Kernel()\n",
|
||||
"\n",
|
||||
@@ -109,10 +109,10 @@
|
||||
"# 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_text_completion_service(\"dv\", AzureTextCompletion(deployment, endpoint, api_key))\n",
|
||||
" kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n",
|
||||
"else:\n",
|
||||
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
|
||||
" kernel.add_text_completion_service(\"dv\", OpenAITextCompletion(\"text-davinci-003\", api_key, org_id))"
|
||||
" kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import semantic_kernel as sk\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion, OpenAITextCompletion\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
|
||||
"\n",
|
||||
"kernel = sk.Kernel()\n",
|
||||
"\n",
|
||||
@@ -46,10 +46,10 @@
|
||||
"# 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_text_completion_service(\"dv\", AzureTextCompletion(deployment, endpoint, api_key))\n",
|
||||
" kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n",
|
||||
"else:\n",
|
||||
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
|
||||
" kernel.add_text_completion_service(\"dv\", OpenAITextCompletion(\"text-davinci-003\", api_key, org_id))"
|
||||
" kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
"from typing import Tuple\n",
|
||||
"\n",
|
||||
"import semantic_kernel as sk\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import OpenAITextCompletion, OpenAITextEmbedding, AzureTextCompletion, AzureTextEmbedding"
|
||||
"from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, OpenAITextEmbedding, AzureChatCompletion, AzureTextEmbedding"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -70,12 +70,12 @@
|
||||
"# 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_text_completion_service(\"dv\", AzureTextCompletion(deployment, endpoint, api_key))\n",
|
||||
" kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", 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",
|
||||
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
|
||||
" kernel.add_text_completion_service(\"dv\", OpenAITextCompletion(\"text-davinci-003\", api_key, org_id))\n",
|
||||
" kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))\n",
|
||||
" kernel.add_text_embedding_generation_service(\"ada\", OpenAITextEmbedding(\"text-embedding-ada-002\", api_key, org_id))\n",
|
||||
"\n",
|
||||
"kernel.register_memory_store(memory_store=sk.memory.VolatileMemoryStore())\n",
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"import semantic_kernel as sk\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion, OpenAITextCompletion\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
|
||||
"\n",
|
||||
"kernel = sk.Kernel()\n",
|
||||
"\n",
|
||||
@@ -69,10 +69,10 @@
|
||||
"# 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_text_completion_service(\"dv\", AzureTextCompletion(deployment, endpoint, api_key))\n",
|
||||
" kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n",
|
||||
"else:\n",
|
||||
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
|
||||
" kernel.add_text_completion_service(\"dv\", OpenAITextCompletion(\"text-davinci-003\", api_key, org_id))"
|
||||
" kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -225,7 +225,7 @@
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"import semantic_kernel as sk\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion, OpenAITextCompletion\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
|
||||
"\n",
|
||||
"kernel = sk.Kernel()\n",
|
||||
"\n",
|
||||
@@ -235,10 +235,10 @@
|
||||
"# 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_text_completion_service(\"dv\", AzureTextCompletion(deployment, endpoint, api_key))\n",
|
||||
" kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n",
|
||||
"else:\n",
|
||||
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
|
||||
" kernel.add_text_completion_service(\"dv\", OpenAITextCompletion(\"text-davinci-003\", api_key, org_id))"
|
||||
" kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import semantic_kernel as sk\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion, OpenAITextCompletion\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
|
||||
"\n",
|
||||
"kernel = sk.Kernel()\n",
|
||||
"\n",
|
||||
@@ -92,10 +92,10 @@
|
||||
"# 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_text_completion_service(\"dv\", AzureTextCompletion(deployment, endpoint, api_key))\n",
|
||||
" kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(\"gpt-35-turbo\", endpoint, api_key))\n",
|
||||
"else:\n",
|
||||
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
|
||||
" kernel.add_text_completion_service(\"dv\", OpenAITextCompletion(\"text-davinci-003\", api_key, org_id))"
|
||||
" kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -190,7 +190,7 @@
|
||||
"\n",
|
||||
"import semantic_kernel as sk\n",
|
||||
"from semantic_kernel.connectors.ai.open_ai import (\n",
|
||||
" OpenAITextCompletion,\n",
|
||||
" OpenAIChatCompletion,\n",
|
||||
" OpenAITextEmbedding,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
@@ -264,8 +264,8 @@
|
||||
"kernel = sk.Kernel()\n",
|
||||
"\n",
|
||||
"api_key, org_id = sk.openai_settings_from_dot_env()\n",
|
||||
"kernel.add_text_completion_service(\n",
|
||||
" \"dv\", OpenAITextCompletion(\"text-davinci-003\", api_key, org_id)\n",
|
||||
"kernel.add_chat_service(\n",
|
||||
" \"chat-gpt\", OpenAIChatCompletion(\"gpt-3.5-turbo\", api_key, org_id)\n",
|
||||
")\n",
|
||||
"kernel.add_text_embedding_generation_service(\n",
|
||||
" \"ada\", OpenAITextEmbedding(\"text-embedding-ada-002\", api_key, org_id)\n",
|
||||
|
||||
@@ -3,7 +3,7 @@ import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import semantic_kernel as sk
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAITextCompletion
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
|
||||
from semantic_kernel.connectors.search_engine import BingConnector
|
||||
from semantic_kernel.core_skills import WebSearchEngineSkill
|
||||
|
||||
@@ -13,8 +13,8 @@ load_dotenv()
|
||||
async def main():
|
||||
kernel = sk.Kernel()
|
||||
api_key, org_id = sk.openai_settings_from_dot_env()
|
||||
kernel.add_text_completion_service(
|
||||
"dv", OpenAITextCompletion("text-davinci-003", api_key, org_id)
|
||||
kernel.add_chat_service(
|
||||
"chat-gpt", OpenAIChatCompletion("gpt-3.5-turbo", api_key, org_id)
|
||||
)
|
||||
connector = BingConnector(api_key=os.getenv("BING_API_KEY"))
|
||||
web_skill = kernel.import_skill(WebSearchEngineSkill(connector), "WebSearch")
|
||||
|
||||
@@ -18,8 +18,8 @@ ChatBot:>
|
||||
kernel = sk.Kernel()
|
||||
|
||||
api_key, org_id = sk.openai_settings_from_dot_env()
|
||||
kernel.add_text_completion_service(
|
||||
"davinci-003", sk_oai.OpenAITextCompletion("text-davinci-003", api_key, org_id)
|
||||
kernel.add_chat_service(
|
||||
"chat-gpt", sk_oai.OpenAIChatCompletion("gpt-3.5-turbo", api_key, org_id)
|
||||
)
|
||||
|
||||
prompt_config = sk.PromptTemplateConfig.from_completion_parameters(
|
||||
|
||||
@@ -5,7 +5,7 @@ import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import semantic_kernel as sk
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAITextCompletion
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
|
||||
from semantic_kernel.connectors.search_engine import GoogleConnector
|
||||
from semantic_kernel.core_skills import WebSearchEngineSkill
|
||||
|
||||
@@ -15,8 +15,8 @@ load_dotenv()
|
||||
async def main():
|
||||
kernel = sk.Kernel()
|
||||
api_key, org_id = sk.openai_settings_from_dot_env()
|
||||
kernel.add_text_completion_service(
|
||||
"dv", OpenAITextCompletion("text-davinci-003", api_key, org_id)
|
||||
kernel.add_chat_service(
|
||||
"chat-gpt", OpenAIChatCompletion("gpt-3.5-turbo", api_key, org_id)
|
||||
)
|
||||
|
||||
"""
|
||||
|
||||
@@ -108,8 +108,8 @@ async def main() -> None:
|
||||
kernel = sk.Kernel()
|
||||
|
||||
api_key, org_id = sk.openai_settings_from_dot_env()
|
||||
kernel.add_text_completion_service(
|
||||
"dv", sk_oai.OpenAITextCompletion("text-davinci-003", api_key, org_id)
|
||||
kernel.add_chat_service(
|
||||
"chat-gpt", sk_oai.OpenAIChatCompletion("gpt-3.5-turbo", api_key, org_id)
|
||||
)
|
||||
kernel.add_text_embedding_generation_service(
|
||||
"ada", sk_oai.OpenAITextEmbedding("text-embedding-ada-002", api_key, org_id)
|
||||
|
||||
Reference in New Issue
Block a user