File size: 14,695 Bytes
c2b7eb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import { ChatOpenAIToolType, OpenAIToolChoice, ResponsesToolChoice } from "../utils/tools.js";
import { ChatOpenAIResponseFormat, OpenAIApiKey, OpenAICacheRetentionParam, OpenAICallOptions, OpenAIChatInput, OpenAICoreRequestOptions, OpenAIVerbosityParam, ResponseFormatConfiguration } from "../types.js";
import OpenAI$1, { ClientOptions, OpenAI } from "openai";
import * as _$_langchain_core_messages0 from "@langchain/core/messages";
import { AIMessageChunk, BaseMessage } from "@langchain/core/messages";
import { ChatGeneration } from "@langchain/core/outputs";
import { InteropZodType } from "@langchain/core/utils/types";
import { BaseChatModel, BaseChatModelCallOptions, BaseChatModelParams, LangSmithParams } from "@langchain/core/language_models/chat_models";
import { BaseFunctionCallOptions, BaseLanguageModelInput, StructuredOutputMethodOptions } from "@langchain/core/language_models/base";
import { Runnable } from "@langchain/core/runnables";
import { SerializableSchema } from "@langchain/core/utils/standard_schema";
import * as _$_langchain_core_utils_stream0 from "@langchain/core/utils/stream";
import { ModelProfile } from "@langchain/core/language_models/profile";

