【问题标题】:Is it possible to create chat bot model passing intents , dialog from java using an API to AZURE bot service是否可以使用 API 到 AZURE bot 服务创建聊天机器人模型传递意图、对话
【发布时间】:2019-12-27 14:10:38
【问题描述】:
  1. 以下代码用于创建意图并将其传递给 google。
  2. 我想使用 java + azure bot 平台实现同样的目标
  3. 我想要一个框架,让用户能够将意图传递给 azure 上的聊天模型。
  4. 该框架将在 java 中创建。
  5. 目前我正在研究 POC,其中我将按照以下代码将意图传递给 azure。
  6. 我想如果可能的话,是否有任何与 google 或 amazon 相同的 api 在 azure 中。
import com.google.api.gax.paging.Page;
import com.google.auth.oauth2.ComputeEngineCredentials;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.dialogflow.v2.Intent;
import com.google.cloud.dialogflow.v2.Intent.Message;
import com.google.cloud.dialogflow.v2.Intent.Message.Text;
import com.google.cloud.dialogflow.v2.IntentsClient;
import com.google.cloud.dialogflow.v2.ProjectAgentName;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import com.google.common.collect.Lists;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class SankalpGCPChatBot {

    public static void main(String[] args) {

        List<String> trainingPhrasesParts = new ArrayList<>();
        List<String> messageTexts = new ArrayList<>();

        trainingPhrasesParts.add("What is your name?");
        messageTexts.add("My name is Sankalp Bot.");
        String displayName = "SankalpTestIntent";
        String projectId = "newagent-257c8";

        try {
            createIntent(displayName, projectId, trainingPhrasesParts, messageTexts);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void authCompute() {
        GoogleCredentials credentials = ComputeEngineCredentials.create();
        Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();

        System.out.println("Buckets:");
        Page<Bucket> buckets = storage.list();
        for (Bucket bucket : buckets.iterateAll()) {
            System.out.println(bucket.toString());
        }
    }

    static void authImplicit() {
        Storage storage = StorageOptions.getDefaultInstance().getService();

        System.out.println("Buckets:");
        Page<Bucket> buckets = storage.list();
        for (Bucket bucket : buckets.iterateAll()) {
            System.out.println(bucket.toString());
        }
    }

    static void authExplicit(String jsonPath) throws IOException {
        GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath))
                .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
        Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();

        System.out.println("Buckets:");
        Page<Bucket> buckets = storage.list();
        for (Bucket bucket : buckets.iterateAll()) {
            System.out.println(bucket.toString());
        }
    }

    public static Intent createIntent(
            String displayName,
            String projectId,
            List<String> trainingPhrasesParts,
            List<String> messageTexts) throws Exception {

        try (IntentsClient intentsClient = IntentsClient.create()) {
            ProjectAgentName parent = ProjectAgentName.of(projectId);

            List<Intent.TrainingPhrase> trainingPhrases = new ArrayList<>();
            for (String trainingPhrase : trainingPhrasesParts) {
                trainingPhrases.add(
                        Intent.TrainingPhrase.newBuilder().addParts(
                                Intent.TrainingPhrase.Part.newBuilder().setText(trainingPhrase).build())
                                .build());
            }

            Message message = Message.newBuilder()
                    .setText(
                            Text.newBuilder()
                                    .addAllText(messageTexts).build()
                    ).build();

            Intent intent = Intent.newBuilder()
                    .setDisplayName(displayName)
                    .addMessages(message)
                    .addAllTrainingPhrases(trainingPhrases)
                    .build();

            Intent response = intentsClient.createIntent(parent, intent);
            System.out.format("Intent created: %s\n", response);

            return response;
        }
    }
}

【问题讨论】:

  • 您是在问是否可以创建一个连接到 azure bot 服务的 google bot,还是在问是否可以使用 java 语言 /like/ google bot 创建一个 Microsoft Bot Framework bot。我有点困惑。
  • 我问我可以创建一个微型软机器人,我想在其中使用 java 语言创建我的意图、实体等
  • @user3675126 - JJ 的回答可以接受吗?

标签: java azure chatbot azure-language-understanding azure-bot-service


【解决方案1】:

截至本答案,Microsoft Bot Framework 的 Java 版本目前处于预览阶段(并且正在积极开发中)。您可以通过监控 Github 上的 Botbuilder-Java 存储库来跟踪更改。

该存储库还包含少量示例,但没有构建 (AFAIK) 来展示如何将 Java 机器人连接到语言理解服务,例如 LUIS。此外,请记住,由于它仍处于预览阶段,某些示例可能无法按预期运行。

【讨论】:

  • 我们可以使用 LUIS Programmatic APIs v2.0 实现上述目的吗?我想在 luis 应用程序中创建意图、话语等,我们可以使用它创建应用程序。
猜你喜欢
  • 2019-02-26
  • 2018-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多