filter SingleTextInputOutput

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk
2025-07-01 12:40:14 +02:00
committed by backportbot[bot]
parent 5fc4f1ee56
commit dccad58b0a
2 changed files with 54 additions and 24 deletions

View File

@ -19,6 +19,32 @@ import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypes
import org.apache.commons.httpclient.HttpStatus
/**
* Returns a list of supported task types.
*
* Example JSON representation of one task type:
* ```
* {
* "id": "core:text2text",
* "name": "Free text to text prompt",
* "description": "Runs an arbitrary prompt through a language model that returns a reply",
* "inputShape": {
* "input": {
* "name": "Prompt",
* "description": "Describe a task that you want the assistant to do or ask a question",
* "type": "Text"
* }
* },
* "outputShape": {
* "output": {
* "name": "Generated reply",
* "description": "The generated text from the assistant",
* "type": "Text"
* }
* }
* }
* ```
*/
class GetTaskTypesRemoteOperationV2 : OCSRemoteOperation<List<TaskTypeData>>() {
private val supportedTaskType = "Text"
@ -36,21 +62,18 @@ class GetTaskTypesRemoteOperationV2 : OCSRemoteOperation<List<TaskTypeData>>() {
getServerResponse(
getMethod,
object : TypeToken<ServerResponse<TaskTypes>>() {}
)?.ocs?.data?.types
)
val taskTypeList =
response?.map { (key, value) ->
value.copy(id = value.id ?: key)
}
val supportedTaskTypeList =
taskTypeList?.filter { taskType ->
taskType.inputShape?.input?.type == supportedTaskType &&
taskType.outputShape?.output?.type == supportedTaskType
}
response
?.ocs
?.data
?.types
?.map { (key, value) -> value.copy(id = value.id ?: key) }
?.filter { taskType -> isSingleTextInputOutput(taskType) }
result = RemoteOperationResult(true, getMethod)
result.setResultData(supportedTaskTypeList)
result.resultData = taskTypeList
} else {
result = RemoteOperationResult(false, getMethod)
}
@ -67,6 +90,21 @@ class GetTaskTypesRemoteOperationV2 : OCSRemoteOperation<List<TaskTypeData>>() {
return result
}
private fun isSingleTextInputOutput(taskType: TaskTypeData): Boolean {
val inputShape = taskType.inputShape
val outputShape = taskType.outputShape
val hasOneTextInput =
inputShape?.size == 1 &&
inputShape.values.first().type == supportedTaskType
val hasOneTextOutput =
outputShape?.size == 1 &&
outputShape.values.first().type == supportedTaskType
return hasOneTextInput && hasOneTextOutput
}
companion object {
private val TAG = GetTaskTypesRemoteOperationV2::class.java.simpleName
private const val DIRECT_ENDPOINT = "/ocs/v2.php/taskprocessing/tasktypes"

View File

@ -16,20 +16,12 @@ data class TaskTypeData(
val id: String?,
val name: String?,
val description: String?,
val inputShape: TaskInputShape?,
val outputShape: TaskOutputShape?
)
data class TaskInputShape(
val input: Shape?
)
data class TaskOutputShape(
val output: Shape?
val inputShape: Map<String, Shape>?,
val outputShape: Map<String, Shape>?
)
data class Shape(
val name: String,
val description: String,
val type: String
val name: String?,
val description: String?,
val type: String?
)