"代理客户端"对象没有属性"set_agent"



我正在尝试使用dialogflow python客户端制作一个dialogflow代理。我指的是谷歌在https://dialogflow-python-client-v2.readthedocs.io/en/latest/gapic/v2/api.html#dialogflow_v2.AgentsClient.set_agent。

通过遵循文档,我编写了以下代码

import dialogflow_v2 as dialogflow
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/home/ubuntu/myServiceAccountKey.json"
client = dialogflow.AgentsClient()
agent = {"parent": "project-id","displayName":"Agent1","defaultLanguageCode":"en-US","timeZone":"Asia/Kolkata"}
response = client.set_agent(agent)

但是当我运行上面的程序时,我得到了以下错误

属性错误:"AgentsClient"对象没有属性"set_agent">

显然,客户端对象没有"set_agent"属性。这是dir(客户端(的结果

['SERVICE_ADDRESS', '_INTERFACE_NAME', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_client_info', '_inner_api_calls', '_method_configs', 'enums', 'export_agent', 'from_service_account_file', 'from_service_account_json', 'get_agent', 'import_agent', 'project_path', 'restore_agent', 'search_agents', 'train_agent', 'transport']

当谷歌在其文档中提到使用set_agent((函数创建或更新代理时,这怎么可能呢?

我也遇到了同样的问题。事实证明,set_agent方法是在2019-10-16添加的,但在此之前我安装了dialogflow库。尝试在您的python环境中通过pip命令更新对话流库。

pip install --upgrade dialogflow

最新更新