gpt4 book ai didi

python - 运行 Miscrosoft Semantic-kernel 时出现资源未找到错误

转载 作者:行者123 更新时间:2023-12-03 06:06:23 28 4
gpt4 key购买 nike

尝试使用 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))

我正在使用以下代码并引用 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())

当我尝试寻找解决方案时,我在 kerrnel.add_chat_service 上运行了 print(f'') 语句我收到以下错误

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

有什么解决办法吗?端点和 api_key 是正确的,因为我一直通过 api 调用将其用作正常的 POST 请求,效果很好。

最佳答案

Resource not found error when running Microsoft semantic-kernel

当您在代码中传递错误的部署名称或 api_key 或端点时,会发生上述错误。

我创建了 Azure 开放式人工智能服务,并部署了名为 deploymentname1gpt-35-turbo 模型.

门户:

enter image description here

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

代码:

from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
import semantic_kernel as sk

kernel = sk.Kernel()

deployment="deploymentname1"
api_key="your-azure-api-key"
endpoint="https://<resource name>.openai.azure.com/"
kernel.add_chat_service("dv", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))

prompt = kernel.create_semantic_function("""
Write a simple palindrome python program.
""")

# Run your prompt
print(prompt())

输出:

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.")
```

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.

enter image description here

引用:

Adding AI services to Semantic Kernel | Microsoft Learn

关于python - 运行 Miscrosoft Semantic-kernel 时出现资源未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77271033/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com