Skip to content

Commit

Permalink
feat(assistant_v2): same as v1, add new properties to models
Browse files Browse the repository at this point in the history
  • Loading branch information
apaparazzi0329 authored and watson-github-bot committed Sep 14, 2021
1 parent 5d4be6e commit 5d37f1f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 18 deletions.
44 changes: 39 additions & 5 deletions Sources/AssistantV2/Models/MessageContextGlobalSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,39 @@ public struct MessageContextGlobalSystem: Codable, Equatable {
current server time, and is used to calculate times mentioned in relative terms such as `now` or `tomorrow`. This
can be useful for simulating past or future times for testing purposes, or when analyzing documents such as news
articles.
This value must be a UTC time value formatted according to ISO 8601 (for example, `2019-06-26T12:00:00Z` for noon
on 26 June 2019.
This value must be a UTC time value formatted according to ISO 8601 (for example, `2021-06-26T12:00:00Z` for noon
UTC on 26 June 2021).
This property is included only if the new system entities are enabled for the skill.
*/
public var referenceTime: String?

/**
The time at which the session started. With the stateful `message` method, the start time is always present, and is
set by the service based on the time the session was created. With the stateless `message` method, the start time
is set by the service in the response to the first message, and should be returned as part of the context with each
subsequent message in the session.
This value is a UTC time value formatted according to ISO 8601 (for example, `2021-06-26T12:00:00Z` for noon UTC on
26 June 2021).
*/
public var sessionStartTime: String?

/**
An encoded string that represents the configuration state of the assistant at the beginning of the conversation. If
you are using the stateless `message` method, save this value and then send it in the context of the subsequent
message request to avoid disruptions if there are configuration changes during the conversation (such as a change
to a skill the assistant uses).
*/
public var state: String?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case timezone = "timezone"
case userID = "user_id"
case turnCount = "turn_count"
case locale = "locale"
case referenceTime = "reference_time"
case sessionStartTime = "session_start_time"
case state = "state"
}

/**
Expand All @@ -119,9 +139,19 @@ public struct MessageContextGlobalSystem: Codable, Equatable {
specified time overrides the current server time, and is used to calculate times mentioned in relative terms such
as `now` or `tomorrow`. This can be useful for simulating past or future times for testing purposes, or when
analyzing documents such as news articles.
This value must be a UTC time value formatted according to ISO 8601 (for example, `2019-06-26T12:00:00Z` for noon
on 26 June 2019.
This value must be a UTC time value formatted according to ISO 8601 (for example, `2021-06-26T12:00:00Z` for noon
UTC on 26 June 2021).
This property is included only if the new system entities are enabled for the skill.
- parameter sessionStartTime: The time at which the session started. With the stateful `message` method, the
start time is always present, and is set by the service based on the time the session was created. With the
stateless `message` method, the start time is set by the service in the response to the first message, and should
be returned as part of the context with each subsequent message in the session.
This value is a UTC time value formatted according to ISO 8601 (for example, `2021-06-26T12:00:00Z` for noon UTC
on 26 June 2021).
- parameter state: An encoded string that represents the configuration state of the assistant at the beginning
of the conversation. If you are using the stateless `message` method, save this value and then send it in the
context of the subsequent message request to avoid disruptions if there are configuration changes during the
conversation (such as a change to a skill the assistant uses).

- returns: An initialized `MessageContextGlobalSystem`.
*/
Expand All @@ -130,14 +160,18 @@ public struct MessageContextGlobalSystem: Codable, Equatable {
userID: String? = nil,
turnCount: Int? = nil,
locale: String? = nil,
referenceTime: String? = nil
referenceTime: String? = nil,
sessionStartTime: String? = nil,
state: String? = nil
)
{
self.timezone = timezone
self.userID = userID
self.turnCount = turnCount
self.locale = locale
self.referenceTime = referenceTime
self.sessionStartTime = sessionStartTime
self.state = state
}

}
16 changes: 13 additions & 3 deletions Sources/AssistantV2/Models/MessageInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ import Foundation
public struct MessageInput: Codable, Equatable {

/**
The type of user input. Currently, only text input is supported.
The type of the message:
- `text`: The user input is processed normally by the assistant.
- `search`: Only search results are returned. (Any dialog or actions skill is bypassed.)
**Note:** A `search` message results in an error if no search skill is configured for the assistant.
*/
public enum MessageType: String {
case text = "text"
case search = "search"
}

/**
The type of user input. Currently, only text input is supported.
The type of the message:
- `text`: The user input is processed normally by the assistant.
- `search`: Only search results are returned. (Any dialog or actions skill is bypassed.)
**Note:** A `search` message results in an error if no search skill is configured for the assistant.
*/
public var messageType: String?

Expand Down Expand Up @@ -73,7 +80,10 @@ public struct MessageInput: Codable, Equatable {
/**
Initialize a `MessageInput` with member variables.

- parameter messageType: The type of user input. Currently, only text input is supported.
- parameter messageType: The type of the message:
- `text`: The user input is processed normally by the assistant.
- `search`: Only search results are returned. (Any dialog or actions skill is bypassed.)
**Note:** A `search` message results in an error if no search skill is configured for the assistant.
- parameter text: The text of the user input. This string cannot contain carriage return, newline, or tab
characters.
- parameter intents: Intents to use when evaluating the user input. Include intents from the previous response
Expand Down
16 changes: 13 additions & 3 deletions Sources/AssistantV2/Models/MessageInputStateless.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ import Foundation
public struct MessageInputStateless: Codable, Equatable {

/**
The type of user input. Currently, only text input is supported.
The type of the message:
- `text`: The user input is processed normally by the assistant.
- `search`: Only search results are returned. (Any dialog or actions skill is bypassed.)
**Note:** A `search` message results in an error if no search skill is configured for the assistant.
*/
public enum MessageType: String {
case text = "text"
case search = "search"
}

/**
The type of user input. Currently, only text input is supported.
The type of the message:
- `text`: The user input is processed normally by the assistant.
- `search`: Only search results are returned. (Any dialog or actions skill is bypassed.)
**Note:** A `search` message results in an error if no search skill is configured for the assistant.
*/
public var messageType: String?

Expand Down Expand Up @@ -73,7 +80,10 @@ public struct MessageInputStateless: Codable, Equatable {
/**
Initialize a `MessageInputStateless` with member variables.

- parameter messageType: The type of user input. Currently, only text input is supported.
- parameter messageType: The type of the message:
- `text`: The user input is processed normally by the assistant.
- `search`: Only search results are returned. (Any dialog or actions skill is bypassed.)
**Note:** A `search` message results in an error if no search skill is configured for the assistant.
- parameter text: The text of the user input. This string cannot contain carriage return, newline, or tab
characters.
- parameter intents: Intents to use when evaluating the user input. Include intents from the previous response
Expand Down
16 changes: 10 additions & 6 deletions Sources/AssistantV2/Models/RuntimeEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct RuntimeEntity: Codable, Equatable {
An array of zero-based character offsets that indicate where the detected entity values begin and end in the input
text.
*/
public var location: [Int]
public var location: [Int]?

/**
The term in the input text that was recognized as an entity value.
Expand All @@ -44,7 +44,9 @@ public struct RuntimeEntity: Codable, Equatable {
public var confidence: Double?

/**
Any metadata for the entity.
**Deprecated.** Any metadata for the entity.
Beginning with the `2021-06-14` API version, the `metadata` property is no longer returned. For information about
system entities recognized in the user input, see the `interpretation` property.
*/
public var metadata: [String: JSON]?

Expand Down Expand Up @@ -92,11 +94,13 @@ public struct RuntimeEntity: Codable, Equatable {
Initialize a `RuntimeEntity` with member variables.

- parameter entity: An entity detected in the input.
- parameter value: The term in the input text that was recognized as an entity value.
- parameter location: An array of zero-based character offsets that indicate where the detected entity values
begin and end in the input text.
- parameter value: The term in the input text that was recognized as an entity value.
- parameter confidence: A decimal percentage that represents Watson's confidence in the recognized entity.
- parameter metadata: Any metadata for the entity.
- parameter metadata: **Deprecated.** Any metadata for the entity.
Beginning with the `2021-06-14` API version, the `metadata` property is no longer returned. For information about
system entities recognized in the user input, see the `interpretation` property.
- parameter groups: The recognized capture groups for the entity, as defined by the entity pattern.
- parameter interpretation: An object containing detailed information about the entity recognized in the user
input. This property is included only if the new system entities are enabled for the skill.
Expand All @@ -114,8 +118,8 @@ public struct RuntimeEntity: Codable, Equatable {
*/
public init(
entity: String,
location: [Int],
value: String,
location: [Int]? = nil,
confidence: Double? = nil,
metadata: [String: JSON]? = nil,
groups: [CaptureGroup]? = nil,
Expand All @@ -125,8 +129,8 @@ public struct RuntimeEntity: Codable, Equatable {
)
{
self.entity = entity
self.location = location
self.value = value
self.location = location
self.confidence = confidence
self.metadata = metadata
self.groups = groups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct RuntimeResponseGenericRuntimeResponseTypeImage: Codable, Equatable
public var responseType: String

/**
The URL of the image.
The `https:` URL of the image.
*/
public var source: String

Expand All @@ -51,13 +51,19 @@ public struct RuntimeResponseGenericRuntimeResponseTypeImage: Codable, Equatable
*/
public var channels: [ResponseGenericChannel]?

/**
Descriptive text that can be used for screen readers or other situations where the image cannot be seen.
*/
public var altText: String?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case responseType = "response_type"
case source = "source"
case title = "title"
case description = "description"
case channels = "channels"
case altText = "alt_text"
}

}

0 comments on commit 5d37f1f

Please sign in to comment.