Skip to content

fix(community): usage error returned by Zhipuai streaming data was missing tokens-related information #7745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions libs/langchain-community/src/chat_models/zhipuai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ export class ChatZhipuAI extends BaseChatModel implements ChatZhipuAIParams {
for await (const chunk of stream) {
if (chunk !== "[DONE]") {
const deserializedChunk = this._deserialize(chunk);
const { choices, id } = deserializedChunk;
const { choices, usage, id } = deserializedChunk;
const text = choices[0]?.delta?.content ?? "";
const finished = !!choices[0]?.finish_reason;
yield new ChatGenerationChunk({
Expand All @@ -524,7 +524,8 @@ export class ChatZhipuAI extends BaseChatModel implements ChatZhipuAIParams {
? {
finished,
request_id: id,
usage: chunk.usage,
// The usage of tokens is counted at the end of the stream
usage,
}
: undefined,
});
Expand Down
Loading