fix: some error

main
ChenZhaoYu 2 years ago
parent 15f3aac88e
commit 40fa028408

@ -25,7 +25,7 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
try { try {
const { prompt, options = {}, systemMessage } = req.body as RequestProps const { prompt, options = {}, systemMessage } = req.body as RequestProps
let firstChunk = true let firstChunk = true
const finalResponse = await chatReplyProcess({ await chatReplyProcess({
message: prompt, message: prompt,
lastContext: options, lastContext: options,
process: (chat: ChatMessage) => { process: (chat: ChatMessage) => {
@ -34,7 +34,6 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
}, },
systemMessage, systemMessage,
}) })
res.write(firstChunk ? JSON.stringify(finalResponse) : `\n${JSON.stringify(finalResponse)}`)
} }
catch (error) { catch (error) {
res.write(JSON.stringify(error)) res.write(JSON.stringify(error))

@ -25,12 +25,6 @@ function http<T = any>(
const successHandler = (res: AxiosResponse<Response<T>>) => { const successHandler = (res: AxiosResponse<Response<T>>) => {
const authStore = useAuthStore() const authStore = useAuthStore()
if (typeof res.data === 'string') {
const lastIndex = (res.data as string).lastIndexOf('\n')
if (lastIndex !== -1)
res.data = JSON.parse((res.data as string).substring(lastIndex))
}
if (res.data.status === 'Success' || typeof res.data === 'string') if (res.data.status === 'Success' || typeof res.data === 'string')
return res.data return res.data

@ -109,7 +109,7 @@ async function onConversation() {
try { try {
let lastText = '' let lastText = ''
const fetchChatAPIOnce = async () => { const fetchChatAPIOnce = async () => {
const { data } = await fetchChatAPIProcess<Chat.ConversationResponse>({ await fetchChatAPIProcess<Chat.ConversationResponse>({
prompt: message, prompt: message,
options, options,
signal: controller.signal, signal: controller.signal,
@ -147,23 +147,11 @@ async function onConversation() {
scrollToBottomIfAtBottom() scrollToBottomIfAtBottom()
} }
catch (error) { catch (error) {
// //
} }
}, },
}) })
updateChat( updateChatSome(+uuid, dataSources.value.length - 1, { loading: false })
+uuid,
dataSources.value.length - 1,
{
dateTime: new Date().toLocaleString(),
text: lastText + data.text ?? '',
inversion: false,
error: false,
loading: false,
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
requestOptions: { prompt: message, options: { ...options } },
},
)
} }
await fetchChatAPIOnce() await fetchChatAPIOnce()
@ -252,7 +240,7 @@ async function onRegenerate(index: number) {
try { try {
let lastText = '' let lastText = ''
const fetchChatAPIOnce = async () => { const fetchChatAPIOnce = async () => {
const { data } = await fetchChatAPIProcess<Chat.ConversationResponse>({ await fetchChatAPIProcess<Chat.ConversationResponse>({
prompt: message, prompt: message,
options, options,
signal: controller.signal, signal: controller.signal,
@ -292,19 +280,7 @@ async function onRegenerate(index: number) {
} }
}, },
}) })
updateChat( updateChatSome(+uuid, index, { loading: false })
+uuid,
index,
{
dateTime: new Date().toLocaleString(),
text: lastText + data.text ?? '',
inversion: false,
error: false,
loading: false,
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
requestOptions: { prompt: message, ...options },
},
)
} }
await fetchChatAPIOnce() await fetchChatAPIOnce()
} }
@ -499,11 +475,7 @@ onUnmounted(() => {
@toggle-using-context="toggleUsingContext" @toggle-using-context="toggleUsingContext"
/> />
<main class="flex-1 overflow-hidden"> <main class="flex-1 overflow-hidden">
<div <div id="scrollRef" ref="scrollRef" class="h-full overflow-hidden overflow-y-auto">
id="scrollRef"
ref="scrollRef"
class="h-full overflow-hidden overflow-y-auto"
>
<div <div
id="image-wrapper" id="image-wrapper"
class="w-full max-w-screen-xl m-auto dark:bg-[#101014]" class="w-full max-w-screen-xl m-auto dark:bg-[#101014]"

Loading…
Cancel
Save