@langchain/openai 0.0.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/dist/llms.cjs ADDED
@@ -0,0 +1,531 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenAI = exports.OpenAIChat = void 0;
4
+ const openai_1 = require("openai");
5
+ const base_1 = require("@langchain/core/language_models/base");
6
+ const outputs_1 = require("@langchain/core/outputs");
7
+ const env_1 = require("@langchain/core/utils/env");
8
+ const llms_1 = require("@langchain/core/language_models/llms");
9
+ const azure_js_1 = require("./utils/azure.cjs");
10
+ const chunk_js_1 = require("./utils/chunk.cjs");
11
+ const legacy_js_1 = require("./legacy.cjs");
12
+ Object.defineProperty(exports, "OpenAIChat", { enumerable: true, get: function () { return legacy_js_1.OpenAIChat; } });
13
+ const openai_js_1 = require("./utils/openai.cjs");
14
+ /**
15
+ * Wrapper around OpenAI large language models.
16
+ *
17
+ * To use you should have the `openai` package installed, with the
18
+ * `OPENAI_API_KEY` environment variable set.
19
+ *
20
+ * To use with Azure you should have the `openai` package installed, with the
21
+ * `AZURE_OPENAI_API_KEY`,
22
+ * `AZURE_OPENAI_API_INSTANCE_NAME`,
23
+ * `AZURE_OPENAI_API_DEPLOYMENT_NAME`
24
+ * and `AZURE_OPENAI_API_VERSION` environment variable set.
25
+ *
26
+ * @remarks
27
+ * Any parameters that are valid to be passed to {@link
28
+ * https://platform.openai.com/docs/api-reference/completions/create |
29
+ * `openai.createCompletion`} can be passed through {@link modelKwargs}, even
30
+ * if not explicitly available on this class.
31
+ * @example
32
+ * ```typescript
33
+ * const model = new OpenAI({
34
+ * modelName: "gpt-4",
35
+ * temperature: 0.7,
36
+ * maxTokens: 1000,
37
+ * maxRetries: 5,
38
+ * });
39
+ *
40
+ * const res = await model.call(
41
+ * "Question: What would be a good company name for a company that makes colorful socks?\nAnswer:"
42
+ * );
43
+ * console.log({ res });
44
+ * ```
45
+ */
46
+ class OpenAI extends llms_1.BaseLLM {
47
+ static lc_name() {
48
+ return "OpenAI";
49
+ }
50
+ get callKeys() {
51
+ return [...super.callKeys, "options"];
52
+ }
53
+ get lc_secrets() {
54
+ return {
55
+ openAIApiKey: "OPENAI_API_KEY",
56
+ azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
57
+ organization: "OPENAI_ORGANIZATION",
58
+ };
59
+ }
60
+ get lc_aliases() {
61
+ return {
62
+ modelName: "model",
63
+ openAIApiKey: "openai_api_key",
64
+ azureOpenAIApiVersion: "azure_openai_api_version",
65
+ azureOpenAIApiKey: "azure_openai_api_key",
66
+ azureOpenAIApiInstanceName: "azure_openai_api_instance_name",
67
+ azureOpenAIApiDeploymentName: "azure_openai_api_deployment_name",
68
+ };
69
+ }
70
+ constructor(fields,
71
+ /** @deprecated */
72
+ configuration) {
73
+ if ((fields?.modelName?.startsWith("gpt-3.5-turbo") ||
74
+ fields?.modelName?.startsWith("gpt-4")) &&
75
+ !fields?.modelName?.includes("-instruct")) {
76
+ // eslint-disable-next-line no-constructor-return
77
+ return new legacy_js_1.OpenAIChat(fields, configuration);
78
+ }
79
+ super(fields ?? {});
80
+ Object.defineProperty(this, "lc_serializable", {
81
+ enumerable: true,
82
+ configurable: true,
83
+ writable: true,
84
+ value: true
85
+ });
86
+ Object.defineProperty(this, "temperature", {
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true,
90
+ value: 0.7
91
+ });
92
+ Object.defineProperty(this, "maxTokens", {
93
+ enumerable: true,
94
+ configurable: true,
95
+ writable: true,
96
+ value: 256
97
+ });
98
+ Object.defineProperty(this, "topP", {
99
+ enumerable: true,
100
+ configurable: true,
101
+ writable: true,
102
+ value: 1
103
+ });
104
+ Object.defineProperty(this, "frequencyPenalty", {
105
+ enumerable: true,
106
+ configurable: true,
107
+ writable: true,
108
+ value: 0
109
+ });
110
+ Object.defineProperty(this, "presencePenalty", {
111
+ enumerable: true,
112
+ configurable: true,
113
+ writable: true,
114
+ value: 0
115
+ });
116
+ Object.defineProperty(this, "n", {
117
+ enumerable: true,
118
+ configurable: true,
119
+ writable: true,
120
+ value: 1
121
+ });
122
+ Object.defineProperty(this, "bestOf", {
123
+ enumerable: true,
124
+ configurable: true,
125
+ writable: true,
126
+ value: void 0
127
+ });
128
+ Object.defineProperty(this, "logitBias", {
129
+ enumerable: true,
130
+ configurable: true,
131
+ writable: true,
132
+ value: void 0
133
+ });
134
+ Object.defineProperty(this, "modelName", {
135
+ enumerable: true,
136
+ configurable: true,
137
+ writable: true,
138
+ value: "gpt-3.5-turbo-instruct"
139
+ });
140
+ Object.defineProperty(this, "modelKwargs", {
141
+ enumerable: true,
142
+ configurable: true,
143
+ writable: true,
144
+ value: void 0
145
+ });
146
+ Object.defineProperty(this, "batchSize", {
147
+ enumerable: true,
148
+ configurable: true,
149
+ writable: true,
150
+ value: 20
151
+ });
152
+ Object.defineProperty(this, "timeout", {
153
+ enumerable: true,
154
+ configurable: true,
155
+ writable: true,
156
+ value: void 0
157
+ });
158
+ Object.defineProperty(this, "stop", {
159
+ enumerable: true,
160
+ configurable: true,
161
+ writable: true,
162
+ value: void 0
163
+ });
164
+ Object.defineProperty(this, "user", {
165
+ enumerable: true,
166
+ configurable: true,
167
+ writable: true,
168
+ value: void 0
169
+ });
170
+ Object.defineProperty(this, "streaming", {
171
+ enumerable: true,
172
+ configurable: true,
173
+ writable: true,
174
+ value: false
175
+ });
176
+ Object.defineProperty(this, "openAIApiKey", {
177
+ enumerable: true,
178
+ configurable: true,
179
+ writable: true,
180
+ value: void 0
181
+ });
182
+ Object.defineProperty(this, "azureOpenAIApiVersion", {
183
+ enumerable: true,
184
+ configurable: true,
185
+ writable: true,
186
+ value: void 0
187
+ });
188
+ Object.defineProperty(this, "azureOpenAIApiKey", {
189
+ enumerable: true,
190
+ configurable: true,
191
+ writable: true,
192
+ value: void 0
193
+ });
194
+ Object.defineProperty(this, "azureOpenAIApiInstanceName", {
195
+ enumerable: true,
196
+ configurable: true,
197
+ writable: true,
198
+ value: void 0
199
+ });
200
+ Object.defineProperty(this, "azureOpenAIApiDeploymentName", {
201
+ enumerable: true,
202
+ configurable: true,
203
+ writable: true,
204
+ value: void 0
205
+ });
206
+ Object.defineProperty(this, "azureOpenAIBasePath", {
207
+ enumerable: true,
208
+ configurable: true,
209
+ writable: true,
210
+ value: void 0
211
+ });
212
+ Object.defineProperty(this, "organization", {
213
+ enumerable: true,
214
+ configurable: true,
215
+ writable: true,
216
+ value: void 0
217
+ });
218
+ Object.defineProperty(this, "client", {
219
+ enumerable: true,
220
+ configurable: true,
221
+ writable: true,
222
+ value: void 0
223
+ });
224
+ Object.defineProperty(this, "clientConfig", {
225
+ enumerable: true,
226
+ configurable: true,
227
+ writable: true,
228
+ value: void 0
229
+ });
230
+ this.openAIApiKey =
231
+ fields?.openAIApiKey ?? (0, env_1.getEnvironmentVariable)("OPENAI_API_KEY");
232
+ this.azureOpenAIApiKey =
233
+ fields?.azureOpenAIApiKey ??
234
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_KEY");
235
+ if (!this.azureOpenAIApiKey && !this.openAIApiKey) {
236
+ throw new Error("OpenAI or Azure OpenAI API key not found");
237
+ }
238
+ this.azureOpenAIApiInstanceName =
239
+ fields?.azureOpenAIApiInstanceName ??
240
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_INSTANCE_NAME");
241
+ this.azureOpenAIApiDeploymentName =
242
+ (fields?.azureOpenAIApiCompletionsDeploymentName ||
243
+ fields?.azureOpenAIApiDeploymentName) ??
244
+ ((0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_COMPLETIONS_DEPLOYMENT_NAME") ||
245
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_DEPLOYMENT_NAME"));
246
+ this.azureOpenAIApiVersion =
247
+ fields?.azureOpenAIApiVersion ??
248
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_VERSION");
249
+ this.azureOpenAIBasePath =
250
+ fields?.azureOpenAIBasePath ??
251
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_BASE_PATH");
252
+ this.organization =
253
+ fields?.configuration?.organization ??
254
+ (0, env_1.getEnvironmentVariable)("OPENAI_ORGANIZATION");
255
+ this.modelName = fields?.modelName ?? this.modelName;
256
+ this.modelKwargs = fields?.modelKwargs ?? {};
257
+ this.batchSize = fields?.batchSize ?? this.batchSize;
258
+ this.timeout = fields?.timeout;
259
+ this.temperature = fields?.temperature ?? this.temperature;
260
+ this.maxTokens = fields?.maxTokens ?? this.maxTokens;
261
+ this.topP = fields?.topP ?? this.topP;
262
+ this.frequencyPenalty = fields?.frequencyPenalty ?? this.frequencyPenalty;
263
+ this.presencePenalty = fields?.presencePenalty ?? this.presencePenalty;
264
+ this.n = fields?.n ?? this.n;
265
+ this.bestOf = fields?.bestOf ?? this.bestOf;
266
+ this.logitBias = fields?.logitBias;
267
+ this.stop = fields?.stop;
268
+ this.user = fields?.user;
269
+ this.streaming = fields?.streaming ?? false;
270
+ if (this.streaming && this.bestOf && this.bestOf > 1) {
271
+ throw new Error("Cannot stream results when bestOf > 1");
272
+ }
273
+ if (this.azureOpenAIApiKey) {
274
+ if (!this.azureOpenAIApiInstanceName && !this.azureOpenAIBasePath) {
275
+ throw new Error("Azure OpenAI API instance name not found");
276
+ }
277
+ if (!this.azureOpenAIApiDeploymentName) {
278
+ throw new Error("Azure OpenAI API deployment name not found");
279
+ }
280
+ if (!this.azureOpenAIApiVersion) {
281
+ throw new Error("Azure OpenAI API version not found");
282
+ }
283
+ this.openAIApiKey = this.openAIApiKey ?? "";
284
+ }
285
+ this.clientConfig = {
286
+ apiKey: this.openAIApiKey,
287
+ organization: this.organization,
288
+ baseURL: configuration?.basePath ?? fields?.configuration?.basePath,
289
+ dangerouslyAllowBrowser: true,
290
+ defaultHeaders: configuration?.baseOptions?.headers ??
291
+ fields?.configuration?.baseOptions?.headers,
292
+ defaultQuery: configuration?.baseOptions?.params ??
293
+ fields?.configuration?.baseOptions?.params,
294
+ ...configuration,
295
+ ...fields?.configuration,
296
+ };
297
+ }
298
+ /**
299
+ * Get the parameters used to invoke the model
300
+ */
301
+ invocationParams(options) {
302
+ return {
303
+ model: this.modelName,
304
+ temperature: this.temperature,
305
+ max_tokens: this.maxTokens,
306
+ top_p: this.topP,
307
+ frequency_penalty: this.frequencyPenalty,
308
+ presence_penalty: this.presencePenalty,
309
+ n: this.n,
310
+ best_of: this.bestOf,
311
+ logit_bias: this.logitBias,
312
+ stop: options?.stop ?? this.stop,
313
+ user: this.user,
314
+ stream: this.streaming,
315
+ ...this.modelKwargs,
316
+ };
317
+ }
318
+ /** @ignore */
319
+ _identifyingParams() {
320
+ return {
321
+ model_name: this.modelName,
322
+ ...this.invocationParams(),
323
+ ...this.clientConfig,
324
+ };
325
+ }
326
+ /**
327
+ * Get the identifying parameters for the model
328
+ */
329
+ identifyingParams() {
330
+ return this._identifyingParams();
331
+ }
332
+ /**
333
+ * Call out to OpenAI's endpoint with k unique prompts
334
+ *
335
+ * @param [prompts] - The prompts to pass into the model.
336
+ * @param [options] - Optional list of stop words to use when generating.
337
+ * @param [runManager] - Optional callback manager to use when generating.
338
+ *
339
+ * @returns The full LLM output.
340
+ *
341
+ * @example
342
+ * ```ts
343
+ * import { OpenAI } from "langchain/llms/openai";
344
+ * const openai = new OpenAI();
345
+ * const response = await openai.generate(["Tell me a joke."]);
346
+ * ```
347
+ */
348
+ async _generate(prompts, options, runManager) {
349
+ const subPrompts = (0, chunk_js_1.chunkArray)(prompts, this.batchSize);
350
+ const choices = [];
351
+ const tokenUsage = {};
352
+ const params = this.invocationParams(options);
353
+ if (params.max_tokens === -1) {
354
+ if (prompts.length !== 1) {
355
+ throw new Error("max_tokens set to -1 not supported for multiple inputs");
356
+ }
357
+ params.max_tokens = await (0, base_1.calculateMaxTokens)({
358
+ prompt: prompts[0],
359
+ // Cast here to allow for other models that may not fit the union
360
+ modelName: this.modelName,
361
+ });
362
+ }
363
+ for (let i = 0; i < subPrompts.length; i += 1) {
364
+ const data = params.stream
365
+ ? await (async () => {
366
+ const choices = [];
367
+ let response;
368
+ const stream = await this.completionWithRetry({
369
+ ...params,
370
+ stream: true,
371
+ prompt: subPrompts[i],
372
+ }, options);
373
+ for await (const message of stream) {
374
+ // on the first message set the response properties
375
+ if (!response) {
376
+ response = {
377
+ id: message.id,
378
+ object: message.object,
379
+ created: message.created,
380
+ model: message.model,
381
+ };
382
+ }
383
+ // on all messages, update choice
384
+ for (const part of message.choices) {
385
+ if (!choices[part.index]) {
386
+ choices[part.index] = part;
387
+ }
388
+ else {
389
+ const choice = choices[part.index];
390
+ choice.text += part.text;
391
+ choice.finish_reason = part.finish_reason;
392
+ choice.logprobs = part.logprobs;
393
+ }
394
+ void runManager?.handleLLMNewToken(part.text, {
395
+ prompt: Math.floor(part.index / this.n),
396
+ completion: part.index % this.n,
397
+ });
398
+ }
399
+ }
400
+ if (options.signal?.aborted) {
401
+ throw new Error("AbortError");
402
+ }
403
+ return { ...response, choices };
404
+ })()
405
+ : await this.completionWithRetry({
406
+ ...params,
407
+ stream: false,
408
+ prompt: subPrompts[i],
409
+ }, {
410
+ signal: options.signal,
411
+ ...options.options,
412
+ });
413
+ choices.push(...data.choices);
414
+ const { completion_tokens: completionTokens, prompt_tokens: promptTokens, total_tokens: totalTokens, } = data.usage
415
+ ? data.usage
416
+ : {
417
+ completion_tokens: undefined,
418
+ prompt_tokens: undefined,
419
+ total_tokens: undefined,
420
+ };
421
+ if (completionTokens) {
422
+ tokenUsage.completionTokens =
423
+ (tokenUsage.completionTokens ?? 0) + completionTokens;
424
+ }
425
+ if (promptTokens) {
426
+ tokenUsage.promptTokens = (tokenUsage.promptTokens ?? 0) + promptTokens;
427
+ }
428
+ if (totalTokens) {
429
+ tokenUsage.totalTokens = (tokenUsage.totalTokens ?? 0) + totalTokens;
430
+ }
431
+ }
432
+ const generations = (0, chunk_js_1.chunkArray)(choices, this.n).map((promptChoices) => promptChoices.map((choice) => ({
433
+ text: choice.text ?? "",
434
+ generationInfo: {
435
+ finishReason: choice.finish_reason,
436
+ logprobs: choice.logprobs,
437
+ },
438
+ })));
439
+ return {
440
+ generations,
441
+ llmOutput: { tokenUsage },
442
+ };
443
+ }
444
+ // TODO(jacoblee): Refactor with _generate(..., {stream: true}) implementation?
445
+ async *_streamResponseChunks(input, options, runManager) {
446
+ const params = {
447
+ ...this.invocationParams(options),
448
+ prompt: input,
449
+ stream: true,
450
+ };
451
+ const stream = await this.completionWithRetry(params, options);
452
+ for await (const data of stream) {
453
+ const choice = data?.choices[0];
454
+ if (!choice) {
455
+ continue;
456
+ }
457
+ const chunk = new outputs_1.GenerationChunk({
458
+ text: choice.text,
459
+ generationInfo: {
460
+ finishReason: choice.finish_reason,
461
+ },
462
+ });
463
+ yield chunk;
464
+ // eslint-disable-next-line no-void
465
+ void runManager?.handleLLMNewToken(chunk.text ?? "");
466
+ }
467
+ if (options.signal?.aborted) {
468
+ throw new Error("AbortError");
469
+ }
470
+ }
471
+ async completionWithRetry(request, options) {
472
+ const requestOptions = this._getClientOptions(options);
473
+ return this.caller.call(async () => {
474
+ try {
475
+ const res = await this.client.completions.create(request, requestOptions);
476
+ return res;
477
+ }
478
+ catch (e) {
479
+ const error = (0, openai_js_1.wrapOpenAIClientError)(e);
480
+ throw error;
481
+ }
482
+ });
483
+ }
484
+ /**
485
+ * Calls the OpenAI API with retry logic in case of failures.
486
+ * @param request The request to send to the OpenAI API.
487
+ * @param options Optional configuration for the API call.
488
+ * @returns The response from the OpenAI API.
489
+ */
490
+ _getClientOptions(options) {
491
+ if (!this.client) {
492
+ const openAIEndpointConfig = {
493
+ azureOpenAIApiDeploymentName: this.azureOpenAIApiDeploymentName,
494
+ azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
495
+ azureOpenAIApiKey: this.azureOpenAIApiKey,
496
+ azureOpenAIBasePath: this.azureOpenAIBasePath,
497
+ baseURL: this.clientConfig.baseURL,
498
+ };
499
+ const endpoint = (0, azure_js_1.getEndpoint)(openAIEndpointConfig);
500
+ const params = {
501
+ ...this.clientConfig,
502
+ baseURL: endpoint,
503
+ timeout: this.timeout,
504
+ maxRetries: 0,
505
+ };
506
+ if (!params.baseURL) {
507
+ delete params.baseURL;
508
+ }
509
+ this.client = new openai_1.OpenAI(params);
510
+ }
511
+ const requestOptions = {
512
+ ...this.clientConfig,
513
+ ...options,
514
+ };
515
+ if (this.azureOpenAIApiKey) {
516
+ requestOptions.headers = {
517
+ "api-key": this.azureOpenAIApiKey,
518
+ ...requestOptions.headers,
519
+ };
520
+ requestOptions.query = {
521
+ "api-version": this.azureOpenAIApiVersion,
522
+ ...requestOptions.query,
523
+ };
524
+ }
525
+ return requestOptions;
526
+ }
527
+ _llmType() {
528
+ return "openai";
529
+ }
530
+ }
531
+ exports.OpenAI = OpenAI;
package/dist/llms.d.ts ADDED
@@ -0,0 +1,126 @@
1
+ import { type ClientOptions, OpenAI as OpenAIClient } from "openai";
2
+ import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
3
+ import { GenerationChunk, type LLMResult } from "@langchain/core/outputs";
4
+ import { BaseLLM, type BaseLLMParams } from "@langchain/core/language_models/llms";
5
+ import type { AzureOpenAIInput, OpenAICallOptions, OpenAICoreRequestOptions, OpenAIInput, LegacyOpenAIInput } from "./types.js";
6
+ import { OpenAIChat, OpenAIChatCallOptions } from "./legacy.js";
7
+ export type { AzureOpenAIInput, OpenAICallOptions, OpenAIInput, OpenAIChatCallOptions, };
8
+ export { OpenAIChat };
9
+ /**
10
+ * Wrapper around OpenAI large language models.
11
+ *
12
+ * To use you should have the `openai` package installed, with the
13
+ * `OPENAI_API_KEY` environment variable set.
14
+ *
15
+ * To use with Azure you should have the `openai` package installed, with the
16
+ * `AZURE_OPENAI_API_KEY`,
17
+ * `AZURE_OPENAI_API_INSTANCE_NAME`,
18
+ * `AZURE_OPENAI_API_DEPLOYMENT_NAME`
19
+ * and `AZURE_OPENAI_API_VERSION` environment variable set.
20
+ *
21
+ * @remarks
22
+ * Any parameters that are valid to be passed to {@link
23
+ * https://platform.openai.com/docs/api-reference/completions/create |
24
+ * `openai.createCompletion`} can be passed through {@link modelKwargs}, even
25
+ * if not explicitly available on this class.
26
+ * @example
27
+ * ```typescript
28
+ * const model = new OpenAI({
29
+ * modelName: "gpt-4",
30
+ * temperature: 0.7,
31
+ * maxTokens: 1000,
32
+ * maxRetries: 5,
33
+ * });
34
+ *
35
+ * const res = await model.call(
36
+ * "Question: What would be a good company name for a company that makes colorful socks?\nAnswer:"
37
+ * );
38
+ * console.log({ res });
39
+ * ```
40
+ */
41
+ export declare class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOptions> extends BaseLLM<CallOptions> implements OpenAIInput, AzureOpenAIInput {
42
+ static lc_name(): string;
43
+ get callKeys(): string[];
44
+ lc_serializable: boolean;
45
+ get lc_secrets(): {
46
+ [key: string]: string;
47
+ } | undefined;
48
+ get lc_aliases(): Record<string, string>;
49
+ temperature: number;
50
+ maxTokens: number;
51
+ topP: number;
52
+ frequencyPenalty: number;
53
+ presencePenalty: number;
54
+ n: number;
55
+ bestOf?: number;
56
+ logitBias?: Record<string, number>;
57
+ modelName: string;
58
+ modelKwargs?: OpenAIInput["modelKwargs"];
59
+ batchSize: number;
60
+ timeout?: number;
61
+ stop?: string[];
62
+ user?: string;
63
+ streaming: boolean;
64
+ openAIApiKey?: string;
65
+ azureOpenAIApiVersion?: string;
66
+ azureOpenAIApiKey?: string;
67
+ azureOpenAIApiInstanceName?: string;
68
+ azureOpenAIApiDeploymentName?: string;
69
+ azureOpenAIBasePath?: string;
70
+ organization?: string;
71
+ private client;
72
+ private clientConfig;
73
+ constructor(fields?: Partial<OpenAIInput> & Partial<AzureOpenAIInput> & BaseLLMParams & {
74
+ configuration?: ClientOptions & LegacyOpenAIInput;
75
+ },
76
+ /** @deprecated */
77
+ configuration?: ClientOptions & LegacyOpenAIInput);
78
+ /**
79
+ * Get the parameters used to invoke the model
80
+ */
81
+ invocationParams(options?: this["ParsedCallOptions"]): Omit<OpenAIClient.CompletionCreateParams, "prompt">;
82
+ /** @ignore */
83
+ _identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, "prompt"> & {
84
+ model_name: string;
85
+ } & ClientOptions;
86
+ /**
87
+ * Get the identifying parameters for the model
88
+ */
89
+ identifyingParams(): Omit<OpenAIClient.CompletionCreateParams, "prompt"> & {
90
+ model_name: string;
91
+ } & ClientOptions;
92
+ /**
93
+ * Call out to OpenAI's endpoint with k unique prompts
94
+ *
95
+ * @param [prompts] - The prompts to pass into the model.
96
+ * @param [options] - Optional list of stop words to use when generating.
97
+ * @param [runManager] - Optional callback manager to use when generating.
98
+ *
99
+ * @returns The full LLM output.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { OpenAI } from "langchain/llms/openai";
104
+ * const openai = new OpenAI();
105
+ * const response = await openai.generate(["Tell me a joke."]);
106
+ * ```
107
+ */
108
+ _generate(prompts: string[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<LLMResult>;
109
+ _streamResponseChunks(input: string, options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;
110
+ /**
111
+ * Calls the OpenAI API with retry logic in case of failures.
112
+ * @param request The request to send to the OpenAI API.
113
+ * @param options Optional configuration for the API call.
114
+ * @returns The response from the OpenAI API.
115
+ */
116
+ completionWithRetry(request: OpenAIClient.CompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Completion>>;
117
+ completionWithRetry(request: OpenAIClient.CompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Completions.Completion>;
118
+ /**
119
+ * Calls the OpenAI API with retry logic in case of failures.
120
+ * @param request The request to send to the OpenAI API.
121
+ * @param options Optional configuration for the API call.
122
+ * @returns The response from the OpenAI API.
123
+ */
124
+ private _getClientOptions;
125
+ _llmType(): string;
126
+ }