Skip to content

Commit

Permalink
fix(nlu): add notices, remove version param, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apaparazzi0329 committed May 12, 2021
1 parent 5abf627 commit 92b0efd
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 83 deletions.
Expand Up @@ -59,11 +59,6 @@ public struct CategoriesModel: Codable, Equatable {
*/
public var modelVersion: String?

/**
Deprecated — use `model_version`.
*/
public var version: String?

/**
ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.
*/
Expand Down Expand Up @@ -94,6 +89,8 @@ public struct CategoriesModel: Codable, Equatable {
*/
public var created: Date

public var notices: [Notice]?

/**
dateTime of last successful model training.
*/
Expand All @@ -111,13 +108,13 @@ public struct CategoriesModel: Codable, Equatable {
case language = "language"
case description = "description"
case modelVersion = "model_version"
case version = "version"
case workspaceID = "workspace_id"
case versionDescription = "version_description"
case features = "features"
case status = "status"
case modelID = "model_id"
case created = "created"
case notices = "notices"
case lastTrained = "last_trained"
case lastDeployed = "last_deployed"
}
Expand Down
Expand Up @@ -59,11 +59,6 @@ public struct ClassificationsModel: Codable, Equatable {
*/
public var modelVersion: String?

/**
Deprecated — use `model_version`.
*/
public var version: String?

/**
ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.
*/
Expand Down Expand Up @@ -94,6 +89,8 @@ public struct ClassificationsModel: Codable, Equatable {
*/
public var created: Date

public var notices: [Notice]?

/**
dateTime of last successful model training.
*/
Expand All @@ -111,13 +108,13 @@ public struct ClassificationsModel: Codable, Equatable {
case language = "language"
case description = "description"
case modelVersion = "model_version"
case version = "version"
case workspaceID = "workspace_id"
case versionDescription = "version_description"
case features = "features"
case status = "status"
case modelID = "model_id"
case created = "created"
case notices = "notices"
case lastTrained = "last_trained"
case lastDeployed = "last_deployed"
}
Expand Down
34 changes: 34 additions & 0 deletions Sources/NaturalLanguageUnderstandingV1/Models/Notice.swift
@@ -0,0 +1,34 @@
/**
* (C) Copyright IBM Corp. 2021.
*
* 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.
**/

import Foundation

/**
A list of messages describing model training issues when model status is `error`.
*/
public struct Notice: Codable, Equatable {

/**
Describes deficiencies or inconsistencies in training data.
*/
public var message: String?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case message = "message"
}

}
Expand Up @@ -89,10 +89,7 @@ public struct SentimentModel: Codable, Equatable {
*/
public var modelVersion: String?

/**
Deprecated — use `model_version`.
*/
public var version: String?
public var notices: [Notice]?

/**
ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.
Expand All @@ -117,7 +114,7 @@ public struct SentimentModel: Codable, Equatable {
case language = "language"
case description = "description"
case modelVersion = "model_version"
case version = "version"
case notices = "notices"
case workspaceID = "workspace_id"
case versionDescription = "version_description"
}
Expand Down
Expand Up @@ -15,7 +15,7 @@
**/

/**
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-bd714324-20210419-134238
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-902c9336-20210507-162723
**/

// swiftlint:disable file_length
Expand Down Expand Up @@ -384,7 +384,6 @@ public class NaturalLanguageUnderstanding {
- parameter name: An optional name for the model.
- parameter description: An optional description of the model.
- parameter modelVersion: An optional version string.
- parameter version: Deprecated — use `model_version`.
- parameter workspaceID: ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language
Understanding.
- parameter versionDescription: The description of the version.
Expand All @@ -397,7 +396,6 @@ public class NaturalLanguageUnderstanding {
name: String? = nil,
description: String? = nil,
modelVersion: String? = nil,
version: String? = nil,
workspaceID: String? = nil,
versionDescription: String? = nil,
headers: [String: String]? = nil,
Expand All @@ -408,7 +406,7 @@ public class NaturalLanguageUnderstanding {
if let languageData = language.data(using: .utf8) {
multipartFormData.append(languageData, withName: "language")
}
multipartFormData.append(trainingData, withName: "training_data", fileName: "filename")
multipartFormData.append(trainingData, withName: "training_data", mimeType: "text/csv", fileName: "filename")
if let name = name {
if let nameData = name.data(using: .utf8) {
multipartFormData.append(nameData, withName: "name")
Expand All @@ -424,11 +422,6 @@ public class NaturalLanguageUnderstanding {
multipartFormData.append(modelVersionData, withName: "model_version")
}
}
if let version = version {
if let versionData = version.data(using: .utf8) {
multipartFormData.append(versionData, withName: "version")
}
}
if let workspaceID = workspaceID {
if let workspaceIDData = workspaceID.data(using: .utf8) {
multipartFormData.append(workspaceIDData, withName: "workspace_id")
Expand Down Expand Up @@ -551,6 +544,10 @@ public class NaturalLanguageUnderstanding {
headerParameters.merge(headers) { (_, new) in new }
}

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

// construct REST request
let path = "/v1/models/sentiment/\(modelID)"
guard let encodedPath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
Expand All @@ -570,7 +567,8 @@ public class NaturalLanguageUnderstanding {
errorResponseDecoder: errorResponseDecoder,
method: "GET",
url: serviceEndpoint + encodedPath,
headerParameters: headerParameters
headerParameters: headerParameters,
queryItems: queryParameters
)

// execute REST request
Expand All @@ -590,7 +588,6 @@ public class NaturalLanguageUnderstanding {
- parameter name: An optional name for the model.
- parameter description: An optional description of the model.
- parameter modelVersion: An optional version string.
- parameter version: Deprecated — use `model_version`.
- parameter workspaceID: ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language
Understanding.
- parameter versionDescription: The description of the version.
Expand All @@ -604,7 +601,6 @@ public class NaturalLanguageUnderstanding {
name: String? = nil,
description: String? = nil,
modelVersion: String? = nil,
version: String? = nil,
workspaceID: String? = nil,
versionDescription: String? = nil,
headers: [String: String]? = nil,
Expand All @@ -615,7 +611,7 @@ public class NaturalLanguageUnderstanding {
if let languageData = language.data(using: .utf8) {
multipartFormData.append(languageData, withName: "language")
}
multipartFormData.append(trainingData, withName: "training_data", fileName: "filename")
multipartFormData.append(trainingData, withName: "training_data", mimeType: "text/csv", fileName: "filename")
if let name = name {
if let nameData = name.data(using: .utf8) {
multipartFormData.append(nameData, withName: "name")
Expand All @@ -631,11 +627,6 @@ public class NaturalLanguageUnderstanding {
multipartFormData.append(modelVersionData, withName: "model_version")
}
}
if let version = version {
if let versionData = version.data(using: .utf8) {
multipartFormData.append(versionData, withName: "version")
}
}
if let workspaceID = workspaceID {
if let workspaceIDData = workspaceID.data(using: .utf8) {
multipartFormData.append(workspaceIDData, withName: "workspace_id")
Expand All @@ -661,6 +652,10 @@ public class NaturalLanguageUnderstanding {
headerParameters.merge(headers) { (_, new) in new }
}

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

// construct REST request
let path = "/v1/models/sentiment/\(modelID)"
guard let encodedPath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
Expand All @@ -681,6 +676,7 @@ public class NaturalLanguageUnderstanding {
method: "PUT",
url: serviceEndpoint + encodedPath,
headerParameters: headerParameters,
queryItems: queryParameters,
messageBody: body
)

Expand Down Expand Up @@ -712,6 +708,10 @@ public class NaturalLanguageUnderstanding {
headerParameters.merge(headers) { (_, new) in new }
}

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

// construct REST request
let path = "/v1/models/sentiment/\(modelID)"
guard let encodedPath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
Expand All @@ -731,7 +731,8 @@ public class NaturalLanguageUnderstanding {
errorResponseDecoder: errorResponseDecoder,
method: "DELETE",
url: serviceEndpoint + encodedPath,
headerParameters: headerParameters
headerParameters: headerParameters,
queryItems: queryParameters
)

// execute REST request
Expand All @@ -751,7 +752,6 @@ public class NaturalLanguageUnderstanding {
- parameter name: An optional name for the model.
- parameter description: An optional description of the model.
- parameter modelVersion: An optional version string.
- parameter version: Deprecated — use `model_version`.
- parameter workspaceID: ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language
Understanding.
- parameter versionDescription: The description of the version.
Expand All @@ -765,7 +765,6 @@ public class NaturalLanguageUnderstanding {
name: String? = nil,
description: String? = nil,
modelVersion: String? = nil,
version: String? = nil,
workspaceID: String? = nil,
versionDescription: String? = nil,
headers: [String: String]? = nil,
Expand All @@ -792,11 +791,6 @@ public class NaturalLanguageUnderstanding {
multipartFormData.append(modelVersionData, withName: "model_version")
}
}
if let version = version {
if let versionData = version.data(using: .utf8) {
multipartFormData.append(versionData, withName: "version")
}
}
if let workspaceID = workspaceID {
if let workspaceIDData = workspaceID.data(using: .utf8) {
multipartFormData.append(workspaceIDData, withName: "workspace_id")
Expand Down Expand Up @@ -964,7 +958,6 @@ public class NaturalLanguageUnderstanding {
- parameter name: An optional name for the model.
- parameter description: An optional description of the model.
- parameter modelVersion: An optional version string.
- parameter version: Deprecated — use `model_version`.
- parameter workspaceID: ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language
Understanding.
- parameter versionDescription: The description of the version.
Expand All @@ -979,7 +972,6 @@ public class NaturalLanguageUnderstanding {
name: String? = nil,
description: String? = nil,
modelVersion: String? = nil,
version: String? = nil,
workspaceID: String? = nil,
versionDescription: String? = nil,
headers: [String: String]? = nil,
Expand All @@ -1006,11 +998,6 @@ public class NaturalLanguageUnderstanding {
multipartFormData.append(modelVersionData, withName: "model_version")
}
}
if let version = version {
if let versionData = version.data(using: .utf8) {
multipartFormData.append(versionData, withName: "version")
}
}
if let workspaceID = workspaceID {
if let workspaceIDData = workspaceID.data(using: .utf8) {
multipartFormData.append(workspaceIDData, withName: "workspace_id")
Expand Down Expand Up @@ -1136,7 +1123,6 @@ public class NaturalLanguageUnderstanding {
- parameter name: An optional name for the model.
- parameter description: An optional description of the model.
- parameter modelVersion: An optional version string.
- parameter version: Deprecated — use `model_version`.
- parameter workspaceID: ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language
Understanding.
- parameter versionDescription: The description of the version.
Expand All @@ -1150,7 +1136,6 @@ public class NaturalLanguageUnderstanding {
name: String? = nil,
description: String? = nil,
modelVersion: String? = nil,
version: String? = nil,
workspaceID: String? = nil,
versionDescription: String? = nil,
headers: [String: String]? = nil,
Expand All @@ -1177,11 +1162,6 @@ public class NaturalLanguageUnderstanding {
multipartFormData.append(modelVersionData, withName: "model_version")
}
}
if let version = version {
if let versionData = version.data(using: .utf8) {
multipartFormData.append(versionData, withName: "version")
}
}
if let workspaceID = workspaceID {
if let workspaceIDData = workspaceID.data(using: .utf8) {
multipartFormData.append(workspaceIDData, withName: "workspace_id")
Expand Down Expand Up @@ -1349,7 +1329,6 @@ public class NaturalLanguageUnderstanding {
- parameter name: An optional name for the model.
- parameter description: An optional description of the model.
- parameter modelVersion: An optional version string.
- parameter version: Deprecated — use `model_version`.
- parameter workspaceID: ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language
Understanding.
- parameter versionDescription: The description of the version.
Expand All @@ -1364,7 +1343,6 @@ public class NaturalLanguageUnderstanding {
name: String? = nil,
description: String? = nil,
modelVersion: String? = nil,
version: String? = nil,
workspaceID: String? = nil,
versionDescription: String? = nil,
headers: [String: String]? = nil,
Expand All @@ -1391,11 +1369,6 @@ public class NaturalLanguageUnderstanding {
multipartFormData.append(modelVersionData, withName: "model_version")
}
}
if let version = version {
if let versionData = version.data(using: .utf8) {
multipartFormData.append(versionData, withName: "version")
}
}
if let workspaceID = workspaceID {
if let workspaceIDData = workspaceID.data(using: .utf8) {
multipartFormData.append(workspaceIDData, withName: "workspace_id")
Expand Down

0 comments on commit 92b0efd

Please sign in to comment.