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 { 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 { pageRequest } from '@/api/type/common'
import type { ApplicationFormType } from '@/api/type/application' import type { ApplicationFormType } from '@/api/type/application'
import { type Ref } from 'vue'
const prefix = '/application' const prefix = '/application'
/** /**
@ -28,7 +30,7 @@ const getApplication: (param: pageRequest) => Promise<Result<any>> = (param) =>
} }
/** /**
* *
* @param * @param
* { * {
"name": "string", "name": "string",
@ -48,9 +50,8 @@ const postApplication: (data: ApplicationFormType) => Promise<Result<any>> = (da
return post(`${prefix}`, data) return post(`${prefix}`, data)
} }
// 临时对话open
/** /**
* * Id
* @param * @param
* { * {
"model_id": "string", "model_id": "string",
@ -63,7 +64,7 @@ const postApplication: (data: ApplicationFormType) => Promise<Result<any>> = (da
const postChatOpen: (data: ApplicationFormType) => Promise<Result<any>> = (data) => { const postChatOpen: (data: ApplicationFormType) => Promise<Result<any>> = (data) => {
return post(`${prefix}/chat/open`, data) return post(`${prefix}/chat/open`, data)
} }
// 临时对话open // 对话
/** /**
* *
* @param * @param
@ -76,7 +77,7 @@ const postChatMessage: (chat_id: string, message: string) => Promise<Result<any>
chat_id, chat_id,
message message
) => { ) => {
return post(`${prefix}/chat_message/${chat_id}`, { message }) return postStream(`${prefix}/chat_message/${chat_id}`, { message })
} }
export default { export default {
getAllAppilcation, getAllAppilcation,

View File

@ -106,27 +106,45 @@ const inputValue = ref('')
function quickProblemHandel(val: string) { function quickProblemHandel(val: string) {
inputValue.value = val inputValue.value = val
} }
/**
* 对话
*/
function chatHandle() { function chatHandle() {
loading.value = true loading.value = true
const obj = { const obj = {
model_id: props.data.model_id, model_id: props.data.model_id,
dataset_id_list: props.data.dataset_id_list, 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 applicationApi
.postChatOpen(obj) .postChatOpen(obj)
.then((res) => { .then((res) => {
loading.value = false chatMessage(res.data)
}) })
.catch(() => { .catch(() => {
loading.value = false loading.value = false
}) })
} }
// funcion chatMessage(chatId) { function chatMessage(chatId: string) {
// postChatMessage 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> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.ai-dialog { .ai-dialog {

View File

@ -39,13 +39,10 @@ instance.interceptors.request.use(
instance.interceptors.response.use( instance.interceptors.response.use(
(response: any) => { (response: any) => {
if (response.data) { if (response.data) {
if (response.data.code !== 200 && !(response.data instanceof Blob)) { if (response.status !== 200 && !(response.data instanceof Blob)) {
MsgError(response.data.message) MsgError(response.data.message)
} }
} }
if (response.headers['content-type'] === 'application/octet-stream') {
return response
}
return response return response
}, },
(err: any) => { (err: any) => {
@ -82,13 +79,10 @@ const promise: (
request request
.then((response) => { .then((response) => {
// blob类型的返回状态是response.status // blob类型的返回状态是response.status
if ( if (response.status === 200) {
response.data.code === 200 || resolve(response?.data || response)
(response.data instanceof Blob && response.status === 200)
) {
resolve(response.data)
} else { } else {
reject(response.data) reject(response?.data || response)
} }
}) })
.catch((error) => { .catch((error) => {
@ -169,6 +163,15 @@ export const del: (
return promise(request({ url: url, method: 'delete', params, data }), loading) 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: ( export const exportExcel: (
fileName: string, fileName: string,
url: string, url: string,