Skip to content

Commit

Permalink
Enhance AIChat initialization logic for existing and new chats
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Feb 6, 2025
1 parent 423c3e1 commit f86c8a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ const AIChat = (props: AIChatProps) => {
if (!initialized && !chat_id) {
// if res is not null, create a new chat
const res = await getLatestChat(assistant_id)
if (res) handleNewChat(res)
res && !res.exist && handleNewChat(res) // new chat
res && res.exist && setChatId(res.chat_id) // existing chat
setInitialized(true)
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/xgen/layouts/components/Neo/hooks/useAIChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,8 @@ export default ({ assistant_id, chat_id, upload_options = {} }: Args) => {
/** Get the latest chat ID */
const getLatestChat = useMemoizedFn(async function (
assistant_id?: string
): Promise<{ chat_id: string; placeholder?: App.ChatPlaceholder } | null> {
if (!neo_api) return { chat_id: makeChatID(), placeholder: undefined }
): Promise<{ chat_id: string; placeholder?: App.ChatPlaceholder; exist?: boolean } | null> {
if (!neo_api) return { chat_id: makeChatID(), placeholder: undefined, exist: false }

const endpoint = `${neo_api}/chats/latest?token=${encodeURIComponent(getToken())}&assistant_id=${
assistant_id || ''
Expand Down Expand Up @@ -1017,8 +1017,8 @@ export default ({ assistant_id, chat_id, upload_options = {} }: Args) => {
setTitle(chatInfo.chat.title || (is_cn ? '未命名' : 'Untitled'))

// Set chat_id
global.setNeoChatId(chatInfo.chat.id)
return null
global.setNeoChatId(chatInfo.chat.chat_id)
return { chat_id: chatInfo.chat.chat_id, exist: true }
})

/** Update Chat **/
Expand Down

0 comments on commit f86c8a2

Please sign in to comment.