Search in sources :

Example 26 with Workspace

use of com.ibm.watson.assistant.v1.model.Workspace in project java-sdk by watson-developer-cloud.

the class Assistant method createIntent.

/**
 * Create intent.
 *
 * <p>Create a new intent.
 *
 * <p>If you want to create multiple intents with a single API call, consider using the **[Update
 * workspace](#update-workspace)** method instead.
 *
 * @param createIntentOptions the {@link CreateIntentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Intent}
 */
public ServiceCall<Intent> createIntent(CreateIntentOptions createIntentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createIntentOptions, "createIntentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", createIntentOptions.workspaceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/intents", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "createIntent");
    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 (createIntentOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(createIntentOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("intent", createIntentOptions.intent());
    if (createIntentOptions.description() != null) {
        contentJson.addProperty("description", createIntentOptions.description());
    }
    if (createIntentOptions.examples() != null) {
        contentJson.add("examples", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createIntentOptions.examples()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Intent> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Intent>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Intent(com.ibm.watson.assistant.v1.model.Intent)

Example 27 with Workspace

use of com.ibm.watson.assistant.v1.model.Workspace in project java-sdk by watson-developer-cloud.

the class Assistant method bulkClassify.

/**
 * Identify intents and entities in multiple user utterances.
 *
 * <p>Send multiple user inputs to a workspace in a single request and receive information about
 * the intents and entities recognized in each input. This method is useful for testing and
 * comparing the performance of different workspaces.
 *
 * <p>This method is available only with Enterprise with Data Isolation plans.
 *
 * @param bulkClassifyOptions the {@link BulkClassifyOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link BulkClassifyResponse}
 */
public ServiceCall<BulkClassifyResponse> bulkClassify(BulkClassifyOptions bulkClassifyOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(bulkClassifyOptions, "bulkClassifyOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", bulkClassifyOptions.workspaceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/bulk_classify", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "bulkClassify");
    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 (bulkClassifyOptions.input() != null) {
        contentJson.add("input", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(bulkClassifyOptions.input()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<BulkClassifyResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<BulkClassifyResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) BulkClassifyResponse(com.ibm.watson.assistant.v1.model.BulkClassifyResponse)

Example 28 with Workspace

use of com.ibm.watson.assistant.v1.model.Workspace in project java-sdk by watson-developer-cloud.

the class Assistant method listEntities.

/**
 * List entities.
 *
 * <p>List the entities for a workspace.
 *
 * @param listEntitiesOptions the {@link ListEntitiesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link EntityCollection}
 */
public ServiceCall<EntityCollection> listEntities(ListEntitiesOptions listEntitiesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listEntitiesOptions, "listEntitiesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", listEntitiesOptions.workspaceId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "listEntities");
    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 (listEntitiesOptions.export() != null) {
        builder.query("export", String.valueOf(listEntitiesOptions.export()));
    }
    if (listEntitiesOptions.pageLimit() != null) {
        builder.query("page_limit", String.valueOf(listEntitiesOptions.pageLimit()));
    }
    if (listEntitiesOptions.includeCount() != null) {
        builder.query("include_count", String.valueOf(listEntitiesOptions.includeCount()));
    }
    if (listEntitiesOptions.sort() != null) {
        builder.query("sort", String.valueOf(listEntitiesOptions.sort()));
    }
    if (listEntitiesOptions.cursor() != null) {
        builder.query("cursor", String.valueOf(listEntitiesOptions.cursor()));
    }
    if (listEntitiesOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(listEntitiesOptions.includeAudit()));
    }
    ResponseConverter<EntityCollection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<EntityCollection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) EntityCollection(com.ibm.watson.assistant.v1.model.EntityCollection)

Example 29 with Workspace

use of com.ibm.watson.assistant.v1.model.Workspace in project java-sdk by watson-developer-cloud.

the class Assistant method updateIntent.

/**
 * Update intent.
 *
 * <p>Update an existing intent with new or modified data. You must provide component objects
 * defining the content of the updated intent.
 *
 * <p>If you want to update multiple intents with a single API call, consider using the **[Update
 * workspace](#update-workspace)** method instead.
 *
 * @param updateIntentOptions the {@link UpdateIntentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Intent}
 */
public ServiceCall<Intent> updateIntent(UpdateIntentOptions updateIntentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateIntentOptions, "updateIntentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateIntentOptions.workspaceId());
    pathParamsMap.put("intent", updateIntentOptions.intent());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/intents/{intent}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateIntent");
    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 (updateIntentOptions.append() != null) {
        builder.query("append", String.valueOf(updateIntentOptions.append()));
    }
    if (updateIntentOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateIntentOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateIntentOptions.newIntent() != null) {
        contentJson.addProperty("intent", updateIntentOptions.newIntent());
    }
    if (updateIntentOptions.newDescription() != null) {
        contentJson.addProperty("description", updateIntentOptions.newDescription());
    }
    if (updateIntentOptions.newExamples() != null) {
        contentJson.add("examples", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateIntentOptions.newExamples()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Intent> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Intent>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Intent(com.ibm.watson.assistant.v1.model.Intent)

Example 30 with Workspace

use of com.ibm.watson.assistant.v1.model.Workspace in project java-sdk by watson-developer-cloud.

the class Assistant method message.

/**
 * Get response to user input.
 *
 * <p>Send user input to a workspace and receive a response.
 *
 * <p>**Important:** This method has been superseded by the new v2 runtime API. The v2 API offers
 * significant advantages, including ease of deployment, automatic state management, versioning,
 * and search capabilities. For more information, see the
 * [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-api-overview).
 *
 * @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("workspace_id", messageOptions.workspaceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/message", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "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));
    if (messageOptions.nodesVisitedDetails() != null) {
        builder.query("nodes_visited_details", String.valueOf(messageOptions.nodesVisitedDetails()));
    }
    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.intents() != null) {
        contentJson.add("intents", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.intents()));
    }
    if (messageOptions.entities() != null) {
        contentJson.add("entities", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.entities()));
    }
    if (messageOptions.alternateIntents() != null) {
        contentJson.addProperty("alternate_intents", messageOptions.alternateIntents());
    }
    if (messageOptions.context() != null) {
        contentJson.add("context", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.context()));
    }
    if (messageOptions.output() != null) {
        contentJson.add("output", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.output()));
    }
    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.v1.model.MessageResponse) JsonObject(com.google.gson.JsonObject)

Aggregations

HashMap (java.util.HashMap)21 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)18 JsonObject (com.google.gson.JsonObject)15 Test (org.junit.Test)8 Workspace (com.ibm.watson.assistant.v1.model.Workspace)6 Workspace (com.ibm.watson.developer_cloud.assistant.v1.model.Workspace)6 Workspace (com.ibm.watson.developer_cloud.conversation.v1.model.Workspace)6 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)6 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)6 DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)5 Counterexample (com.ibm.watson.assistant.v1.model.Counterexample)3 CreateWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateWorkspaceOptions)3 DeleteWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteWorkspaceOptions)3 CreateWorkspaceOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateWorkspaceOptions)3 DeleteWorkspaceOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteWorkspaceOptions)3 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 CreateEntity (com.ibm.watson.assistant.v1.model.CreateEntity)2 CreateIntent (com.ibm.watson.assistant.v1.model.CreateIntent)2