remove: update_total_token()
All checks were successful
Build static content / build (push) Successful in 8m10s

This commit is contained in:
2024-10-15 18:19:51 +08:00
parent a763355420
commit 6aca74a7b4
4 changed files with 11 additions and 24 deletions

View File

@@ -26,7 +26,6 @@ interface Props {
messageIndex: number;
chatStore: ChatStore;
setChatStore: (cs: ChatStore) => void;
update_total_tokens: () => void;
}
export default function Message(props: Props) {
@@ -205,7 +204,6 @@ export default function Message(props: Props) {
className="input input-bordered input-xs w-16"
onChange={(event: any) => {
chat.token = parseInt(event.target.value);
props.update_total_tokens();
setChatStore({ ...chatStore });
}}
/>

View File

@@ -9,10 +9,8 @@ const AddToolMsg = (props: {
setShowAddToolMsg: Dispatch<StateUpdater<boolean>>;
chatStore: ChatStore;
setChatStore: (cs: ChatStore) => void;
update_total_tokens: () => void;
}) => {
const { setShowAddToolMsg, chatStore, update_total_tokens, setChatStore } =
props;
const { setShowAddToolMsg, chatStore, setChatStore } = props;
const [newToolCallID, setNewToolCallID] = useState("");
const [newToolContent, setNewToolContent] = useState("");
@@ -77,7 +75,6 @@ const AddToolMsg = (props: {
audio: null,
logprobs: null,
});
update_total_tokens();
setChatStore({ ...chatStore });
setNewToolCallID("");
setNewToolContent("");

View File

@@ -81,6 +81,16 @@ export function App() {
console.log("saved chat", selectedChatIndex, chatStore);
(await db).put(STORAGE_NAME, chatStore, selectedChatIndex);
// update total tokens
chatStore.totalTokens = calculate_token_length(
chatStore.systemMessageContent,
);
for (const msg of chatStore.history
.filter(({ hide }) => !hide)
.slice(chatStore.postBeginIndex)) {
chatStore.totalTokens += msg.token;
}
_setChatStore(chatStore);
};
useEffect(() => {

View File

@@ -79,19 +79,6 @@ export default function ChatBOX(props: {
const client = new ChatGPT(chatStore.apiKey);
const update_total_tokens = () => {
// manually estimate token
client.total_tokens = calculate_token_length(
chatStore.systemMessageContent,
);
for (const msg of chatStore.history
.filter(({ hide }) => !hide)
.slice(chatStore.postBeginIndex)) {
client.total_tokens += msg.token;
}
chatStore.totalTokens = client.total_tokens;
};
const _completeWithStreamMode = async (response: Response) => {
let responseTokenCount = 0;
const allChunkMessage: string[] = [];
@@ -194,7 +181,6 @@ export default function ChatBOX(props: {
// manually copy status from client to chatStore
chatStore.maxTokens = client.max_tokens;
chatStore.tokenMargin = client.tokens_margin;
update_total_tokens();
setChatStore({ ...chatStore });
setGeneratingMessage("");
setShowGenerating(false);
@@ -592,7 +578,6 @@ export default function ChatBOX(props: {
chatStore={chatStore}
setChatStore={setChatStore}
messageIndex={messageIndex}
update_total_tokens={update_total_tokens}
/>
))}
{showGenerating && (
@@ -613,7 +598,6 @@ export default function ChatBOX(props: {
}
//chatStore.totalTokens =
update_total_tokens();
setChatStore({ ...chatStore });
await complete();
@@ -771,7 +755,6 @@ export default function ChatBOX(props: {
audio: null,
logprobs: null,
});
update_total_tokens();
setInputMsg("");
setChatStore({ ...chatStore });
}}
@@ -806,7 +789,6 @@ export default function ChatBOX(props: {
chatStore={chatStore}
setChatStore={setChatStore}
setShowAddToolMsg={setShowAddToolMsg}
update_total_tokens={update_total_tokens}
/>
)}
</div>