mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: 对话框
This commit is contained in:
parent
c719187067
commit
a1acfdc2be
|
|
@ -1,7 +1,9 @@
|
|||
import { Result } from '@/request/Result'
|
||||
import { get, post, del, put } from '@/request/index'
|
||||
import { get, post, postStream, del, put } from '@/request/index'
|
||||
import type { pageRequest } from '@/api/type/common'
|
||||
import type { ApplicationFormType } from '@/api/type/application'
|
||||
import { type Ref } from 'vue'
|
||||
|
||||
const prefix = '/application'
|
||||
|
||||
/**
|
||||
|
|
@ -28,7 +30,7 @@ const getApplication: (param: pageRequest) => Promise<Result<any>> = (param) =>
|
|||
}
|
||||
|
||||
/**
|
||||
* 创建数据集
|
||||
* 创建应用
|
||||
* @param 参数
|
||||
* {
|
||||
"name": "string",
|
||||
|
|
@ -48,9 +50,8 @@ const postApplication: (data: ApplicationFormType) => Promise<Result<any>> = (da
|
|||
return post(`${prefix}`, data)
|
||||
}
|
||||
|
||||
// 临时对话open
|
||||
/**
|
||||
* 创建数据集
|
||||
* 获得临时回话Id
|
||||
* @param 参数
|
||||
* {
|
||||
"model_id": "string",
|
||||
|
|
@ -63,7 +64,7 @@ const postApplication: (data: ApplicationFormType) => Promise<Result<any>> = (da
|
|||
const postChatOpen: (data: ApplicationFormType) => Promise<Result<any>> = (data) => {
|
||||
return post(`${prefix}/chat/open`, data)
|
||||
}
|
||||
// 临时对话open
|
||||
// 对话
|
||||
/**
|
||||
* 创建数据集
|
||||
* @param 参数
|
||||
|
|
@ -76,7 +77,7 @@ const postChatMessage: (chat_id: string, message: string) => Promise<Result<any>
|
|||
chat_id,
|
||||
message
|
||||
) => {
|
||||
return post(`${prefix}/chat_message/${chat_id}`, { message })
|
||||
return postStream(`${prefix}/chat_message/${chat_id}`, { message })
|
||||
}
|
||||
export default {
|
||||
getAllAppilcation,
|
||||
|
|
|
|||
|
|
@ -106,27 +106,45 @@ const inputValue = ref('')
|
|||
function quickProblemHandel(val: string) {
|
||||
inputValue.value = val
|
||||
}
|
||||
|
||||
/**
|
||||
* 对话
|
||||
*/
|
||||
function chatHandle() {
|
||||
loading.value = true
|
||||
const obj = {
|
||||
model_id: props.data.model_id,
|
||||
dataset_id_list: props.data.dataset_id_list,
|
||||
multiple_rounds_dialogue: props.data.multiple_rounds_dialogue,
|
||||
multiple_rounds_dialogue: props.data.multiple_rounds_dialogue
|
||||
}
|
||||
applicationApi
|
||||
.postChatOpen(obj)
|
||||
.then((res) => {
|
||||
loading.value = false
|
||||
chatMessage(res.data)
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// funcion chatMessage(chatId) {
|
||||
// postChatMessage
|
||||
// }
|
||||
function chatMessage(chatId: string) {
|
||||
applicationApi
|
||||
.postChatMessage(chatId, inputValue.value)
|
||||
.then((response) => {
|
||||
console.log(response.data)
|
||||
response.data.on('data', (chunk) => {
|
||||
console.log(chunk)
|
||||
// 处理流数据的逻辑
|
||||
})
|
||||
|
||||
// response.data.on('end', () => {
|
||||
// // 数据接收完成的逻辑
|
||||
// })
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.ai-dialog {
|
||||
|
|
|
|||
|
|
@ -39,13 +39,10 @@ instance.interceptors.request.use(
|
|||
instance.interceptors.response.use(
|
||||
(response: any) => {
|
||||
if (response.data) {
|
||||
if (response.data.code !== 200 && !(response.data instanceof Blob)) {
|
||||
if (response.status !== 200 && !(response.data instanceof Blob)) {
|
||||
MsgError(response.data.message)
|
||||
}
|
||||
}
|
||||
if (response.headers['content-type'] === 'application/octet-stream') {
|
||||
return response
|
||||
}
|
||||
return response
|
||||
},
|
||||
(err: any) => {
|
||||
|
|
@ -82,13 +79,10 @@ const promise: (
|
|||
request
|
||||
.then((response) => {
|
||||
// blob类型的返回状态是response.status
|
||||
if (
|
||||
response.data.code === 200 ||
|
||||
(response.data instanceof Blob && response.status === 200)
|
||||
) {
|
||||
resolve(response.data)
|
||||
if (response.status === 200) {
|
||||
resolve(response?.data || response)
|
||||
} else {
|
||||
reject(response.data)
|
||||
reject(response?.data || response)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
|
@ -169,6 +163,15 @@ export const del: (
|
|||
return promise(request({ url: url, method: 'delete', params, data }), loading)
|
||||
}
|
||||
|
||||
export const postStream: (
|
||||
url: string,
|
||||
data?: unknown,
|
||||
params?: unknown,
|
||||
loading?: NProgress | Ref<boolean>
|
||||
) => Promise<Result<any> | any> = (url, data, params, loading) => {
|
||||
return request({ url: url, method: 'post', data, params, responseType: 'stream' })
|
||||
}
|
||||
|
||||
export const exportExcel: (
|
||||
fileName: string,
|
||||
url: string,
|
||||
|
|
|
|||
Loading…
Reference in New Issue