UnisKB/ui/src/api/application.ts

248 lines
5.2 KiB
TypeScript
Raw Normal View History

2023-11-22 10:37:08 +00:00
import { Result } from '@/request/Result'
2023-11-27 09:06:39 +00:00
import { get, post, postStream, del, put } from '@/request/index'
2023-11-23 09:20:19 +00:00
import type { pageRequest } from '@/api/type/common'
2023-11-24 11:02:52 +00:00
import type { ApplicationFormType } from '@/api/type/application'
2023-11-27 09:06:39 +00:00
import { type Ref } from 'vue'
2023-11-22 10:37:08 +00:00
const prefix = '/application'
2023-11-24 11:02:52 +00:00
/**
*
* @param
*/
const getAllAppilcation: () => Promise<Result<any[]>> = () => {
return get(`${prefix}`)
}
2023-11-23 09:20:19 +00:00
/**
*
2023-12-06 11:09:54 +00:00
* page {
"current_page": "string",
"page_size": "string",
}
* param {
"name": "string",
}
2023-11-23 09:20:19 +00:00
*/
2023-12-06 11:09:54 +00:00
const getApplication: (
page: pageRequest,
param: any,
loading?: Ref<boolean>
) => Promise<Result<any>> = (page, param, loading) => {
return get(`${prefix}/${page.current_page}/${page.page_size}`, param, loading)
2023-11-23 09:20:19 +00:00
}
2023-11-24 11:02:52 +00:00
2023-11-28 10:53:22 +00:00
/**
*
* @param
* {
"name": "string",
"desc": "string",
"model_id": "string",
"multiple_rounds_dialogue": true,
"prologue": "string",
"example": [
"string"
],
"dataset_id_list": [
"string"
]
}
*/
2023-11-29 03:25:14 +00:00
const postApplication: (
data: ApplicationFormType,
loading?: Ref<boolean>
) => Promise<Result<any>> = (data, loading) => {
2023-11-28 10:53:22 +00:00
return post(`${prefix}`, data, undefined, loading)
}
2023-11-29 07:42:48 +00:00
/**
*
* @param
* {
"name": "string",
"desc": "string",
"model_id": "string",
"multiple_rounds_dialogue": true,
"prologue": "string",
"example": [
"string"
],
"dataset_id_list": [
"string"
]
}
*/
const putApplication: (
applicaiton_id: String,
data: ApplicationFormType,
loading?: Ref<boolean>
) => Promise<Result<any>> = (applicaiton_id, data, loading) => {
return put(`${prefix}/${applicaiton_id}`, data, undefined, loading)
}
2023-11-29 03:25:14 +00:00
/**
*
* @param applicaiton_id
*/
const delApplication: (applicaiton_id: String) => Promise<Result<boolean>> = (applicaiton_id) => {
return del(`${prefix}/${applicaiton_id}`)
}
/**
*
* @param applicaiton_id
*/
2023-11-29 07:42:48 +00:00
const getApplicationDetail: (
applicaiton_id: string,
loading?: Ref<boolean>
) => Promise<Result<any>> = (applicaiton_id, loading) => {
return get(`${prefix}/${applicaiton_id}`, undefined, loading)
}
/**
* 使
* @param applicaiton_id
*/
const getApplicationDataset: (
applicaiton_id: string,
loading?: Ref<boolean>
) => Promise<Result<any>> = (applicaiton_id, loading) => {
return get(`${prefix}/${applicaiton_id}/list_dataset`, undefined, loading)
2023-11-29 03:25:14 +00:00
}
2023-11-29 09:34:45 +00:00
/**
2023-12-08 08:55:29 +00:00
* AccessToken
2023-11-29 09:34:45 +00:00
* @param applicaiton_id
*/
2023-12-08 08:55:29 +00:00
const getAccessToken: (applicaiton_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
2023-11-29 09:34:45 +00:00
applicaiton_id,
loading
) => {
2023-12-08 08:55:29 +00:00
return get(`${prefix}/${applicaiton_id}/access_token`, undefined, loading)
2023-11-29 09:34:45 +00:00
}
/**
2023-12-08 08:55:29 +00:00
* AccessToken
2023-11-29 09:34:45 +00:00
* @param applicaiton_id
2023-12-08 08:55:29 +00:00
* data {
* "is_active": true
* }
2023-11-29 09:34:45 +00:00
*/
2023-12-08 08:55:29 +00:00
const putAccessToken: (
applicaiton_id: string,
data: any,
loading?: Ref<boolean>
) => Promise<Result<any>> = (applicaiton_id, data, loading) => {
return put(`${prefix}/${applicaiton_id}/access_token`, data, undefined, loading)
2023-11-29 09:34:45 +00:00
}
2023-11-30 10:50:42 +00:00
/**
*
* @param
{
"access_token": "string"
}
*/
const postAppAuthentication: (access_token: string, loading?: Ref<boolean>) => Promise<any> = (
access_token,
loading
) => {
return post(`${prefix}/authentication`, { access_token }, undefined, loading)
}
/**
*
* @param
{
"access_token": "string"
}
*/
const getProfile: (loading?: Ref<boolean>) => Promise<any> = (loading) => {
return get(`${prefix}/profile`, undefined, loading)
}
/**
* Id
* @param
* {
"model_id": "string",
"multiple_rounds_dialogue": true,
"dataset_id_list": [
"string"
]
}
*/
const postChatOpen: (data: ApplicationFormType) => Promise<Result<any>> = (data) => {
return post(`${prefix}/chat/open`, data)
}
/**
* Id
* @param
* {
"model_id": "string",
"multiple_rounds_dialogue": true,
"dataset_id_list": [
"string"
]
}
*/
const getChatOpen: (applicaiton_id: String) => Promise<Result<any>> = (applicaiton_id) => {
return get(`${prefix}/${applicaiton_id}/chat/open`)
}
/**
*
* @param
* chat_id: string
* {
"message": "string",
}
*/
const postChatMessage: (chat_id: string, message: string) => Promise<any> = (chat_id, message) => {
2023-12-12 03:25:54 +00:00
return postStream(`/api${prefix}/chat_message/${chat_id}`, { message })
2023-11-30 10:50:42 +00:00
}
2023-12-01 10:21:49 +00:00
/**
*
* @param
* application_id : string; chat_id : string; chat_record_id : string
* {
"vote_status": "string", // -1 0 1
}
*/
const putChatVote: (
application_id: string,
chat_id: string,
chat_record_id: string,
vote_status: string,
loading?: Ref<boolean>
) => Promise<any> = (application_id, chat_id, chat_record_id, vote_status, loading) => {
return put(
`${prefix}/${application_id}/chat/${chat_id}/chat_record/${chat_record_id}/vote`,
{
vote_status
},
undefined,
loading
)
}
2023-11-23 09:20:19 +00:00
export default {
2023-11-24 11:02:52 +00:00
getAllAppilcation,
getApplication,
postApplication,
2023-11-29 07:42:48 +00:00
putApplication,
2023-11-24 11:02:52 +00:00
postChatOpen,
2023-11-30 10:50:42 +00:00
getChatOpen,
2023-11-29 03:25:14 +00:00
postChatMessage,
delApplication,
2023-11-29 07:42:48 +00:00
getApplicationDetail,
2023-11-29 09:34:45 +00:00
getApplicationDataset,
2023-11-30 10:50:42 +00:00
getAccessToken,
2023-12-08 08:55:29 +00:00
putAccessToken,
2023-11-30 10:50:42 +00:00
postAppAuthentication,
2023-12-01 10:21:49 +00:00
getProfile,
2023-12-06 11:09:54 +00:00
putChatVote
2023-11-23 09:20:19 +00:00
}