mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
fix(messageThunk): ensure usage is only estimated when not already present in response (#5553)
* fix(messageThunk): ensure usage is only estimated when not already present in response * refactor: clean logic
This commit is contained in:
parent
f9690d52ee
commit
d05f6985bb
@ -603,7 +603,7 @@ const fetchAndProcessAssistantResponseImpl = async (
|
||||
const finalStateOnComplete = getState()
|
||||
const finalAssistantMsg = finalStateOnComplete.messages.entities[assistantMsgId]
|
||||
|
||||
if (status === 'success' && finalAssistantMsg && response && !response?.usage) {
|
||||
if (status === 'success' && finalAssistantMsg) {
|
||||
const userMsgId = finalAssistantMsg.askId
|
||||
const orderedMsgs = selectMessagesForTopic(finalStateOnComplete, topicId)
|
||||
const userMsgIndex = orderedMsgs.findIndex((m) => m.id === userMsgId)
|
||||
@ -613,8 +613,10 @@ const fetchAndProcessAssistantResponseImpl = async (
|
||||
// 更新topic的name
|
||||
autoRenameTopic(assistant, topicId)
|
||||
|
||||
const usage = await estimateMessagesUsage({ assistant, messages: finalContextWithAssistant })
|
||||
response.usage = usage
|
||||
if (response && !response.usage) {
|
||||
const usage = await estimateMessagesUsage({ assistant, messages: finalContextWithAssistant })
|
||||
response.usage = usage
|
||||
}
|
||||
}
|
||||
if (response && response.metrics) {
|
||||
if (!response.metrics.completion_tokens && response.usage) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user