Skip to content

Commit

Permalink
fix(openai): Ensure usage_metadata is serialized when invoking (#6966)
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored Oct 11, 2024
1 parent ff85bbc commit 763ef92
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libs/langchain-openai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,11 @@ export class ChatOpenAI<
if (isAIMessage(generation.message)) {
generation.message.usage_metadata = usageMetadata;
}
// Fields are not serialized unless passed to the constructor
// Doing this ensures all fields on the message are serialized
generation.message = new AIMessage({
...generation.message,
});
generations.push(generation);
}
return {
Expand Down

0 comments on commit 763ef92

Please sign in to comment.