@langchain/openai 0.3.0-rc.0 → 0.3.0

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/README.md CHANGED
@@ -5,7 +5,7 @@ This package contains the LangChain.js integrations for OpenAI through their SDK
5
5
  ## Installation
6
6
 
7
7
  ```bash npm2yarn
8
- npm install @langchain/openai
8
+ npm install @langchain/openai @langchain/core
9
9
  ```
10
10
 
11
11
  This package, along with the main LangChain package, depends on [`@langchain/core`](https://npmjs.com/package/@langchain/core/).
@@ -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, {
@@ -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, {
package/dist/llms.cjs CHANGED
@@ -82,7 +82,7 @@ class OpenAI extends llms_1.BaseLLM {
82
82
  "",
83
83
  `See this page for more information:`,
84
84
  "|",
85
- `└> https://js.langchain.com/v0.2/docs/integrations/chat/openai`,
85
+ `└> https://js.langchain.com/docs/integrations/chat/openai`,
86
86
  ].join("\n"));
87
87
  // eslint-disable-next-line no-constructor-return
88
88
  return new legacy_js_1.OpenAIChat(fields, configuration);
package/dist/llms.js CHANGED
@@ -79,7 +79,7 @@ export class OpenAI extends BaseLLM {
79
79
  "",
80
80
  `See this page for more information:`,
81
81
  "|",
82
- `└> https://js.langchain.com/v0.2/docs/integrations/chat/openai`,
82
+ `└> https://js.langchain.com/docs/integrations/chat/openai`,
83
83
  ].join("\n"));
84
84
  // eslint-disable-next-line no-constructor-return
85
85
  return new OpenAIChat(fields, configuration);
@@ -1,4 +1,4 @@
1
- import { ToolDefinition } from "@langchain/core/language_models/base";
1
+ import { OpenAI as OpenAIClient } from "openai";
2
2
  import { BindToolsInput } from "@langchain/core/language_models/chat_models";
3
3
  /**
4
4
  * Formats a tool in either OpenAI format, or LangChain structured tool format
@@ -17,4 +17,4 @@ export declare function _convertToOpenAITool(tool: BindToolsInput, fields?: {
17
17
  * provided in the function definition.
18
18
  */
19
19
  strict?: boolean;
20
- }): ToolDefinition;
20
+ }): OpenAIClient.ChatCompletionTool;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.3.0-rc.0",
3
+ "version": "0.3.0",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -41,7 +41,7 @@
41
41
  "zod-to-json-schema": "^3.22.3"
42
42
  },
43
43
  "peerDependencies": {
44
- "@langchain/core": ">=0.2.26 <0.4.0 || 0.3.0-rc.0"
44
+ "@langchain/core": ">=0.2.26 <0.4.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@azure/identity": "^4.2.1",