Search in sources :

Example 1 with AIResponse

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

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

the class ResolveAPIAI method unpack.

public void unpack(@NonNull final String gsonResponse) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "unpacking");
    }
    final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
    final AIResponse response = gson.fromJson(gsonResponse, new TypeToken<AIResponse>() {
    }.getType());
    nluAPIAI = new NLUAPIAI(confidenceArray, resultsArray, response.getResult().getMetadata().getIntentName(), response.getResult().getParameters());
    new NLUCoerce(getNLUAPIAI(), getContext(), getSupportedLanguage(), getVRLocale(), getTTSLocale(), getConfidenceArray(), getResultsArray()).coerce();
}
Also used : AIResponse(ai.api.model.AIResponse) GsonBuilder(com.google.gson.GsonBuilder) TypeToken(com.google.gson.reflect.TypeToken) NLUCoerce(ai.saiy.android.nlu.NLUCoerce) Gson(com.google.gson.Gson)

Example 3 with AIResponse

use of ai.api.model.AIResponse 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 4 with AIResponse

use of ai.api.model.AIResponse 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 5 with AIResponse

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

AIResponse (ai.api.model.AIResponse)6 AIRequest (ai.api.model.AIRequest)5 AIServiceException (ai.api.AIServiceException)4 GsonBuilder (com.google.gson.GsonBuilder)2 AIConfiguration (ai.api.AIConfiguration)1 AIDataService (ai.api.AIDataService)1 AIEvent (ai.api.model.AIEvent)1 NLUCoerce (ai.saiy.android.nlu.NLUCoerce)1 Pair (android.util.Pair)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)1