Skip to content

Commit

Permalink
fix(openai): include model_name in response_metadata (#7403)
Browse files Browse the repository at this point in the history
  • Loading branch information
anadi45 authored Dec 20, 2024
1 parent 5afc890 commit 62bcabd
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions libs/langchain-openai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,15 @@ function openAIResponseToChatMessage(
if (includeRawResponse !== undefined) {
additional_kwargs.__raw_response = rawResponse;
}
let response_metadata: Record<string, unknown> | undefined;
if (rawResponse.system_fingerprint) {
response_metadata = {
usage: { ...rawResponse.usage },
system_fingerprint: rawResponse.system_fingerprint,
};
}
const response_metadata: Record<string, unknown> | undefined = {
model_name: rawResponse.model,
...(rawResponse.system_fingerprint
? {
usage: { ...rawResponse.usage },
system_fingerprint: rawResponse.system_fingerprint,
}
: {}),
};

if (message.audio) {
additional_kwargs.audio = message.audio;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 62bcabd

Please sign in to comment.