-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1599 from nextcloud/update-assistant-api
Update Assistant API
- Loading branch information
Showing
16 changed files
with
507 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]> | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
package com.owncloud.android.lib.resources.assistant | ||
package com.owncloud.android.lib.resources.assistant.v1 | ||
|
||
import com.owncloud.android.AbstractIT | ||
import com.owncloud.android.lib.resources.status.NextcloudVersion | ||
|
@@ -15,15 +15,15 @@ import junit.framework.TestCase.assertTrue | |
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class AssistantIT : AbstractIT() { | ||
class AssistantV1Tests : AbstractIT() { | ||
@Before | ||
fun before() { | ||
testOnlyOnServer(NextcloudVersion.nextcloud_28) | ||
} | ||
|
||
@Test | ||
fun testGetTaskTypes() { | ||
val result = GetTaskTypesRemoteOperation().execute(nextcloudClient) | ||
val result = GetTaskTypesRemoteOperationV1().execute(nextcloudClient) | ||
assertTrue(result.isSuccess) | ||
|
||
val taskTypes = result.resultData.types | ||
|
@@ -32,16 +32,16 @@ class AssistantIT : AbstractIT() { | |
|
||
@Test | ||
fun testGetTaskList() { | ||
var result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient) | ||
var result = GetTaskListRemoteOperationV1("assistant").execute(nextcloudClient) | ||
assertTrue(result.isSuccess) | ||
assertTrue(result.resultData.tasks.isEmpty()) | ||
|
||
// create one task | ||
val input = "Give me some random output for test purpose" | ||
val type = "OCP\\TextProcessing\\FreePromptTaskType" | ||
assertTrue(CreateTaskRemoteOperation(input, type).execute(nextcloudClient).isSuccess) | ||
assertTrue(CreateTaskRemoteOperationV1(input, type).execute(nextcloudClient).isSuccess) | ||
|
||
result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient) | ||
result = GetTaskListRemoteOperationV1("assistant").execute(nextcloudClient) | ||
assertTrue(result.isSuccess) | ||
|
||
val taskList = result.resultData.tasks | ||
|
@@ -53,18 +53,18 @@ class AssistantIT : AbstractIT() { | |
// create one task | ||
val input = "Give me some random output for test purpose" | ||
val type = "OCP\\TextProcessing\\FreePromptTaskType" | ||
assertTrue(CreateTaskRemoteOperation(input, type).execute(nextcloudClient).isSuccess) | ||
assertTrue(CreateTaskRemoteOperationV1(input, type).execute(nextcloudClient).isSuccess) | ||
|
||
var result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient) | ||
var result = GetTaskListRemoteOperationV1("assistant").execute(nextcloudClient) | ||
assertTrue(result.isSuccess) | ||
|
||
val tasks = result.resultData.tasks | ||
val countBefore = tasks.size | ||
|
||
// delete | ||
assertTrue(DeleteTaskRemoteOperation(tasks.first().id).execute(nextcloudClient).isSuccess) | ||
assertTrue(DeleteTaskRemoteOperationV1(tasks.first().id).execute(nextcloudClient).isSuccess) | ||
|
||
result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient) | ||
result = GetTaskListRemoteOperationV1("assistant").execute(nextcloudClient) | ||
assertTrue(result.isSuccess) | ||
|
||
assertEquals(countBefore - 1, result.resultData.tasks.size) | ||
|
100 changes: 100 additions & 0 deletions
100
.../src/androidTest/java/com/owncloud/android/lib/resources/assistant/v2/AssistantV2Tests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
package com.owncloud.android.lib.resources.assistant.v2 | ||
|
||
import com.owncloud.android.AbstractIT | ||
import com.owncloud.android.lib.resources.assistant.v2.model.TaskInputShape | ||
import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutputShape | ||
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData | ||
import com.owncloud.android.lib.resources.status.NextcloudVersion | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class AssistantV2Tests : AbstractIT() { | ||
@Before | ||
fun before() { | ||
testOnlyOnServer(NextcloudVersion.nextcloud_30) | ||
} | ||
|
||
private fun getTaskType(): TaskTypeData { | ||
return TaskTypeData( | ||
"core:text2text", | ||
"Free text to text prompt", | ||
"Runs an arbitrary prompt through a language model that returns a reply", | ||
listOf( | ||
TaskInputShape( | ||
"Prompt", | ||
"Describe a task that you want the assistant to do or ask a question", | ||
"Text" | ||
) | ||
), | ||
listOf( | ||
TaskOutputShape( | ||
"Generated reply", | ||
"The generated text from the assistant", | ||
"Text" | ||
) | ||
) | ||
) | ||
} | ||
|
||
private fun getSelectedTaskType(): String = "core:text2text" | ||
|
||
@Test | ||
fun testGetTaskTypes() { | ||
val result = GetTaskTypesRemoteOperationV2().execute(nextcloudClient) | ||
assertTrue(result.isSuccess) | ||
} | ||
|
||
@Test | ||
fun testGetTaskList() { | ||
val taskType = getTaskType() | ||
val selectedTaskType = getSelectedTaskType() | ||
|
||
var result = GetTaskListRemoteOperationV2(selectedTaskType).execute(nextcloudClient) | ||
assertTrue(result.isSuccess) | ||
assertTrue(result.resultData.tasks.isEmpty()) | ||
|
||
// create one task | ||
val input = "Give me some random output for test purpose" | ||
assertTrue(CreateTaskRemoteOperationV2(input, taskType).execute(nextcloudClient).isSuccess) | ||
|
||
result = GetTaskListRemoteOperationV2(selectedTaskType).execute(nextcloudClient) | ||
assertTrue(result.isSuccess) | ||
|
||
val taskList = result.resultData.tasks | ||
assertTrue(taskList.isNotEmpty()) | ||
} | ||
|
||
@Test | ||
fun testDeleteTask() { | ||
// create one task | ||
val input = "Give me some random output for test purpose" | ||
val taskType = getTaskType() | ||
val selectedTaskType = getSelectedTaskType() | ||
|
||
assertTrue(CreateTaskRemoteOperationV2(input, taskType).execute(nextcloudClient).isSuccess) | ||
|
||
var result = GetTaskListRemoteOperationV2(selectedTaskType).execute(nextcloudClient) | ||
assertTrue(result.isSuccess) | ||
|
||
val tasks = result.resultData.tasks | ||
val countBefore = tasks.size | ||
|
||
// delete | ||
assertTrue(DeleteTaskRemoteOperationV2(tasks.first().id).execute(nextcloudClient).isSuccess) | ||
|
||
result = GetTaskListRemoteOperationV2(selectedTaskType).execute(nextcloudClient) | ||
assertTrue(result.isSuccess) | ||
|
||
assertEquals(countBefore - 1, result.resultData.tasks.size) | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskList.kt
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/model/TaskList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
package com.owncloud.android.lib.resources.assistant.v1.model | ||
|
||
data class TaskList( | ||
var tasks: List<Task> | ||
) | ||
|
||
data class Task( | ||
val id: Long, | ||
val type: String?, | ||
val status: Long?, | ||
val userId: String?, | ||
val appId: String?, | ||
val input: String?, | ||
val output: String?, | ||
val identifier: String?, | ||
val completionExpectedAt: String? = null | ||
) | ||
|
||
fun TaskList.toV2(): com.owncloud.android.lib.resources.assistant.v2.model.TaskList { | ||
return com.owncloud.android.lib.resources.assistant.v2.model.TaskList( | ||
tasks = | ||
tasks.map { task -> | ||
com.owncloud.android.lib.resources.assistant.v2.model.Task( | ||
id = task.id, | ||
type = task.type, | ||
status = task.status?.toString(), | ||
userId = task.userId, | ||
appId = task.appId, | ||
input = | ||
task.input?.let { | ||
com.owncloud.android.lib.resources.assistant.v2.model.TaskInput(input = it) | ||
}, | ||
output = | ||
task.output?.let { | ||
com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput(output = it) | ||
}, | ||
completionExpectedAt = task.completionExpectedAt?.toIntOrNull(), | ||
progress = null, | ||
lastUpdated = null, | ||
scheduledAt = null, | ||
endedAt = null | ||
) | ||
} | ||
) | ||
} |
Oops, something went wrong.