Skip to content

Commit

Permalink
feat(assistant-v1): update models and add new methods
Browse files Browse the repository at this point in the history
NEW methods: createWorkspaceAsync, updateWorkspaceAsync, exportWorkspaceAsync
  • Loading branch information
kevinkowa committed Aug 9, 2022
1 parent ea6cc46 commit 2b8a2fc
Show file tree
Hide file tree
Showing 9 changed files with 619 additions and 17 deletions.
366 changes: 364 additions & 2 deletions src/IBM.Watson.Assistant.v1/AssistantService.cs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/IBM.Watson.Assistant.v1/IAssistantService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2018, 2021.
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,9 @@ public partial interface IAssistantService
DetailedResponse<Workspace> GetWorkspace(string workspaceId, bool? export = null, bool? includeAudit = null, string sort = null);
DetailedResponse<Workspace> UpdateWorkspace(string workspaceId, string name = null, string description = null, string language = null, List<DialogNode> dialogNodes = null, List<Counterexample> counterexamples = null, Dictionary<string, object> metadata = null, bool? learningOptOut = null, WorkspaceSystemSettings systemSettings = null, List<Webhook> webhooks = null, List<CreateIntent> intents = null, List<CreateEntity> entities = null, bool? append = null, bool? includeAudit = null);
DetailedResponse<object> DeleteWorkspace(string workspaceId);
DetailedResponse<Workspace> CreateWorkspaceAsync(string name = null, string description = null, string language = null, List<DialogNode> dialogNodes = null, List<Counterexample> counterexamples = null, Dictionary<string, object> metadata = null, bool? learningOptOut = null, WorkspaceSystemSettings systemSettings = null, List<Webhook> webhooks = null, List<CreateIntent> intents = null, List<CreateEntity> entities = null);
DetailedResponse<Workspace> UpdateWorkspaceAsync(string workspaceId, string name = null, string description = null, string language = null, List<DialogNode> dialogNodes = null, List<Counterexample> counterexamples = null, Dictionary<string, object> metadata = null, bool? learningOptOut = null, WorkspaceSystemSettings systemSettings = null, List<Webhook> webhooks = null, List<CreateIntent> intents = null, List<CreateEntity> entities = null, bool? append = null);
DetailedResponse<Workspace> ExportWorkspaceAsync(string workspaceId, bool? includeAudit = null, string sort = null, bool? verbose = null);
DetailedResponse<IntentCollection> ListIntents(string workspaceId, bool? export = null, long? pageLimit = null, bool? includeCount = null, string sort = null, string cursor = null, bool? includeAudit = null);
DetailedResponse<Intent> CreateIntent(string workspaceId, string intent, string description = null, List<Example> examples = null, bool? includeAudit = null);
DetailedResponse<Intent> GetIntent(string workspaceId, string intent, bool? export = null, bool? includeAudit = null);
Expand Down
5 changes: 3 additions & 2 deletions src/IBM.Watson.Assistant.v1/Model/RuntimeIntent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2018, 2019.
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,8 @@ public class RuntimeIntent
[JsonProperty("intent", NullValueHandling = NullValueHandling.Ignore)]
public string Intent { get; set; }
/// <summary>
/// A decimal percentage that represents Watson's confidence in the intent.
/// A decimal percentage that represents Watson's confidence in the intent. If you are specifying an intent as
/// part of a request, but you do not have a calculated confidence value, specify `1`.
/// </summary>
[JsonProperty("confidence", NullValueHandling = NullValueHandling.Ignore)]
public double? Confidence { get; set; }
Expand Down
34 changes: 34 additions & 0 deletions src/IBM.Watson.Assistant.v1/Model/StatusError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using Newtonsoft.Json;

