智能体列表,全部
This commit is contained in:
@@ -7,35 +7,48 @@ import com.aiosman.ravenow.data.AgentService
|
||||
import com.aiosman.ravenow.data.ServiceException
|
||||
import com.aiosman.ravenow.data.UploadImage
|
||||
import com.aiosman.ravenow.data.api.ApiClient
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import retrofit2.http.Part
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* 智能体
|
||||
*/
|
||||
|
||||
suspend fun createAgent(
|
||||
title: String,
|
||||
desc: String,
|
||||
avatar: UploadImage? = null,
|
||||
workflowId:Int = 1,
|
||||
isPublic:Boolean = true,
|
||||
breakMode:Boolean = false,
|
||||
useWorkflow:Boolean = true,
|
||||
): AgentEntity {
|
||||
val textTitle = title.toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
val textDesc = desc.toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
val workflowIdRequestBody = workflowId.toString().toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
val isPublicRequestBody = isPublic.toString().toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
val breakModeRequestBody = breakMode.toString().toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
val useWorkflowRequestBody = useWorkflow.toString().toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
val workflowInputsValue = "{\"si\":\"$desc\"}"
|
||||
val workflowInputsRequestBody = workflowInputsValue.toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
|
||||
val avatarField: MultipartBody.Part? = avatar?.let {
|
||||
createMultipartBody(it.file, it.filename, "avatar")
|
||||
}
|
||||
val response = ApiClient.api.createAgent(avatarField, textTitle ,textDesc)
|
||||
val response = ApiClient.api.createAgent(avatarField, textTitle ,textDesc,textDesc,workflowIdRequestBody,isPublicRequestBody,breakModeRequestBody,useWorkflowRequestBody,workflowInputsRequestBody)
|
||||
val body = response.body()?.data ?: throw ServiceException("Failed to create agent")
|
||||
return body.toAgentEntity()
|
||||
|
||||
}
|
||||
|
||||
data class AgentEntity(
|
||||
val author: String,
|
||||
//val author: String,
|
||||
val avatar: String,
|
||||
val breakMode: Boolean,
|
||||
val createdAt: String,
|
||||
@@ -43,7 +56,7 @@ data class AgentEntity(
|
||||
val id: Int,
|
||||
val isPublic: Boolean,
|
||||
val openId: String,
|
||||
val profile: ProfileEntity,
|
||||
//val profile: ProfileEntity,
|
||||
val title: String,
|
||||
val updatedAt: String,
|
||||
val useCount: Int
|
||||
@@ -80,8 +93,8 @@ class AgentLoader : DataLoader<AgentEntity,AgentLoaderExtraArgs>() {
|
||||
)
|
||||
val data = result.body()?.let {
|
||||
ListContainer(
|
||||
list = it.list.map { it.toAgentEntity()},
|
||||
total = it.total,
|
||||
list = it.data.list.map { it.toAgentEntity()},
|
||||
total = it.data.total,
|
||||
page = page,
|
||||
pageSize = pageSize
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user