Skip to content

Commit

Permalink
🐛 fix: fix multi-turns tools calling (lobehub#4789)
Browse files Browse the repository at this point in the history
* 🐛 fix: fix tools calling

* 🐛 fix: fix tools calling
  • Loading branch information
arvinxx authored Nov 25, 2024
1 parent b57d996 commit 9d8845f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/store/chat/slices/aiChat/actions/generateAIChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const generateAIChat: StateCreator<
}

// Get the current messages to generate AI response
const messages = chatSelectors.mainDisplayChats(get());
const messages = chatSelectors.activeBaseChats(get());
const userFiles = chatSelectors.currentUserFiles(get()).map((f) => f.id);

await internal_coreProcessMessage(messages, id, {
Expand Down Expand Up @@ -484,7 +484,7 @@ export const generateAIChat: StateCreator<

internal_resendMessage: async (messageId, traceId) => {
// 1. 构造所有相关的历史记录
const chats = chatSelectors.mainDisplayChats(get());
const chats = chatSelectors.activeBaseChats(get());

const currentIndex = chats.findIndex((c) => c.id === messageId);
if (currentIndex < 0) return;
Expand Down
13 changes: 13 additions & 0 deletions src/store/chat/slices/message/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ describe('chatSelectors', () => {
});
});

describe('mainDisplayChats', () => {
it('should return existing messages except tool message', () => {
const state = merge(initialStore, {
messagesMap: {
[messageMapKey('someActiveId')]: mockMessages,
},
activeId: 'someActiveId',
});
const chats = chatSelectors.mainDisplayChats(state);
expect(chats).toEqual(mockedChats.slice(0, 2));
});
});

describe('chatsMessageString', () => {
it('should concatenate the contents of all messages returned by currentChatsWithHistoryConfig', () => {
// Prepare a state with a few messages
Expand Down

0 comments on commit 9d8845f

Please sign in to comment.