@langchain/openai 0.5.5 → 0.5.6

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.
@@ -116,7 +116,12 @@ class AzureOpenAIEmbeddings extends embeddings_js_1.OpenAIEmbeddings {
116
116
  }
117
117
  return this.caller.call(async () => {
118
118
  try {
119
- const res = await this.client.embeddings.create(request, requestOptions);
119
+ const res = await this.client.embeddings.create(request,
120
+ // This unknown cast is required because OpenAI types seem to be incorrect here
121
+ // without it, we can't pass arbitrary keys via the `query` field in the options,
122
+ // which means we can't specify the `api-version` as required by Azure OpenAI.
123
+ // See https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning
124
+ requestOptions);
120
125
  return res;
121
126
  }
122
127
  catch (e) {
@@ -113,7 +113,12 @@ export class AzureOpenAIEmbeddings extends OpenAIEmbeddings {
113
113
  }
114
114
  return this.caller.call(async () => {
115
115
  try {
116
- const res = await this.client.embeddings.create(request, requestOptions);
116
+ const res = await this.client.embeddings.create(request,
117
+ // This unknown cast is required because OpenAI types seem to be incorrect here
118
+ // without it, we can't pass arbitrary keys via the `query` field in the options,
119
+ // which means we can't specify the `api-version` as required by Azure OpenAI.
120
+ // See https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning
121
+ requestOptions);
117
122
  return res;
118
123
  }
119
124
  catch (e) {
@@ -201,7 +201,6 @@ function _convertMessagesToOpenAIResponsesParams(messages, model) {
201
201
  name: toolCall.name,
202
202
  arguments: JSON.stringify(toolCall.args),
203
203
  call_id: toolCall.id,
204
- // @ts-expect-error Might come from a non-Responses API message
205
204
  id: functionCallIds?.[toolCall.id],
206
205
  })));
207
206
  }
@@ -210,7 +209,6 @@ function _convertMessagesToOpenAIResponsesParams(messages, model) {
210
209
  type: "function_call",
211
210
  name: toolCall.function.name,
212
211
  call_id: toolCall.id,
213
- // @ts-expect-error Might come from a non-Responses API message
214
212
  id: functionCallIds?.[toolCall.id],
215
213
  arguments: toolCall.function.arguments,
216
214
  })));
@@ -322,7 +320,9 @@ function _convertOpenAIResponsesMessageToBaseMessage(response) {
322
320
  invalid_tool_calls.push((0, openai_tools_1.makeInvalidToolCall)(fnAdapter, errMessage));
323
321
  }
324
322
  additional_kwargs[_FUNCTION_CALL_IDS_MAP_KEY] ??= {};
325
- additional_kwargs[_FUNCTION_CALL_IDS_MAP_KEY][item.call_id] = item.id;
323
+ if (item.id) {
324
+ additional_kwargs[_FUNCTION_CALL_IDS_MAP_KEY][item.call_id] = item.id;
325
+ }
326
326
  }
