Skip to content

Commit

Permalink
Ensure no null values are passed (langchain-ai#4854)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored Mar 22, 2024
1 parent 84cede0 commit 2425f75
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions libs/langchain-openai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,26 @@ function _convertDeltaToMessageChunk(

function convertMessagesToOpenAIParams(messages: BaseMessage[]) {
// TODO: Function messages do not support array content, fix cast
return messages.map(
(message) =>
({
role: messageToOpenAIRole(message),
content: message.content,
name: message.name,
function_call: message.additional_kwargs.function_call,
tool_calls: message.additional_kwargs.tool_calls,
tool_call_id: (message as ToolMessage).tool_call_id,
} as OpenAICompletionParam)
);
return messages.map((message) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const completionParam: Record<string, any> = {
role: messageToOpenAIRole(message),
content: message.content,
};
if (message.name != null) {
completionParam.name = message.name;
}
if (message.additional_kwargs.function_call != null) {
completionParam.function_call = message.additional_kwargs.function_call;
}
if (message.additional_kwargs.tool_calls != null) {
completionParam.tool_calls = message.additional_kwargs.tool_calls;
}
if ((message as ToolMessage).tool_call_id != null) {
completionParam.tool_call_id = (message as ToolMessage).tool_call_id;
}
return completionParam as OpenAICompletionParam;
});
}

export interface ChatOpenAICallOptions
Expand Down

0 comments on commit 2425f75

Please sign in to comment.