@langchain/openai 0.5.17 → 0.5.18
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 +2 -2
- package/dist/azure/chat_models.cjs +1 -1
- package/dist/azure/chat_models.d.ts +6 -6
- package/dist/azure/chat_models.js +2 -2
- package/dist/chat_models.cjs +1922 -1861
- package/dist/chat_models.d.ts +233 -235
- package/dist/chat_models.js +1890 -1860
- package/dist/types.d.ts +7 -0
- package/dist/utils/openai.cjs +0 -49
- package/dist/utils/openai.d.ts +0 -6
- package/dist/utils/openai.js +1 -49
- package/dist/utils/prompts.cjs +1 -1
- package/dist/utils/prompts.d.ts +1 -1
- package/dist/utils/prompts.js +1 -1
- package/package.json +3 -3
package/dist/chat_models.d.ts
CHANGED
|
@@ -1,65 +1,79 @@
|
|
|
1
1
|
import { type ClientOptions, OpenAI as OpenAIClient } from "openai";
|
|
2
2
|
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
|
|
3
3
|
import { AIMessageChunk, type BaseMessage, ChatMessageChunk, FunctionMessageChunk, HumanMessageChunk, SystemMessageChunk, ToolMessageChunk } from "@langchain/core/messages";
|
|
4
|
-
import { ChatGenerationChunk, type
|
|
4
|
+
import { ChatGenerationChunk, type ChatResult } from "@langchain/core/outputs";
|
|
5
5
|
import { BaseChatModel, type BindToolsInput, type LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
6
6
|
import { type BaseFunctionCallOptions, type BaseLanguageModelInput, type StructuredOutputMethodOptions } from "@langchain/core/language_models/base";
|
|
7
7
|
import { Runnable } from "@langchain/core/runnables";
|
|
8
|
-
import type { ResponseFormatText, ResponseFormatJSONObject, ResponseFormatJSONSchema } from "openai/resources/shared";
|
|
9
8
|
import { InteropZodType } from "@langchain/core/utils/types";
|
|
10
|
-
import { type OpenAICallOptions, type OpenAIChatInput, type OpenAICoreRequestOptions, type ChatOpenAIResponseFormat
|
|
9
|
+
import { type OpenAICallOptions, type OpenAIChatInput, type OpenAICoreRequestOptions, type ChatOpenAIResponseFormat } from "./types.js";
|
|
11
10
|
import { OpenAIToolChoice } from "./utils/openai.js";
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export type { OpenAICallOptions, OpenAIChatInput };
|
|
12
|
+
interface TokenUsage {
|
|
13
|
+
completionTokens?: number;
|
|
14
|
+
promptTokens?: number;
|
|
15
|
+
totalTokens?: number;
|
|
16
|
+
}
|
|
15
17
|
interface OpenAILLMOutput {
|
|
16
|
-
tokenUsage:
|
|
17
|
-
completionTokens?: number;
|
|
18
|
-
promptTokens?: number;
|
|
19
|
-
totalTokens?: number;
|
|
20
|
-
};
|
|
18
|
+
tokenUsage: TokenUsage;
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export declare function
|
|
25
|
-
|
|
20
|
+
type OpenAIRoleEnum = "system" | "developer" | "assistant" | "user" | "function" | "tool";
|
|
21
|
+
type OpenAICompletionParam = OpenAIClient.Chat.Completions.ChatCompletionMessageParam;
|
|
22
|
+
export declare function messageToOpenAIRole(message: BaseMessage): OpenAIRoleEnum;
|
|
23
|
+
export declare function _convertMessagesToOpenAIParams(messages: BaseMessage[], model?: string): OpenAICompletionParam[];
|
|
24
|
+
type ExcludeController<T> = T extends {
|
|
25
|
+
controller: unknown;
|
|
26
|
+
} ? never : T;
|
|
27
|
+
type ExcludeNonController<T> = T extends {
|
|
28
|
+
controller: unknown;
|
|
29
|
+
} ? T : never;
|
|
30
|
+
type ResponsesCreate = OpenAIClient.Responses["create"];
|
|
31
|
+
type ResponsesCreateParams = Parameters<OpenAIClient.Responses["create"]>[0];
|
|
32
|
+
type ResponsesTool = Exclude<ResponsesCreateParams["tools"], undefined>[number];
|
|
33
|
+
type ResponsesToolChoice = Exclude<ResponsesCreateParams["tool_choice"], undefined>;
|
|
34
|
+
type ResponsesCreateInvoke = ExcludeController<Awaited<ReturnType<ResponsesCreate>>>;
|
|
35
|
+
type ResponsesCreateStream = ExcludeNonController<Awaited<ReturnType<ResponsesCreate>>>;
|
|
36
|
+
type ResponseInvocationParams = Omit<ResponsesCreateParams, "input">;
|
|
37
|
+
type ChatCompletionInvocationParams = Omit<OpenAIClient.Chat.ChatCompletionCreateParams, "messages">;
|
|
38
|
+
type ChatOpenAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool | ResponsesTool;
|
|
39
|
+
export interface ChatOpenAIStructuredOutputMethodOptions<IncludeRaw extends boolean> extends StructuredOutputMethodOptions<IncludeRaw> {
|
|
26
40
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
41
|
+
* strict: If `true` and `method` = "function_calling", model output is
|
|
42
|
+
* guaranteed to exactly match the schema. If `true`, the input schema
|
|
43
|
+
* will also be validated according to
|
|
44
|
+
* https://platform.openai.com/docs/guides/structured-outputs/supported-schemas.
|
|
45
|
+
* If `false`, input schema will not be validated and model output will not
|
|
46
|
+
* be validated.
|
|
47
|
+
* If `undefined`, `strict` argument will not be passed to the model.
|
|
48
|
+
*
|
|
49
|
+
* @version 0.2.6
|
|
50
|
+
* @note Planned breaking change in version `0.3.0`:
|
|
51
|
+
* `strict` will default to `true` when `method` is
|
|
52
|
+
* "function_calling" as of version `0.3.0`.
|
|
30
53
|
*/
|
|
54
|
+
strict?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface ChatOpenAICallOptions extends OpenAICallOptions, BaseFunctionCallOptions {
|
|
31
57
|
tools?: ChatOpenAIToolType[];
|
|
32
|
-
/**
|
|
33
|
-
* Specifies which tool the model should use to respond.
|
|
34
|
-
* Can be an {@link OpenAIToolChoice} or a {@link ResponsesToolChoice}.
|
|
35
|
-
* If not set, the model will decide which tool to use automatically.
|
|
36
|
-
*/
|
|
37
58
|
tool_choice?: OpenAIToolChoice | ResponsesToolChoice;
|
|
38
|
-
/**
|
|
39
|
-
* Adds a prompt index to prompts passed to the model to track
|
|
40
|
-
* what prompt is being used for a given generation.
|
|
41
|
-
*/
|
|
42
59
|
promptIndex?: number;
|
|
43
|
-
/**
|
|
44
|
-
* An object specifying the format that the model must output.
|
|
45
|
-
*/
|
|
46
60
|
response_format?: ChatOpenAIResponseFormat;
|
|
47
|
-
/**
|
|
48
|
-
* When provided, the completions API will make a best effort to sample
|
|
49
|
-
* deterministically, such that repeated requests with the same `seed`
|
|
50
|
-
* and parameters should return the same result.
|
|
51
|
-
*/
|
|
52
61
|
seed?: number;
|
|
53
62
|
/**
|
|
54
63
|
* Additional options to pass to streamed completions.
|
|
55
|
-
* If provided
|
|
56
|
-
* initialization time.
|
|
64
|
+
* If provided takes precedence over "streamUsage" set at initialization time.
|
|
57
65
|
*/
|
|
58
|
-
stream_options?:
|
|
66
|
+
stream_options?: {
|
|
67
|
+
/**
|
|
68
|
+
* Whether or not to include token usage in the stream.
|
|
69
|
+
* If set to `true`, this will include an additional
|
|
70
|
+
* chunk at the end of the stream with the token usage.
|
|
71
|
+
*/
|
|
72
|
+
include_usage: boolean;
|
|
73
|
+
};
|
|
59
74
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* [Learn more](https://platform.openai.com/docs/guides/function-calling#parallel-function-calling)
|
|
75
|
+
* Whether or not to restrict the ability to
|
|
76
|
+
* call multiple tools in one response.
|
|
63
77
|
*/
|
|
64
78
|
parallel_tool_calls?: boolean;
|
|
65
79
|
/**
|
|
@@ -72,6 +86,8 @@ interface BaseChatOpenAICallOptions extends OpenAICallOptions, BaseFunctionCallO
|
|
|
72
86
|
* be validated.
|
|
73
87
|
*
|
|
74
88
|
* If `undefined`, `strict` argument will not be passed to the model.
|
|
89
|
+
*
|
|
90
|
+
* @version 0.2.6
|
|
75
91
|
*/
|
|
76
92
|
strict?: boolean;
|
|
77
93
|
/**
|
|
@@ -98,6 +114,13 @@ interface BaseChatOpenAICallOptions extends OpenAICallOptions, BaseFunctionCallO
|
|
|
98
114
|
* [Learn more](https://platform.openai.com/docs/guides/latency-optimization#use-predicted-outputs).
|
|
99
115
|
*/
|
|
100
116
|
prediction?: OpenAIClient.ChatCompletionPredictionContent;
|
|
117
|
+
/**
|
|
118
|
+
* Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and high.
|
|
119
|
+
* Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
|
|
120
|
+
*
|
|
121
|
+
* @deprecated Use {@link reasoning} object instead.
|
|
122
|
+
*/
|
|
123
|
+
reasoning_effort?: OpenAIClient.Chat.ChatCompletionReasoningEffort;
|
|
101
124
|
/**
|
|
102
125
|
* Options for reasoning models.
|
|
103
126
|
*
|
|
@@ -107,207 +130,42 @@ interface BaseChatOpenAICallOptions extends OpenAICallOptions, BaseFunctionCallO
|
|
|
107
130
|
* These options will be ignored when not using a reasoning model.
|
|
108
131
|
*/
|
|
109
132
|
reasoning?: OpenAIClient.Reasoning;
|
|
110
|
-
/**
|
|
111
|
-
* Service tier to use for this request. Can be "auto", "default", or "flex"
|
|
112
|
-
* Specifies the service tier for prioritization and latency optimization.
|
|
113
|
-
*/
|
|
114
|
-
service_tier?: OpenAIClient.Chat.ChatCompletionCreateParams["service_tier"];
|
|
115
|
-
}
|
|
116
|
-
export interface BaseChatOpenAIFields extends Partial<OpenAIChatInput>, BaseChatModelParams {
|
|
117
|
-
/**
|
|
118
|
-
* Optional configuration options for the OpenAI client.
|
|
119
|
-
*/
|
|
120
|
-
configuration?: ClientOptions;
|
|
121
|
-
}
|
|
122
|
-
/** @internal */
|
|
123
|
-
declare abstract class BaseChatOpenAI<CallOptions extends BaseChatOpenAICallOptions> extends BaseChatModel<CallOptions, AIMessageChunk> implements Partial<OpenAIChatInput> {
|
|
124
|
-
temperature?: number;
|
|
125
|
-
topP?: number;
|
|
126
|
-
frequencyPenalty?: number;
|
|
127
|
-
presencePenalty?: number;
|
|
128
|
-
n?: number;
|
|
129
|
-
logitBias?: Record<string, number>;
|
|
130
|
-
model: string;
|
|
131
|
-
modelKwargs?: OpenAIChatInput["modelKwargs"];
|
|
132
|
-
stop?: string[];
|
|
133
|
-
stopSequences?: string[];
|
|
134
|
-
user?: string;
|
|
135
|
-
timeout?: number;
|
|
136
|
-
streaming: boolean;
|
|
137
|
-
streamUsage: boolean;
|
|
138
|
-
maxTokens?: number;
|
|
139
|
-
logprobs?: boolean;
|
|
140
|
-
topLogprobs?: number;
|
|
141
|
-
apiKey?: string;
|
|
142
|
-
organization?: string;
|
|
143
|
-
__includeRawResponse?: boolean;
|
|
144
|
-
protected client: OpenAIClient;
|
|
145
|
-
protected clientConfig: ClientOptions;
|
|
146
|
-
/**
|
|
147
|
-
* Whether the model supports the `strict` argument when passing in tools.
|
|
148
|
-
* If `undefined` the `strict` argument will not be passed to OpenAI.
|
|
149
|
-
*/
|
|
150
|
-
supportsStrictToolCalling?: boolean;
|
|
151
|
-
audio?: OpenAIClient.Chat.ChatCompletionAudioParam;
|
|
152
|
-
modalities?: Array<OpenAIClient.Chat.ChatCompletionModality>;
|
|
153
|
-
reasoning?: OpenAIClient.Reasoning;
|
|
154
|
-
/**
|
|
155
|
-
* Must be set to `true` in tenancies with Zero Data Retention. Setting to `true` will disable
|
|
156
|
-
* output storage in the Responses API, but this DOES NOT enable Zero Data Retention in your
|
|
157
|
-
* OpenAI organization or project. This must be configured directly with OpenAI.
|
|
158
|
-
*
|
|
159
|
-
* See:
|
|
160
|
-
* https://help.openai.com/en/articles/10503543-data-residency-for-the-openai-api
|
|
161
|
-
* https://platform.openai.com/docs/api-reference/responses/create#responses-create-store
|
|
162
|
-
*
|
|
163
|
-
* @default false
|
|
164
|
-
*/
|
|
165
|
-
zdrEnabled?: boolean | undefined;
|
|
166
|
-
/**
|
|
167
|
-
* Service tier to use for this request. Can be "auto", "default", or "flex" or "priority".
|
|
168
|
-
* Specifies the service tier for prioritization and latency optimization.
|
|
169
|
-
*/
|
|
170
|
-
service_tier?: OpenAIClient.Chat.ChatCompletionCreateParams["service_tier"];
|
|
171
|
-
_llmType(): string;
|
|
172
|
-
static lc_name(): string;
|
|
173
|
-
get callKeys(): string[];
|
|
174
|
-
lc_serializable: boolean;
|
|
175
|
-
get lc_secrets(): {
|
|
176
|
-
[key: string]: string;
|
|
177
|
-
} | undefined;
|
|
178
|
-
get lc_aliases(): Record<string, string>;
|
|
179
|
-
get lc_serializable_keys(): string[];
|
|
180
|
-
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
181
|
-
/** @ignore */
|
|
182
|
-
_identifyingParams(): Omit<OpenAIClient.Chat.ChatCompletionCreateParams, "messages"> & {
|
|
183
|
-
model_name: string;
|
|
184
|
-
} & ClientOptions;
|
|
185
|
-
/**
|
|
186
|
-
* Get the identifying parameters for the model
|
|
187
|
-
*/
|
|
188
|
-
identifyingParams(): Omit<OpenAIClient.Chat.Completions.ChatCompletionCreateParams, "messages"> & {
|
|
189
|
-
model_name: string;
|
|
190
|
-
} & ClientOptions;
|
|
191
|
-
constructor(fields?: BaseChatOpenAIFields);
|
|
192
|
-
/**
|
|
193
|
-
* Returns backwards compatible reasoning parameters from constructor params and call options
|
|
194
|
-
* @internal
|
|
195
|
-
*/
|
|
196
|
-
protected _getReasoningParams(options?: this["ParsedCallOptions"]): OpenAIClient.Reasoning | undefined;
|
|
197
|
-
/**
|
|
198
|
-
* Returns an openai compatible response format from a set of options
|
|
199
|
-
* @internal
|
|
200
|
-
*/
|
|
201
|
-
protected _getResponseFormat(resFormat?: CallOptions["response_format"]): ResponseFormatText | ResponseFormatJSONObject | ResponseFormatJSONSchema | undefined;
|
|
202
|
-
protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
|
|
203
|
-
protected _convertChatOpenAIToolToCompletionsTool(tool: ChatOpenAIToolType, fields?: {
|
|
204
|
-
strict?: boolean;
|
|
205
|
-
}): OpenAIClient.ChatCompletionTool;
|
|
206
|
-
bindTools(tools: ChatOpenAIToolType[], kwargs?: Partial<CallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, CallOptions>;
|
|
207
|
-
/** @ignore */
|
|
208
|
-
_combineLLMOutput(...llmOutputs: OpenAILLMOutput[]): OpenAILLMOutput;
|
|
209
|
-
getNumTokensFromMessages(messages: BaseMessage[]): Promise<{
|
|
210
|
-
totalCount: number;
|
|
211
|
-
countPerMessage: number[];
|
|
212
|
-
}>;
|
|
213
|
-
/** @internal */
|
|
214
|
-
protected _getNumTokensFromGenerations(generations: ChatGeneration[]): Promise<number>;
|
|
215
|
-
/** @internal */
|
|
216
|
-
protected _getEstimatedTokenCountFromPrompt(messages: BaseMessage[], functions?: OpenAIClient.Chat.ChatCompletionCreateParams.Function[], function_call?: "none" | "auto" | OpenAIClient.Chat.ChatCompletionFunctionCallOption): Promise<number>;
|
|
217
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
218
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
219
|
-
raw: BaseMessage;
|
|
220
|
-
parsed: RunOutput;
|
|
221
|
-
}>;
|
|
222
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
223
|
-
raw: BaseMessage;
|
|
224
|
-
parsed: RunOutput;
|
|
225
|
-
}>;
|
|
226
|
-
}
|
|
227
|
-
type ExcludeController<T> = T extends {
|
|
228
|
-
controller: unknown;
|
|
229
|
-
} ? never : T;
|
|
230
|
-
type ResponsesCreate = OpenAIClient.Responses["create"];
|
|
231
|
-
type ResponsesParse = OpenAIClient.Responses["parse"];
|
|
232
|
-
type ResponsesCreateInvoke = ExcludeController<Awaited<ReturnType<ResponsesCreate>>>;
|
|
233
|
-
type ResponsesParseInvoke = ExcludeController<Awaited<ReturnType<ResponsesParse>>>;
|
|
234
|
-
interface ChatOpenAIResponsesCallOptions extends BaseChatOpenAICallOptions {
|
|
235
133
|
/**
|
|
236
134
|
* Configuration options for a text response from the model. Can be plain text or
|
|
237
135
|
* structured JSON data.
|
|
136
|
+
*
|
|
137
|
+
* If set, the Responses API will be used to fulfill the request.
|
|
238
138
|
*/
|
|
239
|
-
text?:
|
|
139
|
+
text?: ResponsesCreateParams["text"];
|
|
240
140
|
/**
|
|
241
141
|
* The truncation strategy to use for the model response.
|
|
142
|
+
*
|
|
143
|
+
* If set, the Responses API will be used to fulfill the request.
|
|
242
144
|
*/
|
|
243
|
-
truncation?:
|
|
145
|
+
truncation?: ResponsesCreateParams["truncation"];
|
|
244
146
|
/**
|
|
245
147
|
* Specify additional output data to include in the model response.
|
|
148
|
+
*
|
|
149
|
+
* If set, the Responses API will be used to fulfill the request.
|
|
246
150
|
*/
|
|
247
|
-
include?:
|
|
151
|
+
include?: ResponsesCreateParams["include"];
|
|
248
152
|
/**
|
|
249
153
|
* The unique ID of the previous response to the model. Use this to create multi-turn
|
|
250
|
-
* conversations.
|
|
154
|
+
* conversations. Will be set automatically if {@link ChatOpenAI.zdrEnabled} is `false`, provided
|
|
155
|
+
* that AIMessages included in the request have a `response_metadata.id` property. Ignored unless
|
|
156
|
+
* {@link ChatOpenAI.useResponsesApi} is `true`.
|
|
157
|
+
*
|
|
158
|
+
* If set, the Responses API will be used to fulfill the request.
|
|
251
159
|
*/
|
|
252
|
-
previous_response_id?:
|
|
253
|
-
}
|
|
254
|
-
type ChatResponsesInvocationParams = Omit<OpenAIClient.Responses.ResponseCreateParams, "input">;
|
|
255
|
-
/**
|
|
256
|
-
* OpenAI Responses API implementation.
|
|
257
|
-
*
|
|
258
|
-
* Will be exported in a later version of @langchain/openai.
|
|
259
|
-
*
|
|
260
|
-
* @internal
|
|
261
|
-
*/
|
|
262
|
-
export declare class ChatOpenAIResponses<CallOptions extends ChatOpenAIResponsesCallOptions = ChatOpenAIResponsesCallOptions> extends BaseChatOpenAI<CallOptions> {
|
|
263
|
-
invocationParams(options?: this["ParsedCallOptions"]): ChatResponsesInvocationParams;
|
|
264
|
-
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"]): Promise<ChatResult>;
|
|
265
|
-
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"]): AsyncGenerator<ChatGenerationChunk>;
|
|
160
|
+
previous_response_id?: ResponsesCreateParams["previous_response_id"];
|
|
266
161
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* @param options Optional configuration for the API call.
|
|
270
|
-
* @returns The response from the OpenAI API.
|
|
162
|
+
* Service tier to use for this request. Can be "auto", "default", or "flex"
|
|
163
|
+
* Specifies the service tier for prioritization and latency optimization.
|
|
271
164
|
*/
|
|
272
|
-
|
|
273
|
-
completionWithRetry(request: OpenAIClient.Responses.ResponseCreateParamsNonStreaming, requestOptions?: OpenAIClient.RequestOptions): Promise<OpenAIClient.Responses.Response>;
|
|
274
|
-
/** @internal */
|
|
275
|
-
protected _convertResponsesMessageToBaseMessage(response: ResponsesCreateInvoke | ResponsesParseInvoke): BaseMessage;
|
|
276
|
-
/** @internal */
|
|
277
|
-
protected _convertResponsesDeltaToBaseMessageChunk(chunk: OpenAIClient.Responses.ResponseStreamEvent): ChatGenerationChunk | null;
|
|
278
|
-
/** @internal */
|
|
279
|
-
protected _convertMessagesToResponsesParams(messages: BaseMessage[]): (OpenAIClient.Responses.ResponseReasoningItem | OpenAIClient.Responses.EasyInputMessage | OpenAIClient.Responses.ResponseInputItem.Message | OpenAIClient.Responses.ResponseOutputMessage | OpenAIClient.Responses.ResponseFileSearchToolCall | OpenAIClient.Responses.ResponseComputerToolCall | OpenAIClient.Responses.ResponseInputItem.ComputerCallOutput | OpenAIClient.Responses.ResponseFunctionWebSearch | OpenAIClient.Responses.ResponseFunctionToolCall | OpenAIClient.Responses.ResponseInputItem.FunctionCallOutput | OpenAIClient.Responses.ResponseInputItem.ImageGenerationCall | OpenAIClient.Responses.ResponseCodeInterpreterToolCall | OpenAIClient.Responses.ResponseInputItem.LocalShellCall | OpenAIClient.Responses.ResponseInputItem.LocalShellCallOutput | OpenAIClient.Responses.ResponseInputItem.McpListTools | OpenAIClient.Responses.ResponseInputItem.McpApprovalRequest | OpenAIClient.Responses.ResponseInputItem.McpApprovalResponse | OpenAIClient.Responses.ResponseInputItem.McpCall | OpenAIClient.Responses.ResponseInputItem.ItemReference)[];
|
|
280
|
-
/** @internal */
|
|
281
|
-
protected _convertReasoningSummary(reasoning: ChatOpenAIReasoningSummary): OpenAIClient.Responses.ResponseReasoningItem;
|
|
282
|
-
/** @internal */
|
|
283
|
-
protected _reduceChatOpenAITools(tools: ChatOpenAIToolType[], fields: {
|
|
284
|
-
stream?: boolean;
|
|
285
|
-
strict?: boolean;
|
|
286
|
-
}): ResponsesTool[];
|
|
287
|
-
}
|
|
288
|
-
interface ChatOpenAICompletionsCallOptions extends BaseChatOpenAICallOptions {
|
|
165
|
+
service_tier?: ResponsesCreateParams["service_tier"];
|
|
289
166
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
* OpenAI Completions API implementation.
|
|
293
|
-
* @internal
|
|
294
|
-
*/
|
|
295
|
-
export declare class ChatOpenAICompletions<CallOptions extends ChatOpenAICompletionsCallOptions = ChatOpenAICompletionsCallOptions> extends BaseChatOpenAI<CallOptions> {
|
|
296
|
-
/** @internal */
|
|
297
|
-
invocationParams(options?: this["ParsedCallOptions"], extra?: {
|
|
298
|
-
streaming?: boolean;
|
|
299
|
-
}): ChatCompletionsInvocationParams;
|
|
300
|
-
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
301
|
-
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
302
|
-
completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming, requestOptions?: OpenAIClient.RequestOptions): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;
|
|
303
|
-
completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, requestOptions?: OpenAIClient.RequestOptions): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;
|
|
304
|
-
/** @internal */
|
|
305
|
-
protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.Chat.Completions.ChatCompletionMessage, rawResponse: OpenAIClient.Chat.Completions.ChatCompletion): BaseMessage;
|
|
306
|
-
/** @internal */
|
|
307
|
-
protected _convertCompletionsDeltaToBaseMessageChunk(delta: Record<string, any>, rawResponse: OpenAIClient.Chat.Completions.ChatCompletionChunk, defaultRole?: OpenAIClient.Chat.ChatCompletionRole): AIMessageChunk | HumanMessageChunk | SystemMessageChunk | FunctionMessageChunk | ToolMessageChunk | ChatMessageChunk;
|
|
308
|
-
}
|
|
309
|
-
export type ChatOpenAICallOptions = ChatOpenAICompletionsCallOptions & ChatOpenAIResponsesCallOptions;
|
|
310
|
-
export interface ChatOpenAIFields extends BaseChatOpenAIFields {
|
|
167
|
+
export interface ChatOpenAIFields extends Partial<OpenAIChatInput>, BaseChatModelParams {
|
|
168
|
+
configuration?: ClientOptions;
|
|
311
169
|
/**
|
|
312
170
|
* Whether to use the responses API for all requests. If `false` the responses API will be used
|
|
313
171
|
* only when required in order to fulfill the request.
|
|
@@ -359,7 +217,7 @@ export interface ChatOpenAIFields extends BaseChatOpenAIFields {
|
|
|
359
217
|
* import { ChatOpenAI } from '@langchain/openai';
|
|
360
218
|
*
|
|
361
219
|
* const llm = new ChatOpenAI({
|
|
362
|
-
* model: "gpt-4o
|
|
220
|
+
* model: "gpt-4o",
|
|
363
221
|
* temperature: 0,
|
|
364
222
|
* maxTokens: undefined,
|
|
365
223
|
* timeout: undefined,
|
|
@@ -660,7 +518,7 @@ export interface ChatOpenAIFields extends BaseChatOpenAIFields {
|
|
|
660
518
|
* <summary><strong>Logprobs</strong></summary>
|
|
661
519
|
*
|
|
662
520
|
* ```typescript
|
|
663
|
-
* const logprobsLlm = new ChatOpenAI({
|
|
521
|
+
* const logprobsLlm = new ChatOpenAI({ logprobs: true });
|
|
664
522
|
* const aiMsgForLogprobs = await logprobsLlm.invoke(input);
|
|
665
523
|
* console.log(aiMsgForLogprobs.response_metadata.logprobs);
|
|
666
524
|
* ```
|
|
@@ -852,19 +710,159 @@ export interface ChatOpenAIFields extends BaseChatOpenAIFields {
|
|
|
852
710
|
*
|
|
853
711
|
* <br />
|
|
854
712
|
*/
|
|
855
|
-
export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = ChatOpenAICallOptions> extends
|
|
713
|
+
export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = ChatOpenAICallOptions> extends BaseChatModel<CallOptions, AIMessageChunk> implements Partial<OpenAIChatInput> {
|
|
714
|
+
static lc_name(): string;
|
|
715
|
+
get callKeys(): string[];
|
|
716
|
+
lc_serializable: boolean;
|
|
717
|
+
get lc_secrets(): {
|
|
718
|
+
[key: string]: string;
|
|
719
|
+
} | undefined;
|
|
720
|
+
get lc_aliases(): Record<string, string>;
|
|
721
|
+
get lc_serializable_keys(): string[];
|
|
722
|
+
temperature?: number;
|
|
723
|
+
topP?: number;
|
|
724
|
+
frequencyPenalty?: number;
|
|
725
|
+
presencePenalty?: number;
|
|
726
|
+
n?: number;
|
|
727
|
+
logitBias?: Record<string, number>;
|
|
728
|
+
/** @deprecated Use "model" instead */
|
|
729
|
+
modelName: string;
|
|
730
|
+
model: string;
|
|
731
|
+
modelKwargs?: OpenAIChatInput["modelKwargs"];
|
|
732
|
+
stop?: string[];
|
|
733
|
+
stopSequences?: string[];
|
|
734
|
+
user?: string;
|
|
735
|
+
timeout?: number;
|
|
736
|
+
streaming: boolean;
|
|
737
|
+
streamUsage: boolean;
|
|
738
|
+
maxTokens?: number;
|
|
739
|
+
logprobs?: boolean;
|
|
740
|
+
topLogprobs?: number;
|
|
741
|
+
openAIApiKey?: string;
|
|
742
|
+
apiKey?: string;
|
|
743
|
+
organization?: string;
|
|
744
|
+
__includeRawResponse?: boolean;
|
|
745
|
+
protected client: OpenAIClient;
|
|
746
|
+
protected clientConfig: ClientOptions;
|
|
747
|
+
/**
|
|
748
|
+
* Whether the model supports the `strict` argument when passing in tools.
|
|
749
|
+
* If `undefined` the `strict` argument will not be passed to OpenAI.
|
|
750
|
+
*/
|
|
751
|
+
supportsStrictToolCalling?: boolean;
|
|
752
|
+
audio?: OpenAIClient.Chat.ChatCompletionAudioParam;
|
|
753
|
+
modalities?: Array<OpenAIClient.Chat.ChatCompletionModality>;
|
|
754
|
+
/**
|
|
755
|
+
* @deprecated Use {@link reasoning} object instead.
|
|
756
|
+
*/
|
|
757
|
+
reasoningEffort?: OpenAIClient.Chat.ChatCompletionReasoningEffort;
|
|
758
|
+
/**
|
|
759
|
+
* Options for reasoning models.
|
|
760
|
+
*/
|
|
761
|
+
reasoning?: OpenAIClient.Reasoning;
|
|
856
762
|
/**
|
|
857
763
|
* Whether to use the responses API for all requests. If `false` the responses API will be used
|
|
858
764
|
* only when required in order to fulfill the request.
|
|
859
765
|
*/
|
|
860
766
|
useResponsesApi: boolean;
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
767
|
+
/**
|
|
768
|
+
* Must be set to `true` in tenancies with Zero Data Retention. Setting to `true` will disable
|
|
769
|
+
* output storage in the Responses API, but this DOES NOT enable Zero Data Retention in your
|
|
770
|
+
* OpenAI organization or project. This must be configured directly with OpenAI.
|
|
771
|
+
*
|
|
772
|
+
* See:
|
|
773
|
+
* https://help.openai.com/en/articles/10503543-data-residency-for-the-openai-api
|
|
774
|
+
* https://platform.openai.com/docs/api-reference/responses/create#responses-create-store
|
|
775
|
+
*
|
|
776
|
+
* @default false
|
|
777
|
+
*/
|
|
778
|
+
zdrEnabled?: boolean | undefined;
|
|
779
|
+
/**
|
|
780
|
+
* Service tier to use for this request. Can be "auto", "default", or "flex" or "priority".
|
|
781
|
+
* Specifies the service tier for prioritization and latency optimization.
|
|
782
|
+
*/
|
|
783
|
+
service_tier?: ResponsesCreateParams["service_tier"];
|
|
864
784
|
constructor(fields?: ChatOpenAIFields);
|
|
865
|
-
|
|
785
|
+
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
786
|
+
bindTools(tools: ChatOpenAIToolType[], kwargs?: Partial<CallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, CallOptions>;
|
|
787
|
+
private createResponseFormat;
|
|
788
|
+
private getReasoningParams;
|
|
789
|
+
/**
|
|
790
|
+
* Get the parameters used to invoke the model
|
|
791
|
+
*/
|
|
792
|
+
invocationParams<Type extends "responses" | "completion" = "completion">(options?: this["ParsedCallOptions"], extra?: {
|
|
793
|
+
streaming?: boolean;
|
|
794
|
+
}): Type extends "responses" ? ResponseInvocationParams : ChatCompletionInvocationParams;
|
|
795
|
+
protected _convertOpenAIChatCompletionMessageToBaseMessage(message: OpenAIClient.Chat.Completions.ChatCompletionMessage, rawResponse: OpenAIClient.Chat.Completions.ChatCompletion): BaseMessage;
|
|
796
|
+
protected _convertOpenAIDeltaToBaseMessageChunk(delta: Record<string, any>, rawResponse: OpenAIClient.Chat.Completions.ChatCompletionChunk, defaultRole?: OpenAIRoleEnum): AIMessageChunk | HumanMessageChunk | SystemMessageChunk | FunctionMessageChunk | ToolMessageChunk | ChatMessageChunk;
|
|
866
797
|
/** @ignore */
|
|
867
|
-
|
|
798
|
+
_identifyingParams(): Omit<OpenAIClient.Chat.ChatCompletionCreateParams, "messages"> & {
|
|
799
|
+
model_name: string;
|
|
800
|
+
} & ClientOptions;
|
|
868
801
|
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
869
|
-
|
|
802
|
+
/**
|
|
803
|
+
* Get the identifying parameters for the model
|
|
804
|
+
*
|
|
805
|
+
*/
|
|
806
|
+
identifyingParams(): Omit<OpenAIClient.Chat.Completions.ChatCompletionCreateParams, "messages"> & {
|
|
807
|
+
model_name: string;
|
|
808
|
+
} & ClientOptions;
|
|
809
|
+
/** @ignore */
|
|
810
|
+
_responseApiGenerate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
811
|
+
/**
|
|
812
|
+
* Determines whether the responses API should be used for the given request.
|
|
813
|
+
*
|
|
814
|
+
* @internal
|
|
815
|
+
*
|
|
816
|
+
* @param options The parsed call options for the request.
|
|
817
|
+
* @returns `true` if the responses API should be used, either because it is explicitly enabled,
|
|
818
|
+
* or because the request requires it.
|
|
819
|
+
*/
|
|
820
|
+
protected _useResponseApi(options: this["ParsedCallOptions"] | undefined): boolean;
|
|
821
|
+
/** @ignore */
|
|
822
|
+
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
823
|
+
/**
|
|
824
|
+
* Estimate the number of tokens a prompt will use.
|
|
825
|
+
* Modified from: https://github.com/hmarr/openai-chat-tokens/blob/main/src/index.ts
|
|
826
|
+
*/
|
|
827
|
+
private getEstimatedTokenCountFromPrompt;
|
|
828
|
+
/**
|
|
829
|
+
* Estimate the number of tokens an array of generations have used.
|
|
830
|
+
*/
|
|
831
|
+
private getNumTokensFromGenerations;
|
|
832
|
+
getNumTokensFromMessages(messages: BaseMessage[]): Promise<{
|
|
833
|
+
totalCount: number;
|
|
834
|
+
countPerMessage: number[];
|
|
835
|
+
}>;
|
|
836
|
+
/**
|
|
837
|
+
* Calls the OpenAI API with retry logic in case of failures.
|
|
838
|
+
* @param request The request to send to the OpenAI API.
|
|
839
|
+
* @param options Optional configuration for the API call.
|
|
840
|
+
* @returns The response from the OpenAI API.
|
|
841
|
+
*/
|
|
842
|
+
completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;
|
|
843
|
+
completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;
|
|
844
|
+
protected responseApiWithRetry(request: ResponsesCreateParams & {
|
|
845
|
+
stream: true;
|
|
846
|
+
}, options?: OpenAICoreRequestOptions): Promise<ResponsesCreateStream>;
|
|
847
|
+
protected responseApiWithRetry(request: ResponsesCreateParams, options?: OpenAICoreRequestOptions): Promise<ResponsesCreateInvoke>;
|
|
848
|
+
/**
|
|
849
|
+
* Call the beta chat completions parse endpoint. This should only be called if
|
|
850
|
+
* response_format is set to "json_object".
|
|
851
|
+
* @param {OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming} request
|
|
852
|
+
* @param {OpenAICoreRequestOptions | undefined} options
|
|
853
|
+
*/
|
|
854
|
+
betaParsedCompletionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<ReturnType<OpenAIClient["chat"]["completions"]["parse"]>>;
|
|
855
|
+
protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
|
|
856
|
+
_llmType(): string;
|
|
857
|
+
/** @ignore */
|
|
858
|
+
_combineLLMOutput(...llmOutputs: OpenAILLMOutput[]): OpenAILLMOutput;
|
|
859
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: ChatOpenAIStructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
860
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: ChatOpenAIStructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
861
|
+
raw: BaseMessage;
|
|
862
|
+
parsed: RunOutput;
|
|
863
|
+
}>;
|
|
864
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: ChatOpenAIStructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
865
|
+
raw: BaseMessage;
|
|
866
|
+
parsed: RunOutput;
|
|
867
|
+
}>;
|
|
870
868
|
}
|