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);
}
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();
}
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;
}
}
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);
}
}
});
}
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;
}
}
Aggregations