feat: 调整流输出为实验性质
This commit is contained in:
@@ -65,6 +65,7 @@ async function chatReply(
|
||||
}
|
||||
}
|
||||
|
||||
/** 实验性质的函数,用于处理聊天过程中的中间结果 */
|
||||
async function chatReplyProcess(
|
||||
message: string,
|
||||
lastContext?: { conversationId?: string; parentMessageId?: string },
|
||||
|
||||
@@ -26,6 +26,7 @@ router.post('/chat', async (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
/** 实验性质的函数,用于处理聊天过程中的中间结果 */
|
||||
router.post('/chat-process', async (req, res) => {
|
||||
res.setHeader('Content-type', 'application/octet-stream')
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ export function fetchChatAPI<T = any>(
|
||||
})
|
||||
}
|
||||
|
||||
/** 实验性质的函数,用于处理聊天过程中的中间结果 */
|
||||
export function fetchChatAPIProcess<T = any>(
|
||||
params: {
|
||||
prompt: string
|
||||
|
||||
@@ -36,7 +36,7 @@ const text = computed(() => {
|
||||
<template>
|
||||
<div :class="wrapClass">
|
||||
<template v-if="loading">
|
||||
<span class="w-[3px] h-[20px] block animate-blink" />
|
||||
<span class="w-[5px] h-[20px] block animate-blink" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<code v-if="includeCode(text)" v-highlight class="leading-relaxed" v-text="text" />
|
||||
|
||||
@@ -39,7 +39,7 @@ function handleRegenerate() {
|
||||
<div class="flex items-end mt-2">
|
||||
<Text :inversion="inversion" :error="error" :text="text" :loading="loading" />
|
||||
<button
|
||||
v-if="!inversion && !loading"
|
||||
v-if="!inversion"
|
||||
class="mb-2 ml-2 transition text-neutral-400 hover:text-neutral-800"
|
||||
@click="handleRegenerate"
|
||||
>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useChat } from './hooks/useChat'
|
||||
import { HoverButton, SvgIcon } from '@/components/common'
|
||||
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
||||
import { useChatStore } from '@/store'
|
||||
import { fetchChatAPIProcess } from '@/api'
|
||||
import { fetchChatAPI } from '@/api'
|
||||
|
||||
let controller = new AbortController()
|
||||
|
||||
@@ -80,39 +80,22 @@ async function onConversation() {
|
||||
)
|
||||
scrollToBottom()
|
||||
|
||||
let offset = 0
|
||||
try {
|
||||
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
||||
prompt: message,
|
||||
options,
|
||||
signal: controller.signal,
|
||||
onDownloadProgress: ({ event }) => {
|
||||
const xhr = event.target
|
||||
const { responseText } = xhr
|
||||
const chunk = responseText.substring(offset)
|
||||
offset = responseText.length
|
||||
try {
|
||||
const data = JSON.parse(chunk)
|
||||
updateChat(
|
||||
+uuid,
|
||||
dataSources.value.length - 1,
|
||||
{
|
||||
dateTime: new Date().toLocaleString(),
|
||||
text: data.text ?? '',
|
||||
inversion: false,
|
||||
error: false,
|
||||
loading: false,
|
||||
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
|
||||
requestOptions: { prompt: message, options: { ...options } },
|
||||
},
|
||||
)
|
||||
scrollToBottom()
|
||||
}
|
||||
catch (error) {
|
||||
//
|
||||
}
|
||||
const { data } = await fetchChatAPI<Chat.ConversationResponse>(message, options, controller.signal)
|
||||
updateChat(
|
||||
+uuid,
|
||||
dataSources.value.length - 1,
|
||||
{
|
||||
dateTime: new Date().toLocaleString(),
|
||||
text: data.text ?? '',
|
||||
inversion: false,
|
||||
error: false,
|
||||
loading: false,
|
||||
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
|
||||
requestOptions: { prompt: message, options: { ...options } },
|
||||
},
|
||||
})
|
||||
)
|
||||
scrollToBottom()
|
||||
}
|
||||
catch (error: any) {
|
||||
let errorMessage = error?.message ?? 'Something went wrong, please try again later.'
|
||||
@@ -136,7 +119,6 @@ async function onConversation() {
|
||||
scrollToBottom()
|
||||
}
|
||||
finally {
|
||||
offset = 0
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
@@ -172,41 +154,24 @@ async function onRegenerate(index: number) {
|
||||
},
|
||||
)
|
||||
|
||||
let offset = 0
|
||||
try {
|
||||
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
||||
prompt: message,
|
||||
options,
|
||||
signal: controller.signal,
|
||||
onDownloadProgress: ({ event }) => {
|
||||
const xhr = event.target
|
||||
const { responseText } = xhr
|
||||
const chunk = responseText.substring(offset)
|
||||
offset = responseText.length
|
||||
try {
|
||||
const data = JSON.parse(chunk)
|
||||
updateChat(
|
||||
+uuid,
|
||||
index,
|
||||
{
|
||||
dateTime: new Date().toLocaleString(),
|
||||
text: data.text ?? '',
|
||||
inversion: false,
|
||||
error: false,
|
||||
loading: false,
|
||||
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
|
||||
requestOptions: { prompt: message, ...options },
|
||||
},
|
||||
)
|
||||
}
|
||||
catch (error) {
|
||||
//
|
||||
}
|
||||
const { data } = await fetchChatAPI<Chat.ConversationResponse>(message, options, controller.signal)
|
||||
updateChat(
|
||||
+uuid,
|
||||
index,
|
||||
{
|
||||
dateTime: new Date().toLocaleString(),
|
||||
text: data.text ?? '',
|
||||
inversion: false,
|
||||
error: false,
|
||||
loading: false,
|
||||
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
|
||||
requestOptions: { prompt: message, ...options },
|
||||
},
|
||||
})
|
||||
)
|
||||
}
|
||||
catch (error: any) {
|
||||
let errorMessage = error?.message ?? 'Something went wrong, please try again later.'
|
||||
let errorMessage = 'Something went wrong, please try again later.'
|
||||
|
||||
if (error.message === 'canceled')
|
||||
errorMessage = 'Request canceled. Please try again.'
|
||||
@@ -227,7 +192,6 @@ async function onRegenerate(index: number) {
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
offset = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user