我正在尝试使用带有Python脚本的命令行界面中的Watson Assistant,类似于演示Building a custom client。Python脚本是:
from ibm_watson import AssistantV2
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
# Create Assistant service object.
authenticator = IAMAuthenticator(api_key_for_wa_service) # replace with API key
assistant = AssistantV2(
version = '2020-09-24',
authenticator = authenticator
)
assistant.set_service_url('https://api.au-syd.assistant.watson.cloud.ibm.com')
assistant_id = '00965b15-eb3f-4d83-8983-3df0c7da9c4f'
# Start conversation with empty message:
response = assistant.message_stateless(assistant_id,
).get_result()我认为连接正常,但请求失败,状态代码为422:
c:\Runnable>python create_watson_assistant_service_object.py
Method failed with status code 422: Unknown error我尝试在请求中的assistant_id参数后传递一个输入参数:
input = {'message_type': 'text', 'text': 'Hello'}这会产生相同的结果(代码422)。
我不知道下一步该怎么做。
发布于 2021-07-05 19:47:59
目前还不清楚assistant_id设置为什么。在你的代码片段中,my_assistant_id并没有被初始化。
assistant_id = my_assistant_id您也没有提供任何输入。来自API文档- https://cloud.ibm.com/apidocs/assistant/assistant-v2?code=python#messagestateless
import json
from ibm_watson import AssistantV2
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
assistant = AssistantV2(
version='2020-04-01',
authenticator = authenticator
)
assistant.set_service_url('{url}')
response = assistant.message_stateless(
assistant_id='{assistant_id}',
input={
'message_type': 'text',
'text': 'Hello'
}
).get_result()
print(json.dumps(response, indent=2))https://stackoverflow.com/questions/68232843
复制相似问题