I am getting the following error when trying to run semantic-kernel using azure open ai
Error: (<ErrorCodes.ServiceError: 6>, 'OpenAI service failed to complete the chat', InvalidRequestError(message='Resource not found', param=None, code='404', http_status=404, request_id=None))
I am using the following code with reference from https://github.com/microsoft/semantic-kernel/blob/main/python/README.md
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
kernel = sk.Kernel()
deployment, api_key, endpoint = "<MY_DEPLOYMENT_NAME>","<MY_API_KEY>", "<MY_ENDPOINT>"
# print(f'kernel.add_chat_service("dv", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))')
kernel.add_chat_service("dv", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))
# Wrap your prompt in a function
prompt = kernel.create_semantic_function("""
Write a simple hello-world python program.
""")
# Run your prompt
print(prompt())
When I tried finding solution, I ran print(f'') statement over kerrnel.add_chat_service And I got following error
Traceback (most recent call last):
File "C:\Users\yashroop.rai\Desktop\semantic-kernel\semantic-kernel.py", line 10, in <module>
prompt = kernel.create_semantic_function("""
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yashroop.rai\AppData\Local\Programs\Python\Python311\Lib\site-packages\semantic_kernel\kernel.py", line 851, in create_semantic_function
return self.register_semantic_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yashroop.rai\AppData\Local\Programs\Python\Python311\Lib\site-packages\semantic_kernel\kernel.py", line 129, in register_semantic_function
function = self._create_semantic_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yashroop.rai\AppData\Local\Programs\Python\Python311\Lib\site-packages\semantic_kernel\kernel.py", line 692, in _create_semantic_function
service = self.get_ai_service(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yashroop.rai\AppData\Local\Programs\Python\Python311\Lib\site-packages\semantic_kernel\kernel.py", line 429, in get_ai_service
raise ValueError(
ValueError: TextCompletionClientBase service with service_id 'None' not found
Any solutions ? The endpoint and api_key are correct because I have been using that as a normal POST request through api call which works fine.
The above error occurs when you pass an incorrect deployment name or api_key or endpoint in your code.
I created Azure open ai service and deployed
gpt-35-turbo
model with the name ofdeploymentname1
.Portal:
Now using the below code, I can able to run semantic-kernel with Azure open ai using Python.
Code:
Output:
Reference:
Adding AI services to Semantic Kernel | Microsoft Learn