对话框流CX-必须初始化位置设置-FAILED_PRECONDITION



我正在使用Python客户端库自动化Dialogflow CX。包括agent/intent/entitycreation/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配置位置设置,无法通过API初始化位置设置,只能通过Console进行位置设置。

作为一种选择,由于每个项目的每个区域只需初始化一次位置设置,因此可以设置位置并自动执行代理创建过程,一些有用的链接:1和2。

另一方面,如果你觉得这个功能很有用,你可以在这里提交一个功能请求。它将由谷歌的产品团队进行评估。

非常感谢Alexandre Moraes。我已经提出了同样的功能请求。

相关内容

最新更新