feat: 对话框

This commit is contained in:
wangdan-fit2cloud 2023-11-27 17:06:39 +08:00
parent c719187067
commit a1acfdc2be
3 changed files with 44 additions and 22 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -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,