@langchain/openai 0.2.9 → 0.2.11

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.
@@ -1066,6 +1066,16 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
1066
1066
  };
1067
1067
  }
1068
1068
  async *_streamResponseChunks(messages, options, runManager) {
1069
+ if (this.model.includes("o1-")) {
1070
+ console.warn("[WARNING]: OpenAI o1 models do not yet support token-level streaming. Streaming will yield single chunk.");
1071
+ const result = await this._generate(messages, options, runManager);
1072
+ const messageChunk = (0, messages_1.convertToChunk)(result.generations[0].message);
1073
+ yield new outputs_1.ChatGenerationChunk({
1074
+ message: messageChunk,
1075
+ text: typeof messageChunk.content === "string" ? messageChunk.content : "",
1076
+ });
1077
+ return;
1078
+ }
1069
1079
  const messagesMapped = convertMessagesToOpenAIParams(messages);
1070
1080
  const params = {
1071
1081
  ...this.invocationParams(options, {
@@ -1364,7 +1374,9 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
1364
1374
  * @param {OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming} request
1365
1375
  * @param {OpenAICoreRequestOptions | undefined} options
1366
1376
  */
1367
- async betaParsedCompletionWithRetry(request, options) {
1377
+ async betaParsedCompletionWithRetry(request, options
1378
+ // Avoid relying importing a beta type with no official entrypoint
1379
+ ) {
1368
1380
  const requestOptions = this._getClientOptions(options);
1369
1381
  return this.caller.call(async () => {
1370
1382
  try {
@@ -6,7 +6,6 @@ import { BaseChatModel, BindToolsInput, LangSmithParams, type BaseChatModelParam
6
6
  import { type BaseFunctionCallOptions, type BaseLanguageModelInput, type StructuredOutputMethodOptions, type StructuredOutputMethodParams } from "@langchain/core/language_models/base";
7
7
  import { z } from "zod";
8
8
  import { Runnable } from "@langchain/core/runnables";
9
- import { ParsedChatCompletion } from "openai/resources/beta/chat/completions.mjs";
10
9
  import type { AzureOpenAIInput, OpenAICallOptions, OpenAIChatInput, OpenAICoreRequestOptions, LegacyOpenAIInput, ChatOpenAIResponseFormat } from "./types.js";
11
10
  import { OpenAIToolChoice } from "./utils/openai.js";
12
11
  export type { AzureOpenAIInput, OpenAICallOptions, OpenAIChatInput };
@@ -634,7 +633,7 @@ export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = Chat
634
633
  * @param {OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming} request
635
634
  * @param {OpenAICoreRequestOptions | undefined} options
636
635
  */
637
- betaParsedCompletionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<ParsedChatCompletion<null>>;
636
+ betaParsedCompletionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<ReturnType<OpenAIClient["beta"]["chat"]["completions"]["parse"]>>;
638
637
  protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
639
638
  _llmType(): string;
640
639
  /** @ignore */
@@ -1,5 +1,5 @@
1
1
  import { OpenAI as OpenAIClient } from "openai";
2
- import { AIMessage, AIMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessageChunk, HumanMessageChunk, SystemMessageChunk, ToolMessageChunk, isAIMessage, } from "@langchain/core/messages";
2
+ import { AIMessage, AIMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessageChunk, HumanMessageChunk, SystemMessageChunk, ToolMessageChunk, isAIMessage, convertToChunk, } from "@langchain/core/messages";
3
3
  import { ChatGenerationChunk, } from "@langchain/core/outputs";
4
4
  import { getEnvironmentVariable } from "@langchain/core/utils/env";
5
5
  import { BaseChatModel, } from "@langchain/core/language_models/chat_models";
@@ -1062,6 +1062,16 @@ export class ChatOpenAI extends BaseChatModel {
1062
1062
  };
1063
1063
  }
1064
1064
  async *_streamResponseChunks(messages, options, runManager) {
1065
+ if (this.model.includes("o1-")) {
1066
+ console.warn("[WARNING]: OpenAI o1 models do not yet support token-level streaming. Streaming will yield single chunk.");
1067
+ const result = await this._generate(messages, options, runManager);
1068
+ const messageChunk = convertToChunk(result.generations[0].message);
1069
+ yield new ChatGenerationChunk({
1070
+ message: messageChunk,
1071
+ text: typeof messageChunk.content === "string" ? messageChunk.content : "",
1072
+ });
1073
+ return;
1074
+ }
1065
1075
  const messagesMapped = convertMessagesToOpenAIParams(messages);
1066
1076
  const params = {
1067
1077
  ...this.invocationParams(options, {
@@ -1360,7 +1370,9 @@ export class ChatOpenAI extends BaseChatModel {
1360
1370
  * @param {OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming} request
1361
1371
  * @param {OpenAICoreRequestOptions | undefined} options
1362
1372
  */
1363
- async betaParsedCompletionWithRetry(request, options) {
1373
+ async betaParsedCompletionWithRetry(request, options
1374
+ // Avoid relying importing a beta type with no official entrypoint
1375
+ ) {
1364
1376
  const requestOptions = this._getClientOptions(options);
1365
1377
  return this.caller.call(async () => {
1366
1378
  try {
@@ -89,6 +89,7 @@ class DallEAPIWrapper extends tools_1.Tool {
89
89
  apiKey: openAIApiKey,
90
90
  organization,
91
91
  dangerouslyAllowBrowser: true,
92
+ baseUrl: fields?.baseUrl,
92
93
  };
93
94
  this.client = new openai_1.OpenAI(clientConfig);
94
95
  this.model = fields?.model ?? fields?.modelName ?? this.model;
@@ -73,6 +73,10 @@ export interface DallEAPIWrapperParams extends ToolParams {
73
73
  * The organization to use
74
74
  */
75
75
  organization?: string;
76
+ /**
77
+ * The base URL of the OpenAI API.
78
+ */
79
+ baseUrl?: string;
76
80
  }
77
81
  /**
78
82
  * A tool for generating images with Open AIs Dall-E 2 or 3 API.
@@ -86,6 +86,7 @@ export class DallEAPIWrapper extends Tool {
86
86
  apiKey: openAIApiKey,
87
87
  organization,
88
88
  dangerouslyAllowBrowser: true,
89
+ baseUrl: fields?.baseUrl,
89
90
  };
90
91
  this.client = new OpenAIClient(clientConfig);
91
92
  this.model = fields?.model ?? fields?.modelName ?? this.model;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@langchain/core": ">=0.2.26 <0.3.0",
39
39
  "js-tiktoken": "^1.0.12",
40
- "openai": "^4.55.0",
40
+ "openai": "^4.57.3",
41
41
  "zod": "^3.22.4",
42
42
  "zod-to-json-schema": "^3.22.3"
43
43
  },