Skip to content

Commit

Permalink
fix: some error
Browse files Browse the repository at this point in the history
  • Loading branch information
Chanzhaoyu committed Mar 31, 2023
1 parent 15f3aac commit 40fa028
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 42 deletions.
3 changes: 1 addition & 2 deletions service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
try {
const { prompt, options = {}, systemMessage } = req.body as RequestProps
let firstChunk = true
const finalResponse = await chatReplyProcess({
await chatReplyProcess({
message: prompt,
lastContext: options,
process: (chat: ChatMessage) => {
Expand All @@ -34,7 +34,6 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
},
systemMessage,
})
res.write(firstChunk ? JSON.stringify(finalResponse) : `\n${JSON.stringify(finalResponse)}`)
}
catch (error) {
res.write(JSON.stringify(error))
Expand Down
6 changes: 0 additions & 6 deletions src/utils/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ function http<T = any>(
const successHandler = (res: AxiosResponse<Response<T>>) => {
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')
return res.data

Expand Down
40 changes: 6 additions & 34 deletions src/views/chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async function onConversation() {
try {
let lastText = ''
const fetchChatAPIOnce = async () => {
const { data } = await fetchChatAPIProcess<Chat.ConversationResponse>({
await fetchChatAPIProcess<Chat.ConversationResponse>({
prompt: message,
options,
signal: controller.signal,
Expand Down Expand Up @@ -147,23 +147,11 @@ async function onConversation() {
scrollToBottomIfAtBottom()
}
catch (error) {
//
//
}
},
})
updateChat(
+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 } },
},
)
updateChatSome(+uuid, dataSources.value.length - 1, { loading: false })
}
await fetchChatAPIOnce()
Expand Down Expand Up @@ -252,7 +240,7 @@ async function onRegenerate(index: number) {
try {
let lastText = ''
const fetchChatAPIOnce = async () => {
const { data } = await fetchChatAPIProcess<Chat.ConversationResponse>({
await fetchChatAPIProcess<Chat.ConversationResponse>({
prompt: message,
options,
signal: controller.signal,
Expand Down Expand Up @@ -292,19 +280,7 @@ async function onRegenerate(index: number) {
}
},
})
updateChat(
+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 },
},
)
updateChatSome(+uuid, index, { loading: false })
}
await fetchChatAPIOnce()
}
Expand Down Expand Up @@ -499,11 +475,7 @@ onUnmounted(() => {
@toggle-using-context="toggleUsingContext"
/>
<main class="flex-1 overflow-hidden">
<div
id="scrollRef"
ref="scrollRef"
class="h-full overflow-hidden overflow-y-auto"
>
<div id="scrollRef" ref="scrollRef" class="h-full overflow-hidden overflow-y-auto">
<div
id="image-wrapper"
class="w-full max-w-screen-xl m-auto dark:bg-[#101014]"
Expand Down

0 comments on commit 40fa028

Please sign in to comment.