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