如何解决Dialogflow CX - 必须初始化位置设置 - FAILED_PRECONDITION
我正在使用 Python 客户端库自动化 Dialogflow CX。这包括 agent
/intent
/entity
等。creation
/updation
/deletion
。
但是第一次运行时,我遇到了来自python的以下错误。
如果我登录到控制台并从那里设置位置并重新运行代码,它工作正常。我可以创建代理。
关注 GCP 的这个 URL -
https://cloud.google.com/dialogflow/cx/docs/concept/region
我正在寻找在运行 python 代码之前自动设置区域和位置的代码。请提供代码给我。
下面是我用来创建代理的代码。
Error -
google.api_core.exceptions.FailedPrecondition: 400 com.google.apps.framework.request.FailedPreconditionException: Location settings have to be initialized before creating the agent in location: us-east1. Code: FAILED_PRECONDITION
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.FAILED_PRECONDITION
details = "com.google.apps.framework.request.FailedPreconditionException: Location settings have to be initialized before creating the agent in location: us-east1. Code: FAILED_PRECONDITION"
debug_error_string = "{"created":"@1622183899.891000000","description":"Error received from peer ipv4:142.250.195.170:443","file":"src/core/lib/surface/call.cc","file_line":1068,"grpc_message":"com.google.apps.framework.request.FailedPreconditionException: Location settings have to be initialized before creating the agent in location: us-east1. Code: FAILED_PRECONDITION","grpc_status":9}"
main.py -
# Import Libraries
import google.auth
import google.auth.transport.requests
from google.cloud import dialogflowcx as df
from google.protobuf.field_mask_pb2 import FieldMask
import os,time
import pandas as pd
# Function - Authentication
def gcp_auth():
cred,project = google.auth.default(scopes=["https://www.googleapis.com/auth/cloud-platform"])
auth_req = google.auth.transport.requests.Request()
cred.refresh(auth_req)
# Function - Create Agent
def create_agent(agent_name,agent_description,language_code,location_id,location_path):
if location_id == "global":
agentsClient = df.AgentsClient()
else:
agentsClient = df.AgentsClient(client_options={"api_endpoint": f"{location_id}-dialogflow.googleapis.com:443"})
agent = df.Agent(display_name=agent_name,description=agent_description,default_language_code=language_code,time_zone=time_zone,enable_stackdriver_logging=True)
createAgentRequest = df.CreateAgentRequest(agent=agent,parent=location_path)
agent = agentsClient.create_agent(request=createAgentRequest)
return agent```
解决方法
目前,Dialogflow 不支持通过 API 配置位置设置,因此您无法通过它来初始化位置设置。您只能通过控制台设置位置。
作为替代方案,由于每个项目的每个区域的位置设置只需初始化一次,您可以设置位置并自动执行代理创建过程,一些有用的链接:1 和 2。
另一方面,如果您觉得此功能有用,您可以提交功能请求,here。它将由 Google 的产品团队进行评估。
,非常感谢亚历山大·莫拉斯。我已经提出了相同的功能请求。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。