Skip to content

Commit

Permalink
🐛 fix: 修正total token 计算不正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jul 22, 2023
1 parent 6cb4828 commit 17815c6
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/store/session/slices/chat/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,24 @@ const systemRoleSel = (s: SessionStore): string => {
return config.systemRole;
};

const totalTokens = (s: SessionStore): number[] => {
const chats = currentChats(s);
return encode(chats.map((m) => m.content).join(''));
};

const systemRoleTokens = (s: SessionStore): number[] => {
const systemRole = systemRoleSel(s);

return encode(systemRole || '');
};

const totalTokenCount = (s: SessionStore) => totalTokens(s).length;
const chatsTokens = (s: SessionStore): number[] => {
const chats = currentChats(s);
return encode(chats.map((m) => m.content).join(''));
};

const systemRoleTokenCount = (s: SessionStore) => systemRoleTokens(s).length;

const totalTokenCount = (s: SessionStore) => chatsTokens(s).length + systemRoleTokenCount(s);

export const chatSelectors = {
currentChats,
systemRoleTokenCount,
systemRoleTokens,
totalTokenCount,
totalTokens,
};

0 comments on commit 17815c6

Please sign in to comment.