Saat mencoba detectIntent dari teks, saya menerima pengecualian di bawah ini (project-id diganti). Tidak dapat menemukan apa pun di google yang terkait dengan masalah DesignTimeAgent. Bantuan apa pun dihargai.

Pengecualian:

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

Istirahatkan pengontrol untuk memicu pengujian detectIntent (sebagai 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();
        }
    }
}

Variabel lingkungan yang disediakan:

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

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>
2
vaa 5 Agustus 2019, 16:41

1 menjawab

Jawaban Terbaik

Oke, saya sudah memikirkannya.

Pesan kesalahan menyesatkan di atas disebabkan oleh penggunaan PROJECT_ID yang salah. Kesalahan saya adalah, pertama saya telah membuat Proyek baru dengan Akun Layanan, memberikannya hak API dialogflow dan kemudian saya mencoba menggunakan namanya dan PK JSON terkait untuk panggilan detectIntent saya. TAPI itu tidak ditautkan dengan ID Proyek Dialogflow.

Jadi, untuk memperbaikinya, saya telah memulai dengan ID Proyek default, yang diberikan kepada Agen Dialogflow baru saya dan mengikuti instruksi https://dialogflow.com/docs/reference/v2-auth-setup Saya telah membuat Proyek baru dengan Akun Layanan yang sesuai dengan Agen Dialogflow saya.

2
vaa 6 Agustus 2019, 15:18