0

我正在使用 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```

4

2 回答 2

1

目前,Dialogflow 不支持通过 API 配置位置设置,因此您无法通过它初始化位置设置。您只能通过控制台设置位置。

作为替代方案,由于每个项目的每个区域只需初始化一次位置设置,您可以设置位置并自动化代理创建过程,一些有用的链接:12

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

于 2021-06-02T09:28:01.713 回答
0

非常感谢亚历山大·莫拉斯。我已经提出了相同的功能要求。

于 2021-06-17T17:09:55.427 回答