我在 python 中创建会话以嵌入 watson ai 功能时发现错误

问题描述 投票:0回答:1
Method failed with status code 404: Resource not found

我无法理解为什么我收到“资源未找到”错误。这是什么意思

from ibm_watson import AssistantV2, ApiException
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('api correct')
assistant = AssistantV2(
    version='2023-03-20',
    authenticator=authenticator
)

assistant.set_service_url('used america dallas')

try:
    session = assistant.create_session(
        assistant_id='directly copied and pasted'
    ).get_result()

    session_id = session['session_id']
    response = assistant.message(
        assistant_id='same here',
        session_id=session_id,
        input={
            'message_type': 'text',
            'text': 'Hello, how are you?'
        }
    ).get_result()

    print(response)
except ApiException as ex:
    print("Method failed with status code " + str(ex.code) + ": " + ex.message)

我尝试通过它的 api 将它连接到 watson ai 并期望它的响应,但它总是给我资源错误

machine-learning ibm-cloud
1个回答
0
投票

该错误与输入的信息不正确有关。您应该检查以下内容。

  • Apikey 与您要调用的实例相同。
  • 该实例位于
    us-south
    (您的达拉斯评论)
  • assistant_id
    是一个不同的值,具体取决于您在做什么。
    • 消息、会话和日志请求 =
      environment_id
    • 所有其他请求都使用
      assistant_id
    • 对于经典版本,请始终使用
      assistant_id

在示例代码中,您使用的是

message
,因此您应该使用
environment_id

要查找环境 ID,可以在 WA 的环境部分中找到。单击页面标题旁边的齿轮。

或者,如果您单击左下角的助手设置,您可以在那里进行所有设置。

© www.soinside.com 2019 - 2024. All rights reserved.