Dialogflow CX - 必须初始化位置设置 - FAILED_PRECONDITION

Dialogflow CX - Location settings have to be initialized - FAILED_PRECONDITION

我正在使用 Python 客户端库自动化 Dialogflow CX。这包括 agent/intent/entitycreation/updation/deletion。 但是第一次 运行,我遇到了来自 python.

的以下错误

如果我登录到控制台并从那里设置位置并重新运行 代码,它工作正常。我可以创建代理。

已关注此 URL GCP -

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 and 2.

另一方面,如果您觉得此功能有用,可以提交功能请求,here。它将由 Google 的产品团队进行评估。

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