azure 运行miscrosoft semantic-kernel时出现资源未找到错误

rqmkfv5c  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(148)

当我尝试使用Azure Open AI运行Semantic-kernel时,出现以下错误

  1. 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))

我使用以下代码,参考https://github.com/microsoft/semantic-kernel/blob/main/python/README.md

  1. from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
  2. kernel = sk.Kernel()
  3. deployment, api_key, endpoint = "<MY_DEPLOYMENT_NAME>","<MY_API_KEY>", "<MY_ENDPOINT>"
  4. # print(f'kernel.add_chat_service("dv", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))')
  5. kernel.add_chat_service("dv", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))
  6. # Wrap your prompt in a function
  7. prompt = kernel.create_semantic_function("""
  8. Write a simple hello-world python program.
  9. """)
  10. # Run your prompt
  11. print(prompt())

当我试图找到解决方案时,我在kerrnel.add_chat_service上运行print(f“)语句,得到以下错误

  1. Traceback (most recent call last):
  2. File "C:\Users\yashroop.rai\Desktop\semantic-kernel\semantic-kernel.py", line 10, in <module>
  3. prompt = kernel.create_semantic_function("""
  4. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5. File "C:\Users\yashroop.rai\AppData\Local\Programs\Python\Python311\Lib\site-packages\semantic_kernel\kernel.py", line 851, in create_semantic_function
  6. return self.register_semantic_function(
  7. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8. File "C:\Users\yashroop.rai\AppData\Local\Programs\Python\Python311\Lib\site-packages\semantic_kernel\kernel.py", line 129, in register_semantic_function
  9. function = self._create_semantic_function(
  10. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11. File "C:\Users\yashroop.rai\AppData\Local\Programs\Python\Python311\Lib\site-packages\semantic_kernel\kernel.py", line 692, in _create_semantic_function
  12. service = self.get_ai_service(
  13. ^^^^^^^^^^^^^^^^^^^^
  14. File "C:\Users\yashroop.rai\AppData\Local\Programs\Python\Python311\Lib\site-packages\semantic_kernel\kernel.py", line 429, in get_ai_service
  15. raise ValueError(
  16. ValueError: TextCompletionClientBase service with service_id 'None' not found

有什么办法吗?端点和API_key是正确的,因为我一直在使用它作为一个正常的POST请求通过API调用,这工作正常。

7y4bm7vi

7y4bm7vi1#

运行Microsoft semantic-kernel时出现资源未找到错误
当您在代码中传递不正确的部署名称或API_key或终结点时,会发生上述错误。
我创建了Azure Open AI服务,并部署了名为**deploymentname1gpt-35-turbo**模型。

入口:

现在使用下面的代码,我可以使用Python在Azure open ai中运行语义内核。

验证码:

  1. from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
  2. import semantic_kernel as sk
  3. kernel = sk.Kernel()
  4. deployment="deploymentname1"
  5. api_key="your-azure-api-key"
  6. endpoint="https://<resource name>.openai.azure.com/"
  7. kernel.add_chat_service("dv", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))
  8. prompt = kernel.create_semantic_function("""
  9. Write a simple palindrome python program.
  10. """)
  11. # Run your prompt
  12. print(prompt())

输出:

  1. Here's a simple palindrome python program:

word = input("Enter a word: ")

if word == word[::-1]:
print("The word is a palindrome!")
else:
print("The word is not a palindrome.")

  1. This program prompts the user to enter a word, and then checks if the word is the same forwards and backwards (i.e. a palindrome) using slicing. If the word is a palindrome, it prints a message saying so. Otherwise, it prints a message saying the word is not a palindrome.

参考:

向语义内核添加AI服务|微软学习

展开查看全部

相关问题