Skip to content

Feat/dynamic model #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions Examples/GenericSerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,8 @@ void Start()
LogSystem.InstallDefaultReactors();

MessageResponse messageResponse = JsonConvert.DeserializeObject<MessageResponse>(responseJson);
//Dictionary<string, object> e = Json.Deserialize(responseJson) as Dictionary<string, object>;
//Dictionary<string, object> context = e["context"] as Dictionary<string, object>;
//Dictionary<string, object> skills = context["skills"] as Dictionary<string, object>;
//Dictionary<string, object> main_skill = skills["main skill"] as Dictionary<string, object>;
//Dictionary<string, object> user_defined = main_skill["user_defined"] as Dictionary<string, object>;

//string name = user_defined["name"] as string;

//var user_defined = messageResponse.Context.Skills["main skill"]["user_defined"].ToString();
//var uDefinedObject = JsonConvert.DeserializeObject<Dictionary<string, object>>(user_defined);

//Log.Debug("GenericSerialization", "main skill: {0}", uDefinedObject["name"]);
//Log.Debug("GenericSerialization", "test: {0}", messageResponse);

var name = messageResponse.Context.Skills["main skill"]["user_defined"]["name"].ToString();
var name = messageResponse.Context.Skills.Get("main skill").UserDefined["name"].ToString();
Log.Debug("GenericSerialization", "name: {0}", name);

}
Expand Down
103 changes: 52 additions & 51 deletions Scripts/Services/Assistant/V1/AssistantService.cs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Scripts/Services/Assistant/V1/Model/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*
*/

using IBM.Cloud.SDK.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace IBM.Watson.Assistant.V1.Model
{
/// <summary>
/// State information for the conversation. To maintain state, include the context from the previous response.
/// </summary>
public class Context
public class Context: DynamicModel<object>
{
/// <summary>
/// The unique identifier of the conversation.
Expand All @@ -34,7 +34,7 @@ public class Context
/// For internal use only.
/// </summary>
[JsonProperty("system", NullValueHandling = NullValueHandling.Ignore)]
public JObject System { get; set; }
public SystemResponse System { get; set; }
/// <summary>
/// Metadata related to the message.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions Scripts/Services/Assistant/V1/Model/DialogNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;

namespace IBM.Watson.Assistant.V1.Model
Expand Down Expand Up @@ -226,7 +225,7 @@ public class DigressOutSlotsValue
/// [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-dialog-overview#dialog-overview-responses).
/// </summary>
[JsonProperty("output", NullValueHandling = NullValueHandling.Ignore)]
public JObject Output { get; set; }
public DialogNodeOutput Output { get; set; }
/// <summary>
/// The context for the dialog node.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Scripts/Services/Assistant/V1/Model/DialogNodeOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

using System.Collections.Generic;
using IBM.Cloud.SDK.Model;
using Newtonsoft.Json;

namespace IBM.Watson.Assistant.V1.Model
Expand All @@ -24,7 +25,7 @@ namespace IBM.Watson.Assistant.V1.Model
/// The output of the dialog node. For more information about how to specify dialog node output, see the
/// [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-dialog-overview#dialog-overview-responses).
/// </summary>
public class DialogNodeOutput
public class DialogNodeOutput: DynamicModel<object>
{
/// <summary>
/// An array of objects describing the output defined for the dialog node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace IBM.Watson.Assistant.V1.Model
{
Expand All @@ -31,22 +30,22 @@ public class DialogNodeOutputOptionsElementValue
/// An input object that includes the input text.
/// </summary>
[JsonProperty("input", NullValueHandling = NullValueHandling.Ignore)]
public JObject Input { get; set; }
public MessageInput Input { get; set; }
/// <summary>
/// An array of intents to be used while processing the input.
///
/// **Note:** This property is supported for backward compatibility with applications that use the v1 **Get
/// response to user input** method.
/// </summary>
[JsonProperty("intents", NullValueHandling = NullValueHandling.Ignore)]
public List<JObject> Intents { get; set; }
public List<RuntimeIntent> Intents { get; set; }
/// <summary>
/// An array of entities to be used while processing the user input.
///
/// **Note:** This property is supported for backward compatibility with applications that use the v1 **Get
/// response to user input** method.
/// </summary>
[JsonProperty("entities", NullValueHandling = NullValueHandling.Ignore)]
public List<JObject> Entities { get; set; }
public List<RuntimeEntity> Entities { get; set; }
}
}
3 changes: 1 addition & 2 deletions Scripts/Services/Assistant/V1/Model/DialogSuggestion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace IBM.Watson.Assistant.V1.Model
{
Expand All @@ -42,7 +41,7 @@ public class DialogSuggestion
/// corresponding option.
/// </summary>
[JsonProperty("output", NullValueHandling = NullValueHandling.Ignore)]
public JObject Output { get; set; }
public DialogSuggestionOutput Output { get; set; }
/// <summary>
/// The ID of the dialog node that the **label** property is taken from. The **label** property is populated
/// using the value of the dialog node's **user_label** property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

using System.Collections.Generic;
using IBM.Cloud.SDK.Model;
using Newtonsoft.Json;

namespace IBM.Watson.Assistant.V1.Model
Expand All @@ -24,7 +25,7 @@ namespace IBM.Watson.Assistant.V1.Model
/// The dialog output that will be returned from the Watson Assistant service if the user selects the corresponding
/// option.
/// </summary>
public class DialogSuggestionOutput
public class DialogSuggestionOutput: DynamicModel<object>
{
/// <summary>
/// An array of the nodes that were triggered to create the response, in the order in which they were visited.
Expand Down
3 changes: 1 addition & 2 deletions Scripts/Services/Assistant/V1/Model/DialogSuggestionValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace IBM.Watson.Assistant.V1.Model
{
Expand All @@ -31,7 +30,7 @@ public class DialogSuggestionValue
/// An input object that includes the input text.
/// </summary>
[JsonProperty("input", NullValueHandling = NullValueHandling.Ignore)]
public JObject Input { get; set; }
public MessageInput Input { get; set; }
/// <summary>
/// An array of intents to be sent along with the user input.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Scripts/Services/Assistant/V1/Model/MessageInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*
*/

using IBM.Cloud.SDK.Model;
using Newtonsoft.Json;

namespace IBM.Watson.Assistant.V1.Model
{
/// <summary>
/// An input object that includes the input text.
/// </summary>
public class MessageInput
public class MessageInput: DynamicModel<object>
{
/// <summary>
/// The text of the user input. This string cannot contain carriage return, newline, or tab characters.
Expand Down
7 changes: 3 additions & 4 deletions Scripts/Services/Assistant/V1/Model/MessageRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace IBM.Watson.Assistant.V1.Model
{
Expand All @@ -30,7 +29,7 @@ public class MessageRequest
/// An input object that includes the input text.
/// </summary>
[JsonProperty("input", NullValueHandling = NullValueHandling.Ignore)]
public JObject Input { get; set; }
public MessageInput Input { get; set; }
/// <summary>
/// Intents to use when evaluating the user input. Include intents from the previous response to continue using
/// those intents rather than trying to recognize intents in the new input.
Expand All @@ -52,13 +51,13 @@ public class MessageRequest
/// State information for the conversation. To maintain state, include the context from the previous response.
/// </summary>
[JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)]
public JObject Context { get; set; }
public Context Context { get; set; }
/// <summary>
/// An output object that includes the response to the user, the dialog nodes that were triggered, and messages
/// from the log.
/// </summary>
[JsonProperty("output", NullValueHandling = NullValueHandling.Ignore)]
public JObject Output { get; set; }
public OutputData Output { get; set; }
/// <summary>
/// An array of objects describing any actions requested by the dialog node.
/// </summary>
Expand Down
7 changes: 3 additions & 4 deletions Scripts/Services/Assistant/V1/Model/MessageResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace IBM.Watson.Assistant.V1.Model
{
Expand All @@ -30,7 +29,7 @@ public class MessageResponse
/// An input object that includes the input text.
/// </summary>
[JsonProperty("input", NullValueHandling = NullValueHandling.Ignore)]
public JObject Input { get; set; }
public MessageInput Input { get; set; }
/// <summary>
/// An array of intents recognized in the user input, sorted in descending order of confidence.
/// </summary>
Expand All @@ -50,13 +49,13 @@ public class MessageResponse
/// State information for the conversation. To maintain state, include the context from the previous response.
/// </summary>
[JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)]
public JObject Context { get; set; }
public Context Context { get; set; }
/// <summary>
/// An output object that includes the response to the user, the dialog nodes that were triggered, and messages
/// from the log.
/// </summary>
[JsonProperty("output", NullValueHandling = NullValueHandling.Ignore)]
public JObject Output { get; set; }
public OutputData Output { get; set; }
/// <summary>
/// An array of objects describing any actions requested by the dialog node.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Scripts/Services/Assistant/V1/Model/OutputData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

using System.Collections.Generic;
using IBM.Cloud.SDK.Model;
using Newtonsoft.Json;

namespace IBM.Watson.Assistant.V1.Model
Expand All @@ -24,7 +25,7 @@ namespace IBM.Watson.Assistant.V1.Model
/// An output object that includes the response to the user, the dialog nodes that were triggered, and messages from
/// the log.
/// </summary>
public class OutputData
public class OutputData: DynamicModel<object>
{
/// <summary>
/// An array of the nodes that were triggered to create the response, in the order in which they were visited.
Expand Down
4 changes: 3 additions & 1 deletion Scripts/Services/Assistant/V1/Model/SystemResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*
*/

using IBM.Cloud.SDK.Model;

namespace IBM.Watson.Assistant.V1.Model
{
/// <summary>
/// For internal use only.
/// </summary>
public class SystemResponse
public class SystemResponse: DynamicModel<object>
{
}
}
13 changes: 7 additions & 6 deletions Scripts/Services/Assistant/V2/AssistantService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace IBM.Watson.Assistant.V2
public partial class AssistantService : BaseService
{
private const string serviceId = "assistant";
private const string defaultUrl = "https://gateway.watsonplatform.net/assistant/api";
private const string defaultServiceUrl = "https://gateway.watsonplatform.net/assistant/api";

#region VersionDate
private string versionDate;
Expand Down Expand Up @@ -81,9 +81,10 @@ public AssistantService(string versionDate, Authenticator authenticator) : base(
VersionDate = versionDate;
}

if (string.IsNullOrEmpty(serviceUrl))

if (string.IsNullOrEmpty(GetServiceUrl()))
{
serviceUrl = defaultUrl;
SetServiceUrl(defaultServiceUrl);
}
}

Expand Down Expand Up @@ -131,7 +132,7 @@ public bool CreateSession(Callback<SessionResponse> callback, string assistantId

req.OnResponse = OnCreateSessionResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions", assistantId), serviceUrl);
RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions", assistantId), GetServiceUrl());
if (connector == null)
{
return false;
Expand Down Expand Up @@ -210,7 +211,7 @@ public bool DeleteSession(Callback<object> callback, string assistantId, string

req.OnResponse = OnDeleteSessionResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions/{1}", assistantId, sessionId), serviceUrl);
RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions/{1}", assistantId, sessionId), GetServiceUrl());
if (connector == null)
{
return false;
Expand Down Expand Up @@ -304,7 +305,7 @@ public bool Message(Callback<MessageResponse> callback, string assistantId, stri

req.OnResponse = OnMessageResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions/{1}/message", assistantId, sessionId), serviceUrl);
RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions/{1}/message", assistantId, sessionId), GetServiceUrl());
if (connector == null)
{
return false;
Expand Down
3 changes: 1 addition & 2 deletions Scripts/Services/Assistant/V2/Model/MessageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace IBM.Watson.Assistant.V2.Model
{
Expand All @@ -37,6 +36,6 @@ public class MessageContext
/// that apply to the dialog skill used by the assistant.
/// </summary>
[JsonProperty("skills", NullValueHandling = NullValueHandling.Ignore)]
public JObject Skills { get; set; }
public MessageContextSkills Skills { get; set; }
}
}
4 changes: 3 additions & 1 deletion Scripts/Services/Assistant/V2/Model/MessageContextSkills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

using IBM.Cloud.SDK.Model;

namespace IBM.Watson.Assistant.V2.Model
{
/// <summary>
Expand All @@ -23,7 +25,7 @@ namespace IBM.Watson.Assistant.V2.Model
/// **Note:** Currently, only a single property named `main skill` is supported. This object contains variables that
/// apply to the dialog skill used by the assistant.
/// </summary>
public class MessageContextSkills
public class MessageContextSkills: DynamicModel<MessageContextSkill>
{
}
}
3 changes: 1 addition & 2 deletions Scripts/Services/Assistant/V2/Model/SearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace IBM.Watson.Assistant.V2.Model
{
Expand Down Expand Up @@ -60,6 +59,6 @@ public class SearchResult
/// <em> tags.
/// </summary>
[JsonProperty("highlight", NullValueHandling = NullValueHandling.Ignore)]
public JObject Highlight { get; set; }
public SearchResultHighlight Highlight { get; set; }
}
}
Loading