gpt4 book ai didi

java - 是否可以使用 API 创建聊天机器人模型,将意图、对话从 Java 传递到 AZURE 机器人服务

转载 作者:行者123 更新时间:2023-12-01 19:08:46 24 4
gpt4 key购买 nike

  1. 下面的代码用于创建意图并将其传递给 Google。
  2. 我想使用 java + azure bot 平台实现相同的目标
  3. 我想要一个框架,让用户能够将意图传递给 Azure 上存在的聊天模型。
  4. 该框架将用 java 创建。
  5. 目前我正在研究 POC,其中我会将如下代码的意图传递给 azure。
  6. 如果可能的话,我想知道 azure 中是否也有与 google 或 amazon 相同的 api。
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;
}
}
}

最佳答案

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

该存储库还包含少量示例,但是(据我所知)尚未构建任何示例来展示如何将 Java 机器人连接到 LUIS 等语言理解服务。另外,请记住,由于它仍处于预览阶段,某些示例可能不会按预期运行。

关于java - 是否可以使用 API 创建聊天机器人模型,将意图、对话从 Java 传递到 AZURE 机器人服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59501953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com