区域化和数据驻留

Dialogflow 提供数据驻留以保持您的存储中的数据(静态数据)实际上在一个地理地区或位置内。指定地区时,您的静态数据不会复制到该地区之外。所有地区的价格都相同。

使用地区的原因如下:

  • 您的系统可能有一些法规或政策要求,限定了您的数据必须存放的位置。
  • 当数据位于客户所在的地区时,您的网络延迟可能会得到改善。例如,如果英国客户使用 europe-west2,那么延迟时间可能会更短。

存储中的数据(静态数据)

所有 Dialogflow 开发者用户和最终用户数据都包含在静态数据中。例如:

  • 使用控制台或 API 设置的所有代理资源(意图、实体等)
  • 使用控制台或 API 进行的所有代理设置
  • 查询记录
  • 验证结果
  • 模型创建任务
  • 训练任务
  • 长时间运行的操作任务

可用区域

Dialogflow 提供以下地区:

国家/地区分组 地理位置 区域 ID
欧洲 比利时 europe-west1
欧洲 伦敦 europe-west2
亚太地区 悉尼 australia-southeast1
亚太地区 东京 asia-northeast1
全球 Dialogflow 服务面向全球,静态数据位于美国 global(首选)、us(已弃用)或无区域(默认)

使用控制台选择地区

Dialogflow ES 控制台的左上角区域有一个地区选择下拉列表。每个代理都有一个在创建时指定的不可变地区。 从控制台中选择地区时,您只能为所选地区列出或创建代理。 默认地区为 us

使用 API 选择地区

如果代理是在非默认地区创建的,则必须在为设计时请求或运行时请求调用 API 时指定该地区。

要提供地区,您需要向 API 请求提供 location 参数。对于 REST 调用,请同时执行以下两个操作:

  • 提供 location 网址路径参数。
  • 使用特定于区域的主机名,形式为 REGION_ID-dialogflow.googleapis.com。例如:asia-northeast1-dialogflow.googleapis.com。如果主机名中指定的区域与网址路径中指定的区域不匹配,则请求将被拒绝。

对于客户端库,请参阅客户端库文档。您需要执行以下操作:

  • 将 Dialogflow 服务端点设置为:

    REGION_ID-dialogflow.googleapis.com:443
    
  • 将会话名称设置为:

    projects/PROJECT_ID/locations/REGION_ID/agent/sessions/SESSION_ID
    

例如:

REST

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目 ID
  • REGION_ID:区域 ID,例如:europe-west2
  • SESSION_ID:会话 ID。

HTTP 方法和网址:

POST https://REGION_ID-dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/REGION_ID/agent/sessions/SESSION_ID:detectIntent

请求 JSON 正文:

{
  "query_input": {
    "text": {
      "text": "I want a pony.",
      "language_code": "en-US"
    }
  }
}

如需发送您的请求,请展开以下选项之一:

 

Java

要向 Dialogflow 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


import com.google.api.gax.rpc.ApiException;
import com.google.cloud.dialogflow.v2beta1.DetectIntentResponse;
import com.google.cloud.dialogflow.v2beta1.QueryInput;
import com.google.cloud.dialogflow.v2beta1.QueryResult;
import com.google.cloud.dialogflow.v2beta1.SessionName;
import com.google.cloud.dialogflow.v2beta1.SessionsClient;
import com.google.cloud.dialogflow.v2beta1.SessionsSettings;
import com.google.cloud.dialogflow.v2beta1.TextInput;
import com.google.common.collect.Maps;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public class DetectIntentWithLocation {

  // DialogFlow API Detect Intent sample with text inputs.
  public static Map<String, QueryResult> detectIntentWithLocation(
      String projectId,
      String locationId,
      List<String> texts,
      String sessionId,
      String languageCode)
      throws IOException, ApiException {
    SessionsSettings sessionsSettings =
        SessionsSettings.newBuilder()
            .setEndpoint(locationId + "-dialogflow.googleapis.com:443")
            .build();
    Map<String, QueryResult> queryResults = Maps.newHashMap();
    // Instantiates a client
    try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
      // Set the session name using the projectId (my-project-id), locationId and sessionId (UUID)
      SessionName session =
          SessionName.ofProjectLocationSessionName(projectId, locationId, sessionId);
      System.out.println("Session Path: " + session.toString());

      // Detect intents for each text input
      for (String text : texts) {
        // Set the text (hello) and language code (en-US) for the query
        TextInput.Builder textInput =
            TextInput.newBuilder().setText(text).setLanguageCode(languageCode);

        // Build the query with the TextInput
        QueryInput queryInput = QueryInput.newBuilder().setText(textInput).build();

        // Performs the detect intent request
        DetectIntentResponse response = sessionsClient.detectIntent(session, queryInput);

        // Display the query result
        QueryResult queryResult = response.getQueryResult();

        System.out.println("====================");
        System.out.format("Query Text: '%s'\n", queryResult.getQueryText());
        System.out.format(
            "Detected Intent: %s (confidence: %f)\n",
            queryResult.getIntent().getDisplayName(), queryResult.getIntentDetectionConfidence());
        System.out.format(
            "Fulfillment Text: '%s'\n",
            queryResult.getFulfillmentMessagesCount() > 0
                ? queryResult.getFulfillmentMessages(0).getText()
                : "Triggered Default Fallback Intent");

        queryResults.put(text, queryResult);
      }
    }
    return queryResults;
  }
}

Python

要向 Dialogflow 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

def detect_intent_texts_with_location(
    project_id, location_id, session_id, texts, language_code
):
    """Returns the result of detect intent with texts as inputs.

    Using the same `session_id` between requests allows continuation
    of the conversation."""
    from google.cloud import dialogflow

    session_client = dialogflow.SessionsClient(
        client_options={"api_endpoint": f"{location_id}-dialogflow.googleapis.com"}
    )

    session = (
        f"projects/{project_id}/locations/{location_id}/agent/sessions/{session_id}"
    )
    print(f"Session path: {session}\n")

    for text in texts:
        text_input = dialogflow.TextInput(text=text, language_code=language_code)

        query_input = dialogflow.QueryInput(text=text_input)

        response = session_client.detect_intent(
            request={"session": session, "query_input": query_input}
        )

        print("=" * 20)
        print(f"Query text: {response.query_result.query_text}")
        print(
            f"Detected intent: {response.query_result.intent.display_name} (confidence: {response.query_result.intent_detection_confidence,})\n"
        )
        print(f"Fulfillment text: {response.query_result.fulfillment_text}\n")

其他语言

C#: 请按照客户端库页面上的 C# 设置说明操作,然后访问 .NET 版 Dialogflow 参考文档

PHP: 请按照客户端库页面上的 PHP 设置说明操作,然后访问 PHP 版 Dialogflow 参考文档

Ruby 版: 请按照客户端库页面上的 Ruby 设置说明操作,然后访问 Ruby 版 Dialogflow 参考文档

Cloud Logging

如需控制存储日志的区域,请参阅 Cloud Logging 指南

限制

在 Dialogflow 控制台中选择非默认区域时,以下功能不可用:

许多 REST 参考文档中的 API Explorer 仅支持 global 区域进行 API 调用。