Skip to content

Commit 4745c44

Browse files
committed
filter SingleTextInputOutput
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent c87c1f5 commit 4745c44

2 files changed

Lines changed: 54 additions & 24 deletions

File tree

library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/GetTaskTypesRemoteOperationV2.kt

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@ import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
1919
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypes
2020
import org.apache.commons.httpclient.HttpStatus
2121

22+
/**
23+
* Returns a list of supported task types.
24+
*
25+
* Example JSON representation of one task type:
26+
* ```
27+
* {
28+
* "id": "core:text2text",
29+
* "name": "Free text to text prompt",
30+
* "description": "Runs an arbitrary prompt through a language model that returns a reply",
31+
* "inputShape": {
32+
* "input": {
33+
* "name": "Prompt",
34+
* "description": "Describe a task that you want the assistant to do or ask a question",
35+
* "type": "Text"
36+
* }
37+
* },
38+
* "outputShape": {
39+
* "output": {
40+
* "name": "Generated reply",
41+
* "description": "The generated text from the assistant",
42+
* "type": "Text"
43+
* }
44+
* }
45+
* }
46+
* ```
47+
*/
2248
class GetTaskTypesRemoteOperationV2 : OCSRemoteOperation<List<TaskTypeData>>() {
2349
private val supportedTaskType = "Text"
2450

@@ -36,21 +62,18 @@ class GetTaskTypesRemoteOperationV2 : OCSRemoteOperation<List<TaskTypeData>>() {
3662
getServerResponse(
3763
getMethod,
3864
object : TypeToken<ServerResponse<TaskTypes>>() {}
39-
)?.ocs?.data?.types
65+
)
4066

4167
val taskTypeList =
42-
response?.map { (key, value) ->
43-
value.copy(id = value.id ?: key)
44-
}
45-
46-
val supportedTaskTypeList =
47-
taskTypeList?.filter { taskType ->
48-
taskType.inputShape?.input?.type == supportedTaskType &&
49-
taskType.outputShape?.output?.type == supportedTaskType
50-
}
68+
response
69+
?.ocs
70+
?.data
71+
?.types
72+
?.map { (key, value) -> value.copy(id = value.id ?: key) }
73+
?.filter { taskType -> isSingleTextInputOutput(taskType) }
5174

5275
result = RemoteOperationResult(true, getMethod)
53-
result.setResultData(supportedTaskTypeList)
76+
result.resultData = taskTypeList
5477
} else {
5578
result = RemoteOperationResult(false, getMethod)
5679
}
@@ -67,6 +90,21 @@ class GetTaskTypesRemoteOperationV2 : OCSRemoteOperation<List<TaskTypeData>>() {
6790
return result
6891
}
6992

93+
private fun isSingleTextInputOutput(taskType: TaskTypeData): Boolean {
94+
val inputShape = taskType.inputShape
95+
val outputShape = taskType.outputShape
96+
97+
val hasOneTextInput =
98+
inputShape?.size == 1 &&
99+
inputShape.values.first().type == supportedTaskType
100+
101+
val hasOneTextOutput =
102+
outputShape?.size == 1 &&
103+
outputShape.values.first().type == supportedTaskType
104+
105+
return hasOneTextInput && hasOneTextOutput
106+
}
107+
70108
companion object {
71109
private val TAG = GetTaskTypesRemoteOperationV2::class.java.simpleName
72110
private const val DIRECT_ENDPOINT = "/ocs/v2.php/taskprocessing/tasktypes"

library/src/main/java/com/owncloud/android/lib/resources/assistant/v2/model/TaskTypes.kt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,12 @@ data class TaskTypeData(
1616
val id: String?,
1717
val name: String?,
1818
val description: String?,
19-
val inputShape: TaskInputShape?,
20-
val outputShape: TaskOutputShape?
21-
)
22-
23-
data class TaskInputShape(
24-
val input: Shape?
25-
)
26-
27-
data class TaskOutputShape(
28-
val output: Shape?
19+
val inputShape: Map<String, Shape>?,
20+
val outputShape: Map<String, Shape>?
2921
)
3022

3123
data class Shape(
32-
val name: String,
33-
val description: String,
34-
val type: String
24+
val name: String?,
25+
val description: String?,
26+
val type: String?
3527
)

0 commit comments

Comments
 (0)