From a1acfdc2beacc30eb9c2290e01ba72af3c714e7f Mon Sep 17 00:00:00 2001 From: wangdan-fit2cloud Date: Mon, 27 Nov 2023 17:06:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AF=B9=E8=AF=9D=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/api/application.ts | 13 ++++++------ ui/src/components/ai-dialog/index.vue | 30 +++++++++++++++++++++------ ui/src/request/index.ts | 23 +++++++++++--------- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/ui/src/api/application.ts b/ui/src/api/application.ts index 289cf20e2..2a56d2c3e 100644 --- a/ui/src/api/application.ts +++ b/ui/src/api/application.ts @@ -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> = (param) => } /** - * 创建数据集 + * 创建应用 * @param 参数 * { "name": "string", @@ -48,9 +50,8 @@ const postApplication: (data: ApplicationFormType) => Promise> = (da return post(`${prefix}`, data) } -// 临时对话open /** - * 创建数据集 + * 获得临时回话Id * @param 参数 * { "model_id": "string", @@ -63,7 +64,7 @@ const postApplication: (data: ApplicationFormType) => Promise> = (da const postChatOpen: (data: ApplicationFormType) => Promise> = (data) => { return post(`${prefix}/chat/open`, data) } -// 临时对话open +// 对话 /** * 创建数据集 * @param 参数 @@ -76,7 +77,7 @@ const postChatMessage: (chat_id: string, message: string) => Promise chat_id, message ) => { - return post(`${prefix}/chat_message/${chat_id}`, { message }) + return postStream(`${prefix}/chat_message/${chat_id}`, { message }) } export default { getAllAppilcation, diff --git a/ui/src/components/ai-dialog/index.vue b/ui/src/components/ai-dialog/index.vue index 82ac6285e..2d9399119 100644 --- a/ui/src/components/ai-dialog/index.vue +++ b/ui/src/components/ai-dialog/index.vue @@ -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 + }) +}