//#region src/chat_models/base.d.ts
interface OpenAILLMOutput {
  tokenUsage: {
    completionTokens?: number;
    promptTokens?: number;
    totalTokens?: number;
  };
}
interface BaseChatOpenAICallOptions extends BaseChatModelCallOptions, BaseFunctionCallOptions {
  /**
   * Additional options to pass to the underlying axios request.
   */
  options?: OpenAICoreRequestOptions;
  /**
   * A list of tools that the model may use to generate responses.
   * Each tool can be a function, a built-in tool, or a custom tool definition.
   * If not provided, the model will not use any tools.
   */
  tools?: ChatOpenAIToolType[];
  /**
   * Specifies which tool the model should use to respond.
   * Can be an {@link OpenAIToolChoice} or a {@link ResponsesToolChoice}.
   * If not set, the model will decide which tool to use automatically.
   */
  tool_choice?: OpenAIToolChoice | ResponsesToolChoice;
  /**
   * Adds a prompt index to prompts passed to the model to track
   * what prompt is being used for a given generation.
   */
  promptIndex?: number;
  /**
   * An object specifying the format that the model must output.
   */
  response_format?: ChatOpenAIResponseFormat;
  /**
   * When provided, the completions API will make a best effort to sample
   * deterministically, such that repeated requests with the same `seed`
   * and parameters should return the same result.
   */
  seed?: number;
  /**
   * Additional options to pass to streamed completions.
   * If provided, this takes precedence over "streamUsage" set at
   * initialization time.
   */
  stream_options?: OpenAI.Chat.ChatCompletionStreamOptions;
  /**
   * The model may choose to call multiple functions in a single turn. You can
   * set parallel_tool_calls to false which ensures only one tool is called at most.
   * [Learn more](https://platform.openai.com/docs/guides/function-calling#parallel-function-calling)
   */
  parallel_tool_calls?: boolean;
  /**
   * If `true`, model output is guaranteed to exactly match the JSON Schema
   * provided in the tool definition. If `true`, the input schema will also be
   * validated according to
   * https://platform.openai.com/docs/guides/structured-outputs/supported-schemas.
   *
   * If `false`, input schema will not be validated and model output will not
   * be validated.
   *
   * If `undefined`, `strict` argument will not be passed to the model.
   */
  strict?: boolean;
  /**
   * Output types that you would like the model to generate for this request. Most
   * models are capable of generating text, which is the default:
   *
   * `["text"]`
   *
   * The `gpt-4o-audio-preview` model can also be used to
   * [generate audio](https://platform.openai.com/docs/guides/audio). To request that
   * this model generate both text and audio responses, you can use:
   *
   * `["text", "audio"]`
   */
  modalities?: Array<OpenAI.Chat.ChatCompletionModality>;
  /**
   * Parameters for audio output. Required when audio output is requested with
   * `modalities: ["audio"]`.
   * [Learn more](https://platform.openai.com/docs/guides/audio).
   */
  audio?: OpenAI.Chat.ChatCompletionAudioParam;
  /**
   * Static predicted output content, such as the content of a text file that is being regenerated.
   * [Learn more](https://platform.openai.com/docs/guides/latency-optimization#use-predicted-outputs).
   */
  prediction?: OpenAI.ChatCompletionPredictionContent;
  /**
   * Options for reasoning models.
   *
   * Note that some options, like reasoning summaries, are only available when using the responses
   * API. If these options are set, the responses API will be used to fulfill the request.
   *
   * These options will be ignored when not using a reasoning model.
   */
  reasoning?: OpenAI.Reasoning;
  /**
   * Constrains effort on reasoning for reasoning models. Reduces reasoning in responses,
   * which can reduce latency and cost at the expense of quality.
   *
   * Accepts values: "low", "medium", or "high".
   *
   * @deprecated This is a convenience option that will be merged into the `reasoning` object.
   * Use `reasoning.effort` instead.
   */
  reasoningEffort?: OpenAI.Reasoning["effort"];
  /**
   * Service tier to use for this request. Can be "auto", "default", or "flex"
   * Specifies the service tier for prioritization and latency optimization.
   */
  service_tier?: OpenAI.Chat.ChatCompletionCreateParams["service_tier"];
  /**
   * Used by OpenAI to cache responses for similar requests to optimize your cache
   * hit rates. Replaces the `user` field.
   * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
   */
  promptCacheKey?: string;
  /**
   * Used by OpenAI to set cache retention time
   */
  promptCacheRetention?: OpenAICacheRetentionParam;
  /**
   * The verbosity of the model's response.
   */
  verbosity?: OpenAIVerbosityParam;
}
interface BaseChatOpenAIFields extends Partial<OpenAIChatInput>, BaseChatModelParams {
  /**
   * Optional configuration options for the OpenAI client.
   */
  configuration?: ClientOptions;
}
/** @internal */
declare abstract class BaseChatOpenAI<CallOptions extends BaseChatOpenAICallOptions> extends BaseChatModel<CallOptions, AIMessageChunk> implements Partial<OpenAIChatInput> {
  temperature?: number;
  topP?: number;
  frequencyPenalty?: number;
  presencePenalty?: number;
  n?: number;
  logitBias?: Record<string, number>;
  model: string;
  modelKwargs?: OpenAIChatInput["modelKwargs"];
  stop?: string[];
  stopSequences?: string[];
  user?: string;
  timeout?: number;
  streaming: boolean;
  streamUsage: boolean;
  maxTokens?: number;
  logprobs?: boolean;
  topLogprobs?: number;
  apiKey?: OpenAIApiKey;
  organization?: string;
  __includeRawResponse?: boolean;
  /** @internal */
  client: OpenAI;
  /** @internal */
  clientConfig: ClientOptions;
  /**
   * Whether the model supports the `strict` argument when passing in tools.
   * If `undefined` the `strict` argument will not be passed to OpenAI.
   */
  supportsStrictToolCalling?: boolean;
  audio?: OpenAI.Chat.ChatCompletionAudioParam;
  modalities?: Array<OpenAI.Chat.ChatCompletionModality>;
  reasoning?: OpenAI.Reasoning;
  /**
   * Must be set to `true` in tenancies with Zero Data Retention. Setting to `true` will disable
   * output storage in the Responses API, but this DOES NOT enable Zero Data Retention in your
   * OpenAI organization or project. This must be configured directly with OpenAI.
   *
   * See:
   * https://platform.openai.com/docs/guides/your-data
   * https://platform.openai.com/docs/api-reference/responses/create#responses-create-store
   *
   * @default false
   */
  zdrEnabled?: boolean | undefined;
  /**
   * Service tier to use for this request. Can be "auto", "default", or "flex" or "priority".
   * Specifies the service tier for prioritization and latency optimization.
   */
  service_tier?: OpenAI.Chat.ChatCompletionCreateParams["service_tier"];
  /**
   * Used by OpenAI to cache responses for similar requests to optimize your cache
   * hit rates.
   * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
   */
  promptCacheKey: string;
  /**
   * Used by OpenAI to set cache retention time
   */
  promptCacheRetention?: OpenAICacheRetentionParam;
  /**
   * The verbosity of the model's response.
   */
  verbosity?: OpenAIVerbosityParam;
  protected defaultOptions: CallOptions;
  _llmType(): string;
  static lc_name(): string;
  get callKeys(): string[];
  lc_serializable: boolean;
  get lc_secrets(): {
    [key: string]: string;
  } | undefined;
  get lc_aliases(): Record<string, string>;
  get lc_serializable_keys(): string[];
  getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
  /** @ignore */
  _identifyingParams(): Omit<OpenAI.Chat.ChatCompletionCreateParams, "messages"> & {
    model_name: string;
  } & ClientOptions;
  /**
   * Get the identifying parameters for the model
   */
  identifyingParams(): Omit<OpenAI$1.ChatCompletionCreateParams, "messages"> & {
    model_name: string;
  } & ClientOptions;
  constructor(fields?: BaseChatOpenAIFields);
  /**
   * Returns backwards compatible reasoning parameters from constructor params and call options
   * @internal
   */
  protected _getReasoningParams(options?: this["ParsedCallOptions"]): OpenAI.Reasoning | undefined;
  /**
   * Returns an openai compatible response format from a set of options
   * @internal
   */
  protected _getResponseFormat(resFormat?: CallOptions["response_format"]): ResponseFormatConfiguration | undefined;
  protected _combineCallOptions(additionalOptions?: this["ParsedCallOptions"]): this["ParsedCallOptions"];
  /** @internal */
  _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
  protected _convertChatOpenAIToolToCompletionsTool(tool: ChatOpenAIToolType, fields?: {
    strict?: boolean;
  }): OpenAI.ChatCompletionTool;
  bindTools(tools: ChatOpenAIToolType[], kwargs?: Partial<CallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, CallOptions>;
  stream(input: BaseLanguageModelInput, options?: CallOptions): Promise<_$_langchain_core_utils_stream0.IterableReadableStream<AIMessageChunk<_$_langchain_core_messages0.MessageStructure<_$_langchain_core_messages0.MessageToolSet>>>>;
  invoke(input: BaseLanguageModelInput, options?: CallOptions): Promise<AIMessageChunk<_$_langchain_core_messages0.MessageStructure<_$_langchain_core_messages0.MessageToolSet>>>;
  /** @ignore */
  _combineLLMOutput(...llmOutputs: OpenAILLMOutput[]): OpenAILLMOutput;
  getNumTokensFromMessages(messages: BaseMessage[]): Promise<{
    totalCount: number;
    countPerMessage: number[];
  }>;
  /** @internal */
  protected _getNumTokensFromGenerations(generations: ChatGeneration[]): Promise<number>;
  /** @internal */
  protected _getEstimatedTokenCountFromPrompt(messages: BaseMessage[], functions?: OpenAI.Chat.ChatCompletionCreateParams.Function[], function_call?: "none" | "auto" | OpenAI.Chat.ChatCompletionFunctionCallOption): Promise<number>;
  /**
   * Moderate content using OpenAI's Moderation API.
   *
   * This method checks whether content violates OpenAI's content policy by
   * analyzing text for categories such as hate, harassment, self-harm,
   * sexual content, violence, and more.
   *
   * @param input - The text or array of texts to moderate
   * @param params - Optional parameters for the moderation request
   * @param params.model - The moderation model to use. Defaults to "omni-moderation-latest".
   * @param params.options - Additional options to pass to the underlying request
   * @returns A promise that resolves to the moderation response containing results for each input
   *
   * @example
   * ```typescript
   * const model = new ChatOpenAI({ model: "gpt-4o-mini" });
   *
   * // Moderate a single text
   * const result = await model.moderateContent("This is a test message");
   * console.log(result.results[0].flagged); // false
   * console.log(result.results[0].categories); // { hate: false, harassment: false, ... }
   *
   * // Moderate multiple texts
   * const results = await model.moderateContent([
   *   "Hello, how are you?",
   *   "This is inappropriate content"
   * ]);
   * results.results.forEach((result, index) => {
   *   console.log(`Text ${index + 1} flagged:`, result.flagged);
   * });
   *
   * // Use a specific moderation model
   * const stableResult = await model.moderateContent(
   *   "Test content",
   *   { model: "omni-moderation-latest" }
   * );
   * ```
   */
  moderateContent(input: string | string[], params?: {
    model?: OpenAI$1.ModerationModel;
    options?: OpenAICoreRequestOptions;
  }): Promise<OpenAI.ModerationCreateResponse>;
  /**
   * Return profiling information for the model.
   *
   * Provides information about the model's capabilities and constraints,
   * including token limits, multimodal support, and advanced features like
   * tool calling and structured output.
   *
   * @returns {ModelProfile} An object describing the model's capabilities and constraints
   *
   * @example
   * ```typescript
   * const model = new ChatOpenAI({ model: "gpt-4o" });
   * const profile = model.profile;
   * console.log(profile.maxInputTokens); // 128000
   * console.log(profile.imageInputs); // true
   * ```
   */
  get profile(): ModelProfile;
  /** @internal */
  protected _getStructuredOutputMethod(config: StructuredOutputMethodOptions<boolean>): string | undefined;
  withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | SerializableSchema<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
  withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | SerializableSchema<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
    raw: BaseMessage;
    parsed: RunOutput;
  }>;
  withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | SerializableSchema<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
    raw: BaseMessage;
    parsed: RunOutput;
  }>;
}
//#endregion
export { BaseChatOpenAI, BaseChatOpenAICallOptions, BaseChatOpenAIFields };
//# sourceMappingURL=base.d.ts.map