Skip to content

Commit b820cbb

Browse files
authored
fix(community): usage error returned by Zhipuai streaming data was missing tokens-related information (#7745)
1 parent 1f57087 commit b820cbb

File tree

1 file changed

+3
-2
lines changed
  • libs/langchain-community/src/chat_models

1 file changed

+3
-2
lines changed

libs/langchain-community/src/chat_models/zhipuai.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ export class ChatZhipuAI extends BaseChatModel implements ChatZhipuAIParams {
514514
for await (const chunk of stream) {
515515
if (chunk !== "[DONE]") {
516516
const deserializedChunk = this._deserialize(chunk);
517-
const { choices, id } = deserializedChunk;
517+
const { choices, usage, id } = deserializedChunk;
518518
const text = choices[0]?.delta?.content ?? "";
519519
const finished = !!choices[0]?.finish_reason;
520520
yield new ChatGenerationChunk({
@@ -524,7 +524,8 @@ export class ChatZhipuAI extends BaseChatModel implements ChatZhipuAIParams {
524524
? {
525525
finished,
526526
request_id: id,
527-
usage: chunk.usage,
527+
// The usage of tokens is counted at the end of the stream
528+
usage,
528529
}
529530
: undefined,
530531
});

0 commit comments

Comments
 (0)