namespace IBM.Watson.Assistant.v1.Model
{
/// <summary>
/// An object describing an error that occurred during processing of an asynchronous operation.
/// </summary>
public class StatusError
{
/// <summary>
/// The text of the error message.
/// </summary>
[JsonProperty("message", NullValueHandling = NullValueHandling.Ignore)]
public string Message { get; set; }
}

}
52 changes: 41 additions & 11 deletions src/IBM.Watson.Assistant.v1/Model/Workspace.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2018, 2020.
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,26 +27,37 @@ namespace IBM.Watson.Assistant.v1.Model
public class Workspace
{
/// <summary>
/// The current status of the workspace.
/// The current status of the workspace:
/// - **Available**: The workspace is available and ready to process messages.
/// - **Failed**: An asynchronous operation has failed. See the **status_errors** property for more information
/// about the cause of the failure. Returned only by the **Export workspace asynchronously** method.
/// - **Non Existent**: The workspace does not exist.
/// - **Processing**: An asynchronous operation has not yet completed. Returned only by the **Export workspace
/// asynchronously** method.
/// - **Training**: The workspace is training based on new data such as intents or examples.
/// </summary>
public class StatusEnumValue
{
/// <summary>
/// Constant NON_EXISTENT for Non Existent
/// </summary>
public const string NON_EXISTENT = "Non Existent";
/// <summary>
/// Constant TRAINING for Training
/// Constant AVAILABLE for Available
/// </summary>
public const string TRAINING = "Training";
public const string AVAILABLE = "Available";
/// <summary>
/// Constant FAILED for Failed
/// </summary>
public const string FAILED = "Failed";
/// <summary>
/// Constant AVAILABLE for Available
/// Constant NON_EXISTENT for Non Existent
/// </summary>
public const string AVAILABLE = "Available";
public const string NON_EXISTENT = "Non Existent";
/// <summary>
/// Constant PROCESSING for Processing
/// </summary>
public const string PROCESSING = "Processing";
/// <summary>
/// Constant TRAINING for Training
/// </summary>
public const string TRAINING = "Training";
/// <summary>
/// Constant UNAVAILABLE for Unavailable
/// </summary>
Expand All @@ -55,7 +66,14 @@ public class StatusEnumValue
}

/// <summary>
/// The current status of the workspace.
/// The current status of the workspace:
/// - **Available**: The workspace is available and ready to process messages.
/// - **Failed**: An asynchronous operation has failed. See the **status_errors** property for more information
/// about the cause of the failure. Returned only by the **Export workspace asynchronously** method.
/// - **Non Existent**: The workspace does not exist.
/// - **Processing**: An asynchronous operation has not yet completed. Returned only by the **Export workspace
/// asynchronously** method.
/// - **Training**: The workspace is training based on new data such as intents or examples.
/// Constants for possible values can be found using Workspace.StatusEnumValue
/// </summary>
[JsonProperty("status", NullValueHandling = NullValueHandling.Ignore)]
Expand Down Expand Up @@ -117,6 +135,11 @@ public class StatusEnumValue
[JsonProperty("system_settings", NullValueHandling = NullValueHandling.Ignore)]
public WorkspaceSystemSettings SystemSettings { get; set; }
/// <summary>
/// An array of messages about errors that caused an asynchronous operation to fail.
/// </summary>
[JsonProperty("status_errors", NullValueHandling = NullValueHandling.Ignore)]
public virtual List<StatusError> StatusErrors { get; private set; }
/// <summary>
/// Gets or Sets Webhooks
/// </summary>
[JsonProperty("webhooks", NullValueHandling = NullValueHandling.Ignore)]
Expand All @@ -131,6 +154,13 @@ public class StatusEnumValue
/// </summary>
[JsonProperty("entities", NullValueHandling = NullValueHandling.Ignore)]
public List<Entity> Entities { get; set; }
/// <summary>
/// An object containing properties that indicate how many intents, entities, and dialog nodes are defined in
/// the workspace. This property is included only in responses from the **Export workspace asynchronously**
/// method, and only when the **verbose** query parameter is set to `true`.
/// </summary>
[JsonProperty("counts", NullValueHandling = NullValueHandling.Ignore)]
public WorkspaceCounts Counts { get; set; }
}

}
46 changes: 46 additions & 0 deletions src/IBM.Watson.Assistant.v1/Model/WorkspaceCounts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using Newtonsoft.Json;

namespace IBM.Watson.Assistant.v1.Model
{
/// <summary>
/// An object containing properties that indicate how many intents, entities, and dialog nodes are defined in the
/// workspace. This property is included only in responses from the **Export workspace asynchronously** method, and
/// only when the **verbose** query parameter is set to `true`.
/// </summary>
public class WorkspaceCounts
{
/// <summary>
/// The number of intents defined in the workspace.
/// </summary>
[JsonProperty("intent", NullValueHandling = NullValueHandling.Ignore)]
public long? Intent { get; set; }
/// <summary>
/// The number of entities defined in the workspace.
/// </summary>
[JsonProperty("entity", NullValueHandling = NullValueHandling.Ignore)]
public long? Entity { get; set; }
/// <summary>
/// The number of nodes defined in the workspace.
/// </summary>
[JsonProperty("node", NullValueHandling = NullValueHandling.Ignore)]
public long? Node { get; set; }
}

}
7 changes: 6 additions & 1 deletion src/IBM.Watson.Assistant.v1/Model/WorkspaceSystemSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2018, 2022.
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -64,6 +64,11 @@ public class WorkspaceSystemSettings : DynamicModel<object>
/// </summary>
[JsonProperty("off_topic", NullValueHandling = NullValueHandling.Ignore)]
public WorkspaceSystemSettingsOffTopic OffTopic { get; set; }
/// <summary>
/// Workspace settings related to the version of the training algorithms currently used by the skill.
/// </summary>
[JsonProperty("nlp", NullValueHandling = NullValueHandling.Ignore)]
public WorkspaceSystemSettingsNlp Nlp { get; set; }
}

}
57 changes: 57 additions & 0 deletions src/IBM.Watson.Assistant.v1/Model/WorkspaceSystemSettingsNlp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using Newtonsoft.Json;

