Search in sources :

Example 1 with AIRequest

use of ai.api.model.AIRequest in project Saiy-PS by brandall76.

the class RemoteAPIAI method fetch.

public Pair<Boolean, String> fetch() {
    final AIRequest aiRequest = new AIRequest();
    aiRequest.setQuery(utterance);
    try {
        final AIResponse response = aiDataService.request(aiRequest);
        if (response != null) {
            final String gsonString = new GsonBuilder().disableHtmlEscaping().create().toJson(response);
            if (DEBUG) {
                MyLog.i(CLS_NAME, "gsonString: " + response.toString());
            }
            return new Pair<>(true, gsonString);
        } else {
            if (DEBUG) {
                MyLog.w(CLS_NAME, "response null");
            }
        }
    } catch (final AIServiceException e) {
        if (DEBUG) {
            MyLog.e(CLS_NAME, "AIResponse AIServiceException");
            e.printStackTrace();
        }
    }
    return new Pair<>(false, null);
}
Also used : AIResponse(ai.api.model.AIResponse) GsonBuilder(com.google.gson.GsonBuilder) AIRequest(ai.api.model.AIRequest) AIServiceException(ai.api.AIServiceException) Pair(android.util.Pair)

Example 2 with AIRequest

use of ai.api.model.AIRequest in project VKBot by EugeneTheDev.

the class Bot method aiAnswer.

/**
 * @param input user says
 * @return artificial intelligence answer
 */
public String aiAnswer(String input) {
    String result = "";
    try {
        AIRequest request = new AIRequest(input);
        AIResponse response = dataService.request(request);
        if (response.getStatus().getCode() == 200)
            result = response.getResult().getFulfillment().getSpeech();
    } catch (AIServiceException e) {
        logger.info("AI Service Exception when ai answering.");
    } finally {
        return result;
    }
}
Also used : AIResponse(ai.api.model.AIResponse) AIRequest(ai.api.model.AIRequest) AIServiceException(ai.api.AIServiceException)

Example 3 with AIRequest

use of ai.api.model.AIRequest in project dobby-android by InceptAi.

the class ApiAiClient method sendTextQuery.

public void sendTextQuery(@Nullable final String query, @Nullable final String event, final ResultListener listener) {
    Preconditions.checkState(query != null || event != null);
    threadpool.submit(new Runnable() {

        @Override
        public void run() {
            final AIRequest aiRequest = new AIRequest();
            if (query != null) {
                aiRequest.setQuery(query);
            }
            if (event != null) {
                aiRequest.setEvent(new AIEvent(event));
            }
            try {
                DobbyLog.i("Submitting query: " + query);
                final AIResponse response = aiDataService.request(aiRequest);
                DobbyLog.i(" Response:" + GsonFactory.getGson().toJson(response.toString()));
                processResult(response.getResult(), listener);
            } catch (AIServiceException exception) {
                DobbyLog.e("Api.ai Exception: " + exception);
            }
        }
    });
}
Also used : AIResponse(ai.api.model.AIResponse) AIEvent(ai.api.model.AIEvent) AIRequest(ai.api.model.AIRequest) AIServiceException(ai.api.AIServiceException)

Example 4 with AIRequest

use of ai.api.model.AIRequest in project VKBot by EugeneProto.

the class MessageReplier method aiAnswer.

private String aiAnswer(String input) {
    String result = "";
    try {
        AIRequest request = new AIRequest(input);
        AIResponse response = bot.getDataService().request(request);
        if (response.getStatus().getCode() == 200)
            result = response.getResult().getFulfillment().getSpeech();
    } catch (AIServiceException e) {
        logger.info("AI Service Exception when ai answering");
    } finally {
        return result;
    }
}
Also used : AIResponse(ai.api.model.AIResponse) AIRequest(ai.api.model.AIRequest) AIServiceException(ai.api.AIServiceException)

Example 5 with AIRequest

use of ai.api.model.AIRequest in project Gary by help-chat.

the class AI method execute.

@Override
protected void execute(MessageReceivedEvent e, String[] args) {
    MessageChannel channel = e.getChannel();
    if (channel.getIdLong() == 339674158596358145L) {
        AIConfiguration config = new AIConfiguration(this.config.getItem("config", "aitoken"));
        AIDataService data = new AIDataService(config);
        try {
            AIRequest request = new AIRequest(e.getMessage().getContentRaw().replace("!", ""));
            request.setSessionId(e.getAuthor().getId());
            AIResponse response = data.request(request);
            if (response.getStatus().getCode() == 200) {
                if (e.getMessage().getContentRaw().startsWith("!say ")) {
                    channel.sendMessage(mutil.format(e, e.getMessage().getContentRaw().replace("!say ", ""))).queue();
                } else {
                    channel.sendMessage(mutil.format(e, response.getResult().getFulfillment().getSpeech())).queue();
                }
            } else {
                System.out.println(response.getStatus().getErrorDetails());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : AIDataService(ai.api.AIDataService) AIResponse(ai.api.model.AIResponse) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) AIConfiguration(ai.api.AIConfiguration) AIRequest(ai.api.model.AIRequest)

Aggregations

AIRequest (ai.api.model.AIRequest)5 AIResponse (ai.api.model.AIResponse)5 AIServiceException (ai.api.AIServiceException)4 AIConfiguration (ai.api.AIConfiguration)1 AIDataService (ai.api.AIDataService)1 AIEvent (ai.api.model.AIEvent)1 Pair (android.util.Pair)1 GsonBuilder (com.google.gson.GsonBuilder)1 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)1