リージョン指定とデータ所在地

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 URL パス パラメータを指定します。
  • リージョン固有のホスト名の形式 REGION_ID-dialogflow.googleapis.com を使用します。例: asia-northeast1-dialogflow.googleapis.com ホスト名で指定されたリージョンが URL パスで指定されたリージョンと一致しない場合、リクエストは拒否されます。

クライアント ライブラリについては、クライアント ライブラリのドキュメントをご覧ください。次の操作を行う必要があります。

  • 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 メソッドと URL:

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 のロギング

ログを保存するリージョンを指定する場合は、Cloud ロギングガイドをご覧ください。

制限事項

Dialogflow コンソールでデフォルト以外のリージョンが選択されている場合、次の機能は使用できません。

多くの REST リファレンス ドキュメントにある APIs Explorer は、API 呼び出しの global リージョンのみをサポートしています。