@langchain/openai 0.6.13 → 0.6.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat_models.cjs +6 -4
- package/dist/chat_models.d.ts +4 -2
- package/dist/chat_models.js +7 -5
- package/dist/utils/output.cjs +23 -0
- package/dist/utils/output.d.ts +3 -1
- package/dist/utils/output.js +22 -0
- package/package.json +1 -1
package/dist/chat_models.cjs
CHANGED
|
@@ -527,7 +527,7 @@ class BaseChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
527
527
|
* OpenAI organization or project. This must be configured directly with OpenAI.
|
|
528
528
|
*
|
|
529
529
|
* See:
|
|
530
|
-
* https://
|
|
530
|
+
* https://platform.openai.com/docs/guides/your-data
|
|
531
531
|
* https://platform.openai.com/docs/api-reference/responses/create#responses-create-store
|
|
532
532
|
*
|
|
533
533
|
* @default false
|
|
@@ -1299,7 +1299,7 @@ class ChatOpenAIResponses extends BaseChatOpenAI {
|
|
|
1299
1299
|
content,
|
|
1300
1300
|
tool_calls,
|
|
1301
1301
|
invalid_tool_calls,
|
|
1302
|
-
usage_metadata: response.usage,
|
|
1302
|
+
usage_metadata: (0, output_js_1._convertOpenAIResponsesUsageToLangChainUsage)(response.usage),
|
|
1303
1303
|
additional_kwargs,
|
|
1304
1304
|
response_metadata,
|
|
1305
1305
|
});
|
|
@@ -1366,7 +1366,7 @@ class ChatOpenAIResponses extends BaseChatOpenAI {
|
|
|
1366
1366
|
}
|
|
1367
1367
|
else if (chunk.type === "response.completed") {
|
|
1368
1368
|
const msg = this._convertResponsesMessageToBaseMessage(chunk.response);
|
|
1369
|
-
usage_metadata = chunk.response.usage;
|
|
1369
|
+
usage_metadata = (0, output_js_1._convertOpenAIResponsesUsageToLangChainUsage)(chunk.response.usage);
|
|
1370
1370
|
if (chunk.response.text?.format?.type === "json_schema") {
|
|
1371
1371
|
additional_kwargs.parsed ??= JSON.parse(msg.text);
|
|
1372
1372
|
}
|
|
@@ -2217,7 +2217,9 @@ exports.ChatOpenAICompletions = ChatOpenAICompletions;
|
|
|
2217
2217
|
* timeout: undefined,
|
|
2218
2218
|
* maxRetries: 2,
|
|
2219
2219
|
* // apiKey: "...",
|
|
2220
|
-
* //
|
|
2220
|
+
* // configuration: {
|
|
2221
|
+
* // baseURL: "...",
|
|
2222
|
+
* // }
|
|
2221
2223
|
* // organization: "...",
|
|
2222
2224
|
* // other params...
|
|
2223
2225
|
* });
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -166,7 +166,7 @@ export declare abstract class BaseChatOpenAI<CallOptions extends BaseChatOpenAIC
|
|
|
166
166
|
* OpenAI organization or project. This must be configured directly with OpenAI.
|
|
167
167
|
*
|
|
168
168
|
* See:
|
|
169
|
-
* https://
|
|
169
|
+
* https://platform.openai.com/docs/guides/your-data
|
|
170
170
|
* https://platform.openai.com/docs/api-reference/responses/create#responses-create-store
|
|
171
171
|
*
|
|
172
172
|
* @default false
|
|
@@ -405,7 +405,9 @@ export interface ChatOpenAIFields extends BaseChatOpenAIFields {
|
|
|
405
405
|
* timeout: undefined,
|
|
406
406
|
* maxRetries: 2,
|
|
407
407
|
* // apiKey: "...",
|
|
408
|
-
* //
|
|
408
|
+
* // configuration: {
|
|
409
|
+
* // baseURL: "...",
|
|
410
|
+
* // }
|
|
409
411
|
* // organization: "...",
|
|
410
412
|
* // other params...
|
|
411
413
|
* });
|
package/dist/chat_models.js
CHANGED
|
@@ -13,7 +13,7 @@ import { getEndpoint } from "./utils/azure.js";
|
|
|
13
13
|
import { formatToOpenAIToolChoice, interopZodResponseFormat, wrapOpenAIClientError, } from "./utils/openai.js";
|
|
14
14
|
import { formatFunctionDefinitions, } from "./utils/openai-format-fndef.js";
|
|
15
15
|
import { _convertToOpenAITool, convertCompletionsCustomTool, convertResponsesCustomTool, isBuiltInTool, isBuiltInToolChoice, isCustomTool, isCustomToolCall, isOpenAICustomTool, parseCustomToolCall, } from "./utils/tools.js";
|
|
16
|
-
import { handleMultiModalOutput } from "./utils/output.js";
|
|
16
|
+
import { _convertOpenAIResponsesUsageToLangChainUsage, handleMultiModalOutput, } from "./utils/output.js";
|
|
17
17
|
const _FUNCTION_CALL_IDS_MAP_KEY = "__openai_function_call_ids__";
|
|
18
18
|
function isReasoningModel(model) {
|
|
19
19
|
if (!model)
|
|
@@ -522,7 +522,7 @@ export class BaseChatOpenAI extends BaseChatModel {
|
|
|
522
522
|
* OpenAI organization or project. This must be configured directly with OpenAI.
|
|
523
523
|
*
|
|
524
524
|
* See:
|
|
525
|
-
* https://
|
|
525
|
+
* https://platform.openai.com/docs/guides/your-data
|
|
526
526
|
* https://platform.openai.com/docs/api-reference/responses/create#responses-create-store
|
|
527
527
|
*
|
|
528
528
|
* @default false
|
|
@@ -1293,7 +1293,7 @@ export class ChatOpenAIResponses extends BaseChatOpenAI {
|
|
|
1293
1293
|
content,
|
|
1294
1294
|
tool_calls,
|
|
1295
1295
|
invalid_tool_calls,
|
|
1296
|
-
usage_metadata: response.usage,
|
|
1296
|
+
usage_metadata: _convertOpenAIResponsesUsageToLangChainUsage(response.usage),
|
|
1297
1297
|
additional_kwargs,
|
|
1298
1298
|
response_metadata,
|
|
1299
1299
|
});
|
|
@@ -1360,7 +1360,7 @@ export class ChatOpenAIResponses extends BaseChatOpenAI {
|
|
|
1360
1360
|
}
|
|
1361
1361
|
else if (chunk.type === "response.completed") {
|
|
1362
1362
|
const msg = this._convertResponsesMessageToBaseMessage(chunk.response);
|
|
1363
|
-
usage_metadata = chunk.response.usage;
|
|
1363
|
+
usage_metadata = _convertOpenAIResponsesUsageToLangChainUsage(chunk.response.usage);
|
|
1364
1364
|
if (chunk.response.text?.format?.type === "json_schema") {
|
|
1365
1365
|
additional_kwargs.parsed ??= JSON.parse(msg.text);
|
|
1366
1366
|
}
|
|
@@ -2209,7 +2209,9 @@ export class ChatOpenAICompletions extends BaseChatOpenAI {
|
|
|
2209
2209
|
* timeout: undefined,
|
|
2210
2210
|
* maxRetries: 2,
|
|
2211
2211
|
* // apiKey: "...",
|
|
2212
|
-
* //
|
|
2212
|
+
* // configuration: {
|
|
2213
|
+
* // baseURL: "...",
|
|
2214
|
+
* // }
|
|
2213
2215
|
* // organization: "...",
|
|
2214
2216
|
* // other params...
|
|
2215
2217
|
* });
|
package/dist/utils/output.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handleMultiModalOutput = handleMultiModalOutput;
|
|
4
|
+
exports._convertOpenAIResponsesUsageToLangChainUsage = _convertOpenAIResponsesUsageToLangChainUsage;
|
|
4
5
|
/**
|
|
5
6
|
* Handle multi modal response content.
|
|
6
7
|
*
|
|
@@ -28,3 +29,25 @@ function handleMultiModalOutput(content, messages) {
|
|
|
28
29
|
}
|
|
29
30
|
return content;
|
|
30
31
|
}
|
|
32
|
+
function _convertOpenAIResponsesUsageToLangChainUsage(usage) {
|
|
33
|
+
// TODO: Remove raw OpenAI usage details in v1
|
|
34
|
+
const inputTokenDetails = {
|
|
35
|
+
...(usage?.input_tokens_details?.cached_tokens != null && {
|
|
36
|
+
...usage?.input_tokens_details,
|
|
37
|
+
cache_read: usage?.input_tokens_details?.cached_tokens,
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
const outputTokenDetails = {
|
|
41
|
+
...(usage?.output_tokens_details?.reasoning_tokens != null && {
|
|
42
|
+
...usage?.output_tokens_details,
|
|
43
|
+
reasoning: usage?.output_tokens_details?.reasoning_tokens,
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
input_tokens: usage?.input_tokens ?? 0,
|
|
48
|
+
output_tokens: usage?.output_tokens ?? 0,
|
|
49
|
+
total_tokens: usage?.total_tokens ?? 0,
|
|
50
|
+
input_token_details: inputTokenDetails,
|
|
51
|
+
output_token_details: outputTokenDetails,
|
|
52
|
+
};
|
|
53
|
+
}
|
package/dist/utils/output.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OpenAI as OpenAIClient } from "openai";
|
|
2
|
+
import { StandardImageBlock, StandardTextBlock, UsageMetadata } from "@langchain/core/messages";
|
|
2
3
|
/**
|
|
3
4
|
* Handle multi modal response content.
|
|
4
5
|
*
|
|
@@ -7,3 +8,4 @@ import { StandardImageBlock, StandardTextBlock } from "@langchain/core/messages"
|
|
|
7
8
|
* @returns The new content of the message.
|
|
8
9
|
*/
|
|
9
10
|
export declare function handleMultiModalOutput(content: string, messages: unknown): (StandardImageBlock | StandardTextBlock)[] | string;
|
|
11
|
+
export declare function _convertOpenAIResponsesUsageToLangChainUsage(usage?: OpenAIClient.Responses.ResponseUsage): UsageMetadata;
|
package/dist/utils/output.js
CHANGED
|
@@ -25,3 +25,25 @@ export function handleMultiModalOutput(content, messages) {
|
|
|
25
25
|
}
|
|
26
26
|
return content;
|
|
27
27
|
}
|
|
28
|
+
export function _convertOpenAIResponsesUsageToLangChainUsage(usage) {
|
|
29
|
+
// TODO: Remove raw OpenAI usage details in v1
|
|
30
|
+
const inputTokenDetails = {
|
|
31
|
+
...(usage?.input_tokens_details?.cached_tokens != null && {
|
|
32
|
+
...usage?.input_tokens_details,
|
|
33
|
+
cache_read: usage?.input_tokens_details?.cached_tokens,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
const outputTokenDetails = {
|
|
37
|
+
...(usage?.output_tokens_details?.reasoning_tokens != null && {
|
|
38
|
+
...usage?.output_tokens_details,
|
|
39
|
+
reasoning: usage?.output_tokens_details?.reasoning_tokens,
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
input_tokens: usage?.input_tokens ?? 0,
|
|
44
|
+
output_tokens: usage?.output_tokens ?? 0,
|
|
45
|
+
total_tokens: usage?.total_tokens ?? 0,
|
|
46
|
+
input_token_details: inputTokenDetails,
|
|
47
|
+
output_token_details: outputTokenDetails,
|
|
48
|
+
};
|
|
49
|
+
}
|