use of com.ibm.watson.assistant.v2.model.ListLogsOptions.Builder in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method testListLogs.
/**
* Test List Logs.
*/
// @Test
public void testListLogs() {
// list logs sorted by timestamp and that contain the text Hello
Builder builder = new ListLogsOptions.Builder();
builder.assistantId(assistantId);
builder.sort("request_timestamp");
builder.filter("request.input.text::\"Hello\"");
builder.pageLimit(5);
LogCollection logCollection = service.listLogs(builder.build()).execute().getResult();
assertNotNull(logCollection);
assertTrue(logCollection.getLogs().get(0).getRequest().input().text().contains("Hello"));
assertTrue(logCollection.getLogs().get(0).getLanguage().equals("en"));
}
use of com.ibm.watson.assistant.v2.model.ListLogsOptions.Builder in project java-sdk by watson-developer-cloud.
the class Assistant method message.
/**
* Send user input to assistant (stateful).
*
* <p>Send user input to an assistant and receive a response, with conversation state (including
* context data) stored by Watson Assistant for the duration of the session.
*
* @param messageOptions the {@link MessageOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link MessageResponse}
*/
public ServiceCall<MessageResponse> message(MessageOptions messageOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(messageOptions, "messageOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("assistant_id", messageOptions.assistantId());
pathParamsMap.put("session_id", messageOptions.sessionId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/assistants/{assistant_id}/sessions/{session_id}/message", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v2", "message");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
final JsonObject contentJson = new JsonObject();
if (messageOptions.input() != null) {
contentJson.add("input", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.input()));
}
if (messageOptions.context() != null) {
contentJson.add("context", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.context()));
}
if (messageOptions.userId() != null) {
contentJson.addProperty("user_id", messageOptions.userId());
}
builder.bodyJson(contentJson);
ResponseConverter<MessageResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<MessageResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.assistant.v2.model.ListLogsOptions.Builder in project java-sdk by watson-developer-cloud.
the class Assistant method listLogs.
/**
* List log events for an assistant.
*
* <p>List the events from the log of an assistant.
*
* <p>This method requires Manager access, and is available only with Enterprise plans.
*
* @param listLogsOptions the {@link ListLogsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link LogCollection}
*/
public ServiceCall<LogCollection> listLogs(ListLogsOptions listLogsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(listLogsOptions, "listLogsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("assistant_id", listLogsOptions.assistantId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/assistants/{assistant_id}/logs", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v2", "listLogs");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
if (listLogsOptions.sort() != null) {
builder.query("sort", String.valueOf(listLogsOptions.sort()));
}
if (listLogsOptions.filter() != null) {
builder.query("filter", String.valueOf(listLogsOptions.filter()));
}
if (listLogsOptions.pageLimit() != null) {
builder.query("page_limit", String.valueOf(listLogsOptions.pageLimit()));
}
if (listLogsOptions.cursor() != null) {
builder.query("cursor", String.valueOf(listLogsOptions.cursor()));
}
ResponseConverter<LogCollection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<LogCollection>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.assistant.v2.model.ListLogsOptions.Builder in project java-sdk by watson-developer-cloud.
the class Assistant method createSession.
/**
* Create a session.
*
* <p>Create a new session. A session is used to send user input to a skill and receive responses.
* It also maintains the state of the conversation. A session persists until it is deleted, or
* until it times out because of inactivity. (For more information, see the
* [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-assistant-settings).
*
* @param createSessionOptions the {@link CreateSessionOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link SessionResponse}
*/
public ServiceCall<SessionResponse> createSession(CreateSessionOptions createSessionOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createSessionOptions, "createSessionOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("assistant_id", createSessionOptions.assistantId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/assistants/{assistant_id}/sessions", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v2", "createSession");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
ResponseConverter<SessionResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SessionResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.assistant.v2.model.ListLogsOptions.Builder in project java-sdk by watson-developer-cloud.
the class Assistant method messageStateless.
/**
* Send user input to assistant (stateless).
*
* <p>Send user input to an assistant and receive a response, with conversation state (including
* context data) managed by your application.
*
* @param messageStatelessOptions the {@link MessageStatelessOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link MessageResponseStateless}
*/
public ServiceCall<MessageResponseStateless> messageStateless(MessageStatelessOptions messageStatelessOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(messageStatelessOptions, "messageStatelessOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("assistant_id", messageStatelessOptions.assistantId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/assistants/{assistant_id}/message", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v2", "messageStateless");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
final JsonObject contentJson = new JsonObject();
if (messageStatelessOptions.input() != null) {
contentJson.add("input", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageStatelessOptions.input()));
}
if (messageStatelessOptions.context() != null) {
contentJson.add("context", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageStatelessOptions.context()));
}
if (messageStatelessOptions.userId() != null) {
contentJson.addProperty("user_id", messageStatelessOptions.userId());
}
builder.bodyJson(contentJson);
ResponseConverter<MessageResponseStateless> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<MessageResponseStateless>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations