@langchain/openai 0.2.10 → 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, {
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {