Skip to content

Commit b8560fe

Browse files
committed
Filter assistant types for single input/output
Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com>
1 parent 99d564f commit b8560fe

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

Sources/NextcloudKit/Models/Assistant/v2/TaskTypes.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public struct TaskTypes: Codable {
2929
}
3030

3131
public struct TaskTypeData: Codable {
32+
public typealias TaskInputShape = [String: Shape]
33+
public typealias TaskOutputShape = [String: Shape]
34+
3235
public var id: String?
3336
public let name: String?
3437
public let description: String?
@@ -42,21 +45,21 @@ public struct TaskTypeData: Codable {
4245
self.inputShape = inputShape
4346
self.outputShape = outputShape
4447
}
45-
}
46-
47-
public struct TaskInputShape: Codable {
48-
public let input: Shape?
4948

50-
public init(input: Shape?) {
51-
self.input = input
49+
public func isChat() -> Bool {
50+
id == "core:text2text:chat"
5251
}
53-
}
5452

55-
public struct TaskOutputShape: Codable {
56-
public let output: Shape?
53+
public func isTranslate() -> Bool {
54+
id?.contains("translate") == true
55+
}
5756

58-
public init(output: Shape?) {
59-
self.output = output
57+
public func isSingleTextInputOutput(supportedTaskType: String = "Text") -> Bool {
58+
guard let inputShape, let outputShape else { return false }
59+
return inputShape.count == 1 &&
60+
outputShape.count == 1 &&
61+
inputShape.values.first?.type == supportedTaskType &&
62+
outputShape.values.first?.type == supportedTaskType
6063
}
6164
}
6265

Sources/NextcloudKit/NextcloudKit+AssistantV2.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ public extension NextcloudKit {
5050
if let result = try? decoder.decode(OCSTaskTypesResponse.self, from: data) {
5151
var types = result.ocs.data.types.map { (key, value) -> TaskTypeData in
5252
var taskType = value
53-
taskType.id = key
53+
taskType.id = taskType.id ?? key
5454
return taskType
5555
}
5656
types = types
57-
.filter { $0.inputShape?.input?.type == supportedTaskType && $0.outputShape?.output?.type == supportedTaskType }
58-
.sorted { ($0.id ?? "") < ($1.id ?? "") }
57+
.filter { $0.isSingleTextInputOutput(supportedTaskType: supportedTaskType) || $0.isChat() || $0.isTranslate() }
5958
options.queue.async {
6059
continuation.resume(returning: (account: account, types: types, responseData: response, error: .success))
6160
}

0 commit comments

Comments
 (0)