简体   繁体   English

Dialogflow v2 Java Client Library detectIntent with Spring Boot:找不到项目的 DesignTimeAgent

[英]Dialogflow v2 Java Client Library detectIntent with Spring Boot: No DesignTimeAgent found for project

While trying to detectIntent from text I have received a below exception (project-id was replaced).在尝试从文本中detectIntent时,我收到了以下异常(项目 ID 已被替换)。 Cannot find anything in google related to DesignTimeAgent issue.在谷歌中找不到与DesignTimeAgent问题相关的任何内容。 Any help is appreciated.任何帮助表示赞赏。

Exception:例外:

There was an unexpected error (type=Internal Server Error, status=500).
io.grpc.StatusRuntimeException: NOT_FOUND: com.google.apps.framework.request.NotFoundException: No DesignTimeAgent found for project 'MY_PROJECT_ID'.
com.google.api.gax.rpc.NotFoundException: io.grpc.StatusRuntimeException: NOT_FOUND: com.google.apps.framework.request.NotFoundException: No DesignTimeAgent found for project 'MY_PROJECT_ID'.
    at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:45)
    at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)
    at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)
    at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:95)
    at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:61)
    at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1015)
    at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30)
    at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1137)
    at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:957)
    at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:748)
    at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:493)
    at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:468)
    at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
    at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
    at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
    at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:684)
    ...
    Suppressed: com.google.api.gax.rpc.AsyncTaskException: Asynchronous task failed
        at com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:57)
        at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)
        at com.google.cloud.dialogflow.v2.SessionsClient.detectIntent(SessionsClient.java:245)
        at com.google.cloud.dialogflow.v2.SessionsClient.detectIntent(SessionsClient.java:184)
        at com.my.microservices.controllers.DialogFlowRestController.test(DialogFlowRestController.java:35)
        ...
Caused by: io.grpc.StatusRuntimeException: NOT_FOUND: com.google.apps.framework.request.NotFoundException: No DesignTimeAgent found for project 'MY_PROJECT_ID'.
    at io.grpc.Status.asRuntimeException(Status.java:533)
    ... 23 more

Rest controller to trigger detectIntent test (as https://localhost:8080/api/test ): Rest controller 触发detectIntent测试(如https://localhost:8080/api/test ):

package com.my.microservices.controllers;

import com.google.cloud.dialogflow.v2.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

@RestController
@RequestMapping("/api")
public class DialogFlowRestController {

    private static final Logger logger = LoggerFactory.getLogger(DialogFlowRestController.class);

    private String userText = "Weather forecast for today in Berlin";
    private final String LANG_CODE = "en-US";
    private final String PROJECT_ID = System.getenv().get("GOOGLE_CLOUD_PROJECT");
    private String sessionId = UUID.randomUUID().toString();

    @GetMapping(value = "/test", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String test() throws Exception { 
        logger.info("test was called");

        try (SessionsClient sessionsClient = SessionsClient.create()) {
            SessionName session = SessionName.of(PROJECT_ID, sessionId);

            TextInput.Builder textInput = TextInput.newBuilder().setText(userText).setLanguageCode(LANG_CODE);

            QueryInput queryInput = QueryInput.newBuilder().setText(textInput).build();

            DetectIntentResponse response = sessionsClient.detectIntent(session, queryInput);
            return response.toString();
        }
    }
}

Provided environment variables:提供的环境变量:

GOOGLE_CLOUD_PROJECT=MY_PROJECT_ID
GOOGLE_APPLICATION_CREDENTIALS=/Users/me/.my/pk.json

Spring-Boot pom.xml : Spring-Boot pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.my.microservices</groupId>
    <artifactId>dialog-flow-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>dialog-flow-test</name>
    <description>Demo project with Dialog Flow</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Dialogflow API Client Library for Java -->
        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-dialogflow</artifactId>
            <version>v2-rev81-1.25.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-dialogflow</artifactId>
            <version>0.103.0-alpha</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

OK, I have figured it out. 好,我知道了。

The above misleading error message was caused by the use of a wrong PROJECT_ID. 上面的误导性错误消息是由使用错误的PROJECT_ID引起的。 My mistake was, that first I have created a new Project with a Service Account, gave to it dialogflow API rights and later I have tried to use its name and related PK JSON for my detectIntent calls. 我的错误是,首先我创建了一个带有服务帐户的新项目,并赋予了它dialogflow API权限,后来我尝试将其名称和相关的PK JSON用于我的detectIntent调用。 BUT it was not linked with Dialogflow Project ID. 但是它没有与Dialogflow项目ID链接。

So, to fix it I have started with a default Project ID, which was given to my new Dialogflow Agent and following instruction https://dialogflow.com/docs/reference/v2-auth-setup I have created a new Project with a Service Account which fit my Dialogflow Agent. 因此,要解决此问题,我从默认的项目ID开始,该ID已分配给我的新Dialogflow代理,并按照以下说明https://dialogflow.com/docs/reference/v2-auth-setup创建了一个新项目,其中包含一个适合我的Dialogflow代理的服务帐户。

In my case I needed to move my Agent to Global serving from EU-W1就我而言,我需要将我的代理从 EU-W1 移至全球服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM