Skip to content

Commit

Permalink
Merge pull request #1018 from watson-developer-cloud/feat/release-2-q…
Browse files Browse the repository at this point in the history
…2-2020

Feat/release 2 q2 2020
  • Loading branch information
jeff-arn authored Jun 5, 2020
2 parents f0143cd + b3fb5ed commit 34d2ce1
Show file tree
Hide file tree
Showing 35 changed files with 1,256 additions and 150 deletions.
263 changes: 196 additions & 67 deletions .travis.yml

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Source/AssistantV1/Models/DialogNodeOutputGeneric.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public struct DialogNodeOutputGeneric: Codable, Equatable {
/**
The text of the search query. This can be either a natural-language query or a query that uses the Discovery query
language syntax, depending on the value of the **query_type** property. For more information, see the [Discovery
service documentation](https://cloud.ibm.com/docs/discovery/query-operators.html#query-operators). Required when
**response_type**=`search_skill`.
service documentation](https://cloud.ibm.com/docs/discovery?topic=discovery-query-operators#query-operators).
Required when **response_type**=`search_skill`.
*/
public var query: String?

Expand All @@ -144,7 +144,7 @@ public struct DialogNodeOutputGeneric: Codable, Equatable {
/**
An optional filter that narrows the set of documents to be searched. For more information, see the [Discovery
service documentation]([Discovery service
documentation](https://cloud.ibm.com/docs/discovery/query-parameters.html#filter).
documentation](https://cloud.ibm.com/docs/discovery?topic=discovery-query-parameters#filter).
*/
public var filter: String?

Expand Down Expand Up @@ -204,12 +204,12 @@ public struct DialogNodeOutputGeneric: Codable, Equatable {
- parameter query: The text of the search query. This can be either a natural-language query or a query that
uses the Discovery query language syntax, depending on the value of the **query_type** property. For more
information, see the [Discovery service
documentation](https://cloud.ibm.com/docs/discovery/query-operators.html#query-operators). Required when
**response_type**=`search_skill`.
documentation](https://cloud.ibm.com/docs/discovery?topic=discovery-query-operators#query-operators). Required
when **response_type**=`search_skill`.
- parameter queryType: The type of the search query. Required when **response_type**=`search_skill`.
- parameter filter: An optional filter that narrows the set of documents to be searched. For more information,
see the [Discovery service documentation]([Discovery service
documentation](https://cloud.ibm.com/docs/discovery/query-parameters.html#filter).
documentation](https://cloud.ibm.com/docs/discovery?topic=discovery-query-parameters#filter).
- parameter discoveryVersion: The version of the Discovery service API to use for the query.

- returns: An initialized `DialogNodeOutputGeneric`.
Expand Down
62 changes: 60 additions & 2 deletions Source/AssistantV1/Models/MessageInput.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2017, 2019.
* (C) Copyright IBM Corp. 2017, 2020.
*
* 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,42 +27,100 @@ public struct MessageInput: Codable, Equatable {
*/
public var text: String?

/**
Whether to use spelling correction when processing the input. This property overrides the value of the
**spelling_suggestions** property in the workspace settings.
*/
public var spellingSuggestions: Bool?

/**
Whether to use autocorrection when processing the input. If spelling correction is used and this property is
`false`, any suggested corrections are returned in the **suggested_text** property of the message response. If this
property is `true`, any corrections are automatically applied to the user input, and the original text is returned
in the **original_text** property of the message response. This property overrides the value of the
**spelling_auto_correct** property in the workspace settings.
*/
public var spellingAutoCorrect: Bool?

/**
Any suggested corrections of the input text. This property is returned only if spelling correction is enabled and
autocorrection is disabled.
*/
public var suggestedText: String?

/**
The original user input text. This property is returned only if autocorrection is enabled and the user input was
corrected.
*/
public var originalText: String?

/// Additional properties associated with this model.
public var additionalProperties: [String: JSON]

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case text = "text"
static let allValues = [text]
case spellingSuggestions = "spelling_suggestions"
case spellingAutoCorrect = "spelling_auto_correct"
case suggestedText = "suggested_text"
case originalText = "original_text"
static let allValues = [text, spellingSuggestions, spellingAutoCorrect, suggestedText, originalText]
}

/**
Initialize a `MessageInput` with member variables.

- parameter text: The text of the user input. This string cannot contain carriage return, newline, or tab
characters.
- parameter spellingSuggestions: Whether to use spelling correction when processing the input. This property
overrides the value of the **spelling_suggestions** property in the workspace settings.
- parameter spellingAutoCorrect: Whether to use autocorrection when processing the input. If spelling correction
is used and this property is `false`, any suggested corrections are returned in the **suggested_text** property
of the message response. If this property is `true`, any corrections are automatically applied to the user input,
and the original text is returned in the **original_text** property of the message response. This property
overrides the value of the **spelling_auto_correct** property in the workspace settings.
- parameter suggestedText: Any suggested corrections of the input text. This property is returned only if
spelling correction is enabled and autocorrection is disabled.
- parameter originalText: The original user input text. This property is returned only if autocorrection is
enabled and the user input was corrected.

- returns: An initialized `MessageInput`.
*/
public init(
text: String? = nil,
spellingSuggestions: Bool? = nil,
spellingAutoCorrect: Bool? = nil,
suggestedText: String? = nil,
originalText: String? = nil,
additionalProperties: [String: JSON] = [:]
)
{
self.text = text
self.spellingSuggestions = spellingSuggestions
self.spellingAutoCorrect = spellingAutoCorrect
self.suggestedText = suggestedText
self.originalText = originalText
self.additionalProperties = additionalProperties
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
text = try container.decodeIfPresent(String.self, forKey: .text)
spellingSuggestions = try container.decodeIfPresent(Bool.self, forKey: .spellingSuggestions)
spellingAutoCorrect = try container.decodeIfPresent(Bool.self, forKey: .spellingAutoCorrect)
suggestedText = try container.decodeIfPresent(String.self, forKey: .suggestedText)
originalText = try container.decodeIfPresent(String.self, forKey: .originalText)
let dynamicContainer = try decoder.container(keyedBy: DynamicKeys.self)
additionalProperties = try dynamicContainer.decode([String: JSON].self, excluding: CodingKeys.allValues)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(text, forKey: .text)
try container.encodeIfPresent(spellingSuggestions, forKey: .spellingSuggestions)
try container.encodeIfPresent(spellingAutoCorrect, forKey: .spellingAutoCorrect)
try container.encodeIfPresent(suggestedText, forKey: .suggestedText)
try container.encodeIfPresent(originalText, forKey: .originalText)
var dynamicContainer = encoder.container(keyedBy: DynamicKeys.self)
try dynamicContainer.encodeIfPresent(additionalProperties)
}
Expand Down
24 changes: 24 additions & 0 deletions Source/AssistantV1/Models/WorkspaceSystemSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ public struct WorkspaceSystemSettings: Codable, Equatable {
*/
public var humanAgentAssist: [String: JSON]?

/**
Whether spelling correction is enabled for the workspace.
*/
public var spellingSuggestions: Bool?

/**
Whether autocorrection is enabled for the workspace. If spelling correction is enabled and this property is
`false`, any suggested corrections are returned in the **suggested_text** property of the message response. If this
property is `true`, any corrections are automatically applied to the user input, and the original text is returned
in the **original_text** property of the message response.
*/
public var spellingAutoCorrect: Bool?

/**
Workspace settings related to the behavior of system entities.
*/
Expand All @@ -53,6 +66,8 @@ public struct WorkspaceSystemSettings: Codable, Equatable {
case tooling = "tooling"
case disambiguation = "disambiguation"
case humanAgentAssist = "human_agent_assist"
case spellingSuggestions = "spelling_suggestions"
case spellingAutoCorrect = "spelling_auto_correct"
case systemEntities = "system_entities"
case offTopic = "off_topic"
}
Expand All @@ -64,6 +79,11 @@ public struct WorkspaceSystemSettings: Codable, Equatable {
- parameter disambiguation: Workspace settings related to the disambiguation feature.
**Note:** This feature is available only to Plus and Premium users.
- parameter humanAgentAssist: For internal use only.
- parameter spellingSuggestions: Whether spelling correction is enabled for the workspace.
- parameter spellingAutoCorrect: Whether autocorrection is enabled for the workspace. If spelling correction is
enabled and this property is `false`, any suggested corrections are returned in the **suggested_text** property
of the message response. If this property is `true`, any corrections are automatically applied to the user input,
and the original text is returned in the **original_text** property of the message response.
- parameter systemEntities: Workspace settings related to the behavior of system entities.
- parameter offTopic: Workspace settings related to detection of irrelevant input.

Expand All @@ -73,13 +93,17 @@ public struct WorkspaceSystemSettings: Codable, Equatable {
tooling: WorkspaceSystemSettingsTooling? = nil,
disambiguation: WorkspaceSystemSettingsDisambiguation? = nil,
humanAgentAssist: [String: JSON]? = nil,
spellingSuggestions: Bool? = nil,
spellingAutoCorrect: Bool? = nil,
systemEntities: WorkspaceSystemSettingsSystemEntities? = nil,
offTopic: WorkspaceSystemSettingsOffTopic? = nil
)
{
self.tooling = tooling
self.disambiguation = disambiguation
self.humanAgentAssist = humanAgentAssist
self.spellingSuggestions = spellingSuggestions
self.spellingAutoCorrect = spellingAutoCorrect
self.systemEntities = systemEntities
self.offTopic = offTopic
}
Expand Down
89 changes: 84 additions & 5 deletions Source/AssistantV2/Assistant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ public class Assistant {
}

/**
Send user input to assistant.
Send user input to assistant (stateful).

Send user input to an assistant and receive a response.
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.
There is no rate limit for this operation.

- parameter assistantID: Unique identifier of the assistant. To find the assistant ID in the Watson Assistant
Expand All @@ -260,9 +261,10 @@ public class Assistant {
**Note:** Currently, the v2 API does not support creating assistants.
- parameter sessionID: Unique identifier of the session.
- parameter input: An input object that includes the input text.
- parameter context: State information for the conversation. The context is stored by the assistant on a
per-session basis. You can use this property to set or modify context variables, which can also be accessed by
dialog nodes.
- parameter context: Context data for the conversation. You can use this property to set or modify context
variables, which can also be accessed by dialog nodes. The context is stored by the assistant on a per-session
basis.
**Note:** The total size of the context data stored for a stateful session cannot exceed 100KB.
- parameter headers: A dictionary of request headers to be sent with this request.
- parameter completionHandler: A function executed when the request completes with a successful result or error
*/
Expand Down Expand Up @@ -325,4 +327,81 @@ public class Assistant {
request.responseObject(completionHandler: completionHandler)
}

/**
Send user input to assistant (stateless).

Send user input to an assistant and receive a response, with conversation state (including context data) managed by
your application.
There is no rate limit for this operation.

- parameter assistantID: Unique identifier of the assistant. To find the assistant ID in the Watson Assistant
user interface, open the assistant settings and click **API Details**. For information about creating assistants,
see the [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-assistant-add#assistant-add-task).
**Note:** Currently, the v2 API does not support creating assistants.
- parameter input: An input object that includes the input text.
- parameter context: Context data for the conversation. You can use this property to set or modify context
variables, which can also be accessed by dialog nodes. The context is not stored by the assistant. To maintain
session state, include the context from the previous response.
**Note:** The total size of the context data for a stateless session cannot exceed 250KB.
- parameter headers: A dictionary of request headers to be sent with this request.
- parameter completionHandler: A function executed when the request completes with a successful result or error
*/
public func messageStateless(
assistantID: String,
input: MessageInputStateless? = nil,
context: MessageContextStateless? = nil,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<MessageResponseStateless>?, WatsonError?) -> Void)
{
// construct body
let messageStatelessRequest = MessageRequestStateless(
input: input,
context: context)
guard let body = try? JSON.encoder.encodeIfPresent(messageStatelessRequest) else {
completionHandler(nil, WatsonError.serialization(values: "request body"))
return
}

// construct header parameters
var headerParameters = defaultHeaders
if let headers = headers {
headerParameters.merge(headers) { (_, new) in new }
}
let sdkHeaders = Shared.getSDKHeaders(serviceName: serviceName, serviceVersion: serviceVersion, methodName: "messageStateless")
headerParameters.merge(sdkHeaders) { (_, new) in new }
headerParameters["Accept"] = "application/json"
headerParameters["Content-Type"] = "application/json"

// construct query parameters
var queryParameters = [URLQueryItem]()
queryParameters.append(URLQueryItem(name: "version", value: version))

// construct REST request
let path = "/v2/assistants/\(assistantID)/message"
guard let encodedPath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
completionHandler(nil, WatsonError.urlEncoding(path: path))
return
}

// ensure that serviceURL is set
guard let serviceEndpoint = serviceURL else {
completionHandler(nil, WatsonError.noEndpoint)
return
}

let request = RestRequest(
session: session,
authenticator: authenticator,
errorResponseDecoder: errorResponseDecoder,
method: "POST",
url: serviceEndpoint + encodedPath,
headerParameters: headerParameters,
queryItems: queryParameters,
messageBody: body
)

// execute REST request
request.responseObject(completionHandler: completionHandler)
}

}
18 changes: 9 additions & 9 deletions Source/AssistantV2/Models/MessageContext.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2018, 2019.
* (C) Copyright IBM Corp. 2018, 2020.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,14 +20,14 @@ import Foundation
public struct MessageContext: Codable, Equatable {

/**
Information that is shared by all skills used by the Assistant.
Session context data that is shared by all skills used by the Assistant.
*/
public var global: MessageContextGlobal?

/**
Information specific to particular skills used by the Assistant.
**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.
Information specific to particular skills used by the assistant.
**Note:** Currently, only a single child property is supported, containing variables that apply to the dialog skill
used by the assistant.
*/
public var skills: MessageContextSkills?

Expand All @@ -40,10 +40,10 @@ public struct MessageContext: Codable, Equatable {
/**
Initialize a `MessageContext` with member variables.

- parameter global: Information that is shared by all skills used by the Assistant.
- parameter skills: Information specific to particular skills used by the Assistant.
**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.
- parameter global: Session context data that is shared by all skills used by the Assistant.
- parameter skills: Information specific to particular skills used by the assistant.
**Note:** Currently, only a single child property is supported, containing variables that apply to the dialog
skill used by the assistant.

- returns: An initialized `MessageContext`.
*/
Expand Down
Loading

0 comments on commit 34d2ce1

Please sign in to comment.