327
327
  else if (item.type === "reasoning") {
328
328
  additional_kwargs.reasoning = item;
@@ -466,7 +466,9 @@ function _convertChatOpenAIToolTypeToOpenAITool(tool, fields) {
466
466
  return (0, tools_js_1._convertToOpenAITool)(tool, fields);
467
467
  }
468
468
  function isReasoningModel(model) {
469
- return model?.startsWith("o1") || model?.startsWith("o3");
469
+ return (model?.startsWith("o1") ||
470
+ model?.startsWith("o3") ||
471
+ model?.startsWith("o4"));
470
472
  }
471
473
  /**
472
474
  * OpenAI chat model integration.
@@ -196,7 +196,6 @@ function _convertMessagesToOpenAIResponsesParams(messages, model) {
196
196
  name: toolCall.name,
197
197
  arguments: JSON.stringify(toolCall.args),
198
198
  call_id: toolCall.id,
199
- // @ts-expect-error Might come from a non-Responses API message
200
199
  id: functionCallIds?.[toolCall.id],
201
200
  })));
202
201
  }
@@ -205,7 +204,6 @@ function _convertMessagesToOpenAIResponsesParams(messages, model) {
205
204
  type: "function_call",
206
205
  name: toolCall.function.name,
207
206
  call_id: toolCall.id,
208
- // @ts-expect-error Might come from a non-Responses API message
209
207
  id: functionCallIds?.[toolCall.id],
210
208
  arguments: toolCall.function.arguments,
211
209
  })));
@@ -317,7 +315,9 @@ function _convertOpenAIResponsesMessageToBaseMessage(response) {
317
315
  invalid_tool_calls.push(makeInvalidToolCall(fnAdapter, errMessage));
318
316
  }
319
317
  additional_kwargs[_FUNCTION_CALL_IDS_MAP_KEY] ??= {};
320
- additional_kwargs[_FUNCTION_CALL_IDS_MAP_KEY][item.call_id] = item.id;
318
+ if (item.id) {
319
+ additional_kwargs[_FUNCTION_CALL_IDS_MAP_KEY][item.call_id] = item.id;
320
+ }
321
321
  }
322
322
  else if (item.type === "reasoning") {
323
323
  additional_kwargs.reasoning = item;
@@ -461,7 +461,9 @@ function _convertChatOpenAIToolTypeToOpenAITool(tool, fields) {
461
461
  return _convertToOpenAITool(tool, fields);
462
462
  }
463
463
  function isReasoningModel(model) {
464
- return model?.startsWith("o1") || model?.startsWith("o3");
464
+ return (model?.startsWith("o1") ||
465
+ model?.startsWith("o3") ||
466
+ model?.startsWith("o4"));
465
467
  }
466
468
  /**
467
469
  * OpenAI chat model integration.
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { OpenAI as OpenAIClient } from "openai";
2
+ import type { RequestOptions as _OpenAICoreRequestOptions } from "openai/core";
2
3
  import type { ResponseFormatText, ResponseFormatJSONObject, ResponseFormatJSONSchema } from "openai/resources/shared";
3
4
  import { TiktokenModel } from "js-tiktoken/lite";
4
5
  import type { BaseLanguageModelCallOptions } from "@langchain/core/language_models/base";
@@ -73,18 +74,7 @@ export declare interface OpenAIBaseInput {
73
74
  */
74
75
  apiKey?: string;
75
76
  }
76
- export type OpenAICoreRequestOptions<Req extends object = Record<string, unknown>> = {
77
- path?: string;
78
- query?: Req | undefined;
79
- body?: Req | undefined;
80
- headers?: Record<string, string | null | undefined> | undefined;
81
- maxRetries?: number;
82
- stream?: boolean | undefined;
83
- timeout?: number;
84
- httpAgent?: any;
85
- signal?: AbortSignal | undefined | null;
86
- idempotencyKey?: string;
87
- };
77
+ export type OpenAICoreRequestOptions<Req = Record<string, unknown>> = _OpenAICoreRequestOptions<Req>;
88
78
  export interface OpenAICallOptions extends BaseLanguageModelCallOptions {
89
79
  /**
90
80
  * Additional options to pass to the underlying axios request.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -36,7 +36,7 @@
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
38
  "js-tiktoken": "^1.0.12",
39
- "openai": "^4.87.3",
39
+ "openai": "^4.93.0",
40
40
  "zod": "^3.22.4",
41
41
  "zod-to-json-schema": "^3.22.3"
42
42
  },
@@ -62,7 +62,7 @@
62
62
  "jest": "^29.5.0",
63
63
  "jest-environment-node": "^29.6.4",
64
64
  "prettier": "^2.8.3",
65
- "release-it": "^17.6.0",
65
+ "release-it": "^18.1.2",
66
66
  "rimraf": "^5.0.1",
67
67
  "ts-jest": "^29.1.0",
68
68
  "typescript": "~5.1.6"