Skip to content

Commit

Permalink
fix(openai): Remove extra serialized params for OpenAI messages (#7414)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored Dec 20, 2024
1 parent 62bcabd commit a76d83e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions libs/langchain-openai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
OpenAIToolCall,
isAIMessage,
UsageMetadata,
BaseMessageFields,
} from "@langchain/core/messages";
import {
type ChatGeneration,
Expand Down Expand Up @@ -1677,9 +1678,13 @@ export class ChatOpenAI<
}
// 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,
});
generation.message = new AIMessage(
Object.fromEntries(
Object.entries(generation.message).filter(
([key]) => !key.startsWith("lc_")
)
) as BaseMessageFields
);
generations.push(generation);
}
return {
Expand Down

0 comments on commit a76d83e

Please sign in to comment.