namespace IBM.Watson.Assistant.v1.Model
{
/// <summary>
/// Workspace settings related to the version of the training algorithms currently used by the skill.
/// </summary>
public class WorkspaceSystemSettingsNlp
{
/// <summary>
/// The policy the skill follows for selecting the algorithm version to use:
///
/// - `baseline`: the latest mature version
/// - `beta`: the latest beta version.
/// </summary>
public class ModelEnumValue
{
/// <summary>
/// Constant BASELINE for baseline
/// </summary>
public const string BASELINE = "baseline";
/// <summary>
/// Constant BETA for beta
/// </summary>
public const string BETA = "beta";

}

/// <summary>
/// The policy the skill follows for selecting the algorithm version to use:
///
/// - `baseline`: the latest mature version
/// - `beta`: the latest beta version.
/// Constants for possible values can be found using WorkspaceSystemSettingsNlp.ModelEnumValue
/// </summary>
[JsonProperty("model", NullValueHandling = NullValueHandling.Ignore)]
public string Model { get; set; }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
using System.Collections.Generic;
using IBM.Cloud.SDK.Core.Util;
using IBM.Cloud.SDK.Core.Authentication.Iam;
using System.Threading;
using IBM.Cloud.SDK.Core.Http;

namespace IBM.Watson.Assistant.v1.IntegrationTests
{
Expand Down Expand Up @@ -1104,6 +1106,68 @@ public void TestRuntimeResponseGeneric()
Assert.IsTrue(response.Result.Output.Generic[0].ResponseType.Contains(inputMessage));
}
}

[TestMethod]
public void TestWorkspaceAsync()
{
service.WithHeader("X-Watson-Test", "1");
var createWorkspaceAsyncResult = service.CreateWorkspaceAsync(
name: createdWorkspaceName,
description: createdWorkspaceDescription,
language: createdWorkspaceLanguage
);
var workspaceId = createWorkspaceAsyncResult.Result.WorkspaceId;

DetailedResponse<Workspace> getWorkspaceResult = null;
var workspaceStatus = createWorkspaceAsyncResult.Result.Status;
while (workspaceStatus == Workspace.StatusEnumValue.PROCESSING)
{
Thread.Sleep(10000);
getWorkspaceResult = service.GetWorkspace(
workspaceId: workspaceId
);
workspaceStatus = getWorkspaceResult.Result.Status;
}

Assert.IsTrue(workspaceStatus == Workspace.StatusEnumValue.AVAILABLE);

var updateWorkspaceAsyncResult = service.UpdateWorkspaceAsync(
workspaceId: workspaceId,
name: createdWorkspaceName,
description: createdWorkspaceDescription + "-updated",
language: createdWorkspaceLanguage,
learningOptOut: true
);

workspaceStatus = Workspace.StatusEnumValue.PROCESSING;
while (workspaceStatus == Workspace.StatusEnumValue.PROCESSING)
{
Thread.Sleep(10000);
getWorkspaceResult = service.GetWorkspace(
workspaceId: workspaceId
);
workspaceStatus = getWorkspaceResult.Result.Status;
}
Assert.IsTrue(workspaceStatus == Workspace.StatusEnumValue.AVAILABLE);
Assert.IsTrue(getWorkspaceResult.Result.Description == createdWorkspaceDescription + "-updated");

var exportWorkspaceAsyncResult = service.ExportWorkspaceAsync(
workspaceId: workspaceId
);
workspaceStatus = Workspace.StatusEnumValue.PROCESSING;

while(workspaceStatus == Workspace.StatusEnumValue.PROCESSING)
{
Thread.Sleep(10000);
exportWorkspaceAsyncResult = service.ExportWorkspaceAsync(
workspaceId: workspaceId
);
workspaceStatus = getWorkspaceResult.Result.Status;
}

Assert.IsTrue(workspaceStatus == Workspace.StatusEnumValue.AVAILABLE);
Assert.IsTrue(exportWorkspaceAsyncResult.Result.Description == createdWorkspaceDescription + "-updated");
}
#endregion
}
}

0 comments on commit 2b8a2fc

Please sign in to comment.