diff --git a/libs/langchain-openai/src/chat_models.ts b/libs/langchain-openai/src/chat_models.ts index f2151c8e0a50..0906d2848655 100644 --- a/libs/langchain-openai/src/chat_models.ts +++ b/libs/langchain-openai/src/chat_models.ts @@ -173,13 +173,15 @@ function openAIResponseToChatMessage( if (includeRawResponse !== undefined) { additional_kwargs.__raw_response = rawResponse; } - let response_metadata: Record | undefined; - if (rawResponse.system_fingerprint) { - response_metadata = { - usage: { ...rawResponse.usage }, - system_fingerprint: rawResponse.system_fingerprint, - }; - } + const response_metadata: Record | undefined = { + model_name: rawResponse.model, + ...(rawResponse.system_fingerprint + ? { + usage: { ...rawResponse.usage }, + system_fingerprint: rawResponse.system_fingerprint, + } + : {}), + }; if (message.audio) { additional_kwargs.audio = message.audio; @@ -1443,6 +1445,7 @@ export class ChatOpenAI< // Only include system fingerprint in the last chunk for now // to avoid concatenation issues generationInfo.system_fingerprint = data.system_fingerprint; + generationInfo.model_name = data.model; } if (this.logprobs) { generationInfo.logprobs = choice.logprobs;