You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Azure OpenAI运行Semantic Kernel遇资源未找到等错误求助

Azure OpenAI + Semantic Kernel 报错排查与解决

遇到的错误

错误1:资源未找到(404)

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

错误2:找不到文本补全服务

执行调试print语句后出现:

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

用户代码

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()) 

解决方案

针对错误1(404资源未找到)

  1. 确认**部署名称(deployment_name)**与Azure门户中创建的聊天模型部署名称完全一致,注意大小写敏感。
  2. 验证部署的模型类型:AzureChatCompletion仅支持聊天类模型(如gpt-35-turbo、gpt-4系列),若部署的是文本补全模型(如text-davinci-003),需改用AzureTextCompletion。
  3. 检查endpoint格式:确保endpoint为https://<资源名称>.openai.azure.com/,无需额外路径,且未包含拼写错误。

针对错误2(找不到文本补全服务)

create_semantic_function默认会查找文本补全服务(TextCompletionClientBase),但你添加的是聊天服务(ChatCompletion),需显式指定使用的服务ID:

# 修改语义函数创建代码,指定service_id为你添加的聊天服务ID"dv"
prompt = kernel.create_semantic_function(
    """Write a simple hello-world python program.""",
    service_id="dv"
)

或者,改用聊天服务的原生调用方式更适配场景:

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

async def main():
    kernel = sk.Kernel()
    deployment, api_key, endpoint = "<MY_DEPLOYMENT_NAME>","<MY_API_KEY>", "<MY_ENDPOINT>"
    kernel.add_chat_service("dv", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))
    
    chat_service = kernel.get_chat_service("dv")
    result = await chat_service.complete_chat(
        history=[],
        prompt="Write a simple hello-world python program."
    )
    print(result)

asyncio.run(main())

内容的提问来源于stack exchange,提问作者YRR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 15:37:03