Search in sources :

Example 1 with AIServiceException

use of ai.api.AIServiceException 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 AIServiceException

use of ai.api.AIServiceException 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 AIServiceException

use of ai.api.AIServiceException 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 AIServiceException

use of ai.api.AIServiceException 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)

Aggregations

AIServiceException (ai.api.AIServiceException)4 AIRequest (ai.api.model.AIRequest)4 AIResponse (ai.api.model.AIResponse)4 AIEvent (ai.api.model.AIEvent)1 Pair (android.util.Pair)1 GsonBuilder (com.google.gson.GsonBuilder)1