ConstThe converter handles the following message roles:
assistant: Converted to AIMessage with support for tool calls, function calls,
audio content, and multi-modal outputsFor assistant messages, the converter:
The complete raw response from OpenAI's API, used to extract metadata like model name, usage statistics, and system fingerprint
If true, includes the raw OpenAI response in the
message's additional_kwargs under the __raw_response key. Useful for debugging
or accessing provider-specific fields. Defaults to false.
A LangChain BaseMessage instance:
const baseMessage = convertCompletionsMessageToBaseMessage({
message: {
role: "assistant",
content: "Hello! How can I help you?",
tool_calls: [
{
id: "call_123",
type: "function",
function: { name: "get_weather", arguments: '{"location":"NYC"}' }
}
]
},
rawResponse: completionResponse,
includeRawResponse: true
});
// Returns an AIMessage with parsed tool calls and metadata
Converts an OpenAI Chat Completions API message to a LangChain BaseMessage.
This converter transforms messages from OpenAI's Chat Completions API format into LangChain's internal message representation, handling various message types and preserving metadata, tool calls, and other relevant information.