UnisKB/ui/src/api/application.ts

172 lines
3.7 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
/**
*
* @param {
"current_page": "string",
"page_size": "string",
"name": "string",
}
*/
const getApplication: (param: pageRequest) => Promise<Result<any>> = (param) => {
return get(
`${prefix}/${param.current_page}/${param.page_size}`,
param.name && { name: param.name }
)
}
2023-11-24 11:02:52 +00:00
/**
2023-11-27 09:06:39 +00:00
* Id
2023-11-24 11:02:52 +00:00
* @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)
}
/**
2023-11-28 10:53:22 +00:00
*
2023-11-24 11:02:52 +00:00
* @param
* chat_id: string
* {
"message": "string",
}
*/
2023-11-27 10:08:58 +00:00
const postChatMessage: (chat_id: string, message: string) => Promise<any> = (chat_id, message) => {
return postStream(`/api/${prefix}/chat_message/${chat_id}`, { message })
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
/**
* API_KEY
* @param applicaiton_id
*/
const getAPIKey: (applicaiton_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
applicaiton_id,
loading
) => {
return get(`${prefix}/${applicaiton_id}/api_key`, undefined, loading)
}
/**
* AccessToken
* @param applicaiton_id
*/
const getAccessToken: (applicaiton_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
applicaiton_id,
loading
) => {
2023-11-30 06:05:49 +00:00
return get(`${prefix}/${applicaiton_id}/access_token`, undefined, loading)
2023-11-29 09:34:45 +00:00
}
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-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,
getAPIKey,
getAccessToken
2023-11-23 09:20:19 +00:00
}