Search in sources :

Example 1 with Builder

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"));
}
Also used : Builder(com.ibm.watson.assistant.v2.model.ListLogsOptions.Builder)

Example 2 with Builder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) MessageResponse(com.ibm.watson.assistant.v2.model.MessageResponse) JsonObject(com.google.gson.JsonObject)

Example 3 with Builder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) LogCollection(com.ibm.watson.assistant.v2.model.LogCollection)

Example 4 with Builder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) SessionResponse(com.ibm.watson.assistant.v2.model.SessionResponse)

Example 5 with Builder

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);
}
Also used : MessageResponseStateless(com.ibm.watson.assistant.v2.model.MessageResponseStateless) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)5 HashMap (java.util.HashMap)5 JsonObject (com.google.gson.JsonObject)3 BulkClassifyResponse (com.ibm.watson.assistant.v2.model.BulkClassifyResponse)1 Builder (com.ibm.watson.assistant.v2.model.ListLogsOptions.Builder)1 LogCollection (com.ibm.watson.assistant.v2.model.LogCollection)1 MessageResponse (com.ibm.watson.assistant.v2.model.MessageResponse)1 MessageResponseStateless (com.ibm.watson.assistant.v2.model.MessageResponseStateless)1 SessionResponse (com.ibm.watson.assistant.v2.model.SessionResponse)1