cost in stream mode
This commit is contained in:
@@ -83,11 +83,25 @@ export default function ChatBOX(props: {
|
|||||||
|
|
||||||
// console.log("push to history", allChunkMessage);
|
// console.log("push to history", allChunkMessage);
|
||||||
const content = allChunkMessage.join("");
|
const content = allChunkMessage.join("");
|
||||||
|
const token = calculate_token_length(content);
|
||||||
|
// estimate cost
|
||||||
|
if (chatStore.responseModelName) {
|
||||||
|
chatStore.cost +=
|
||||||
|
token * models[chatStore.responseModelName].price.completion;
|
||||||
|
let sum = 0;
|
||||||
|
for (const msg of chatStore.history
|
||||||
|
.filter(({ hide }) => !hide)
|
||||||
|
.slice(chatStore.postBeginIndex)) {
|
||||||
|
sum += msg.token;
|
||||||
|
}
|
||||||
|
chatStore.cost +=
|
||||||
|
sum * models[chatStore.responseModelName].price.prompt;
|
||||||
|
}
|
||||||
chatStore.history.push({
|
chatStore.history.push({
|
||||||
role: "assistant",
|
role: "assistant",
|
||||||
content,
|
content,
|
||||||
hide: false,
|
hide: false,
|
||||||
token: calculate_token_length(content),
|
token,
|
||||||
});
|
});
|
||||||
// manually copy status from client to chatStore
|
// manually copy status from client to chatStore
|
||||||
chatStore.maxTokens = client.max_tokens;
|
chatStore.maxTokens = client.max_tokens;
|
||||||
|
|||||||
Reference in New Issue
Block a user