ai 3.1.0-canary.2 → 3.1.0-canary.4

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.
@@ -48,6 +48,10 @@ type LanguageModelV1CallSettings = {
48
48
  * by the model, calls will generate deterministic results.
49
49
  */
50
50
  seed?: number;
51
+ /**
52
+ * Abort signal for cancelling the operation.
53
+ */
54
+ abortSignal?: AbortSignal;
51
55
  };
52
56
 
53
57
  /**
@@ -103,9 +107,9 @@ interface LanguageModelV1TextPart {
103
107
  interface LanguageModelV1ImagePart {
104
108
  type: 'image';
105
109
  /**
106
- * Image data as a Uint8Array.
110
+ * Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
107
111
  */
108
- image: Uint8Array;
112
+ image: Uint8Array | URL;
109
113
  /**
110
114
  * Optional mime type of the image.
111
115
  */
@@ -231,6 +235,32 @@ type LanguageModelV1 = {
231
235
  * model has only generated text.
232
236
  */
233
237
  toolCalls?: Array<LanguageModelV1FunctionToolCall>;
238
+ /**
239
+ * Finish reason.
240
+ */
241
+ finishReason: LanguageModelV1FinishReason;
242
+ /**
243
+ * Usage information.
244
+ */
245
+ usage: {
246
+ promptTokens: number;
247
+ completionTokens: number;
248
+ };
249
+ /**
250
+ * Raw prompt and setting information for observability provider integration.
251
+ */
252
+ rawCall: {
253
+ /**
254
+ * Raw prompt after expansion and conversion to the format that the
255
+ * provider uses to send the information to their API.
256
+ */
257
+ rawPrompt: unknown;
258
+ /**
259
+ * Raw settings that are used for the API call. Includes provider-specific
260
+ * settings.
261
+ */
262
+ rawSettings: Record<string, unknown>;
263
+ };
234
264
  warnings?: LanguageModelV1CallWarning[];
235
265
  }>;
236
266
  /**
@@ -243,6 +273,21 @@ type LanguageModelV1 = {
243
273
  */
244
274
  doStream(options: LanguageModelV1CallOptions): PromiseLike<{
245
275
  stream: ReadableStream<LanguageModelV1StreamPart>;
276
+ /**
277
+ * Raw prompt and setting information for observability provider integration.
278
+ */
279
+ rawCall: {
280
+ /**
281
+ * Raw prompt after expansion and conversion to the format that the
282
+ * provider uses to send the information to their API.
283
+ */
284
+ rawPrompt: unknown;
285
+ /**
286
+ * Raw settings that are used for the API call. Includes provider-specific
287
+ * settings.
288
+ */
289
+ rawSettings: Record<string, unknown>;
290
+ };
246
291
  warnings?: LanguageModelV1CallWarning[];
247
292
  }>;
248
293
  };
@@ -268,83 +313,117 @@ type LanguageModelV1StreamPart = {
268
313
  error: unknown;
269
314
  };
270
315
 
271
- type Config$1<SETTINGS extends {
272
- id: string;
273
- }> = {
316
+ type OpenAIChatModelId = 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-4-vision-preview' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | (string & {});
317
+ interface OpenAIChatSettings {
318
+ /**
319
+ * Modify the likelihood of specified tokens appearing in the completion.
320
+ *
321
+ * Accepts a JSON object that maps tokens (specified by their token ID in
322
+ * the GPT tokenizer) to an associated bias value from -100 to 100. You
323
+ * can use this tokenizer tool to convert text to token IDs. Mathematically,
324
+ * the bias is added to the logits generated by the model prior to sampling.
325
+ * The exact effect will vary per model, but values between -1 and 1 should
326
+ * decrease or increase likelihood of selection; values like -100 or 100
327
+ * should result in a ban or exclusive selection of the relevant token.
328
+ *
329
+ * As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
330
+ * token from being generated.
331
+ */
332
+ logitBias?: Record<number, number>;
333
+ /**
334
+ * A unique identifier representing your end-user, which can help OpenAI to
335
+ * monitor and detect abuse. Learn more.
336
+ */
337
+ user?: string;
338
+ }
339
+
340
+ type OpenAIChatConfig = {
274
341
  provider: string;
275
342
  baseUrl: string;
276
- apiKey: () => string;
277
- mapSettings: (settings: SETTINGS) => Record<string, unknown> & {
278
- model: string;
279
- };
343
+ headers: () => Record<string, string | undefined>;
280
344
  };
281
- declare class OpenAIChatLanguageModel<SETTINGS extends {
282
- id: string;
283
- }> implements LanguageModelV1 {
345
+ declare class OpenAIChatLanguageModel implements LanguageModelV1 {
284
346
  readonly specificationVersion = "v1";
285
347
  readonly defaultObjectGenerationMode = "tool";
286
- readonly settings: SETTINGS;
348
+ readonly modelId: OpenAIChatModelId;
349
+ readonly settings: OpenAIChatSettings;
287
350
  private readonly config;
288
- constructor(settings: SETTINGS, config: Config$1<SETTINGS>);
351
+ constructor(modelId: OpenAIChatModelId, settings: OpenAIChatSettings, config: OpenAIChatConfig);
289
352
  get provider(): string;
290
- get modelId(): string;
291
353
  private getArgs;
292
354
  doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
293
355
  doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
294
356
  }
295
357
 
296
- type OpenAIChatModelId = 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-4-vision-preview' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | (string & {});
297
- interface OpenAIChatSettings {
358
+ type OpenAICompletionModelId = 'gpt-3.5-turbo-instruct' | (string & {});
359
+ interface OpenAICompletionSettings {
298
360
  /**
299
- * The ID of the model to use.
361
+ * Echo back the prompt in addition to the completion
362
+ */
363
+ echo?: boolean;
364
+ /**
365
+ * Modify the likelihood of specified tokens appearing in the completion.
366
+ *
367
+ * Accepts a JSON object that maps tokens (specified by their token ID in
368
+ * the GPT tokenizer) to an associated bias value from -100 to 100. You
369
+ * can use this tokenizer tool to convert text to token IDs. Mathematically,
370
+ * the bias is added to the logits generated by the model prior to sampling.
371
+ * The exact effect will vary per model, but values between -1 and 1 should
372
+ * decrease or increase likelihood of selection; values like -100 or 100
373
+ * should result in a ban or exclusive selection of the relevant token.
374
+ *
375
+ * As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
376
+ * token from being generated.
300
377
  */
301
- id: OpenAIChatModelId;
302
378
  logitBias?: Record<number, number>;
379
+ /**
380
+ * The suffix that comes after a completion of inserted text.
381
+ */
382
+ suffix?: string;
383
+ /**
384
+ * A unique identifier representing your end-user, which can help OpenAI to
385
+ * monitor and detect abuse. Learn more.
386
+ */
387
+ user?: string;
303
388
  }
304
389
 
305
- type Config<SETTINGS extends {
306
- id: string;
307
- }> = {
390
+ type OpenAICompletionConfig = {
308
391
  provider: string;
309
392
  baseUrl: string;
310
- apiKey: () => string;
311
- mapSettings: (settings: SETTINGS) => Record<string, unknown> & {
312
- model: string;
313
- };
393
+ headers: () => Record<string, string | undefined>;
314
394
  };
315
- declare class OpenAICompletionLanguageModel<SETTINGS extends {
316
- id: string;
317
- }> implements LanguageModelV1 {
395
+ declare class OpenAICompletionLanguageModel implements LanguageModelV1 {
318
396
  readonly specificationVersion = "v1";
319
397
  readonly defaultObjectGenerationMode: undefined;
320
- readonly settings: SETTINGS;
398
+ readonly modelId: OpenAICompletionModelId;
399
+ readonly settings: OpenAICompletionSettings;
321
400
  private readonly config;
322
- constructor(settings: SETTINGS, config: Config<SETTINGS>);
401
+ constructor(modelId: OpenAICompletionModelId, settings: OpenAICompletionSettings, config: OpenAICompletionConfig);
323
402
  get provider(): string;
324
- get modelId(): string;
325
403
  private getArgs;
326
404
  doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
327
405
  doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
328
406
  }
329
407
 
330
- type OpenAICompletionModelId = 'gpt-3.5-turbo-instruct' | (string & {});
331
- interface OpenAICompletionSettings {
332
- /**
333
- * The ID of the model to use.
334
- */
335
- id: OpenAICompletionModelId;
336
- logitBias?: Record<number, number>;
337
- }
338
-
408
+ /**
409
+ * OpenAI provider.
410
+ */
339
411
  declare class OpenAI {
340
412
  readonly baseUrl?: string;
341
413
  readonly apiKey?: string;
342
- constructor({ baseUrl, apiKey }?: {
414
+ readonly organization?: string;
415
+ constructor(options?: {
343
416
  baseUrl?: string;
344
417
  apiKey?: string;
418
+ organization?: string;
345
419
  });
346
- chat(settings: OpenAIChatSettings): OpenAIChatLanguageModel<OpenAIChatSettings>;
347
- completion(settings: OpenAICompletionSettings): OpenAICompletionLanguageModel<OpenAICompletionSettings>;
420
+ private get baseConfig();
421
+ chat(modelId: OpenAIChatModelId, settings?: OpenAIChatSettings): OpenAIChatLanguageModel;
422
+ completion(modelId: OpenAICompletionModelId, settings?: OpenAICompletionSettings): OpenAICompletionLanguageModel;
348
423
  }
424
+ /**
425
+ * Default OpenAI provider instance.
426
+ */
427
+ declare const openai: OpenAI;
349
428
 
350
- export { OpenAI };
429
+ export { OpenAI, openai };
@@ -48,6 +48,10 @@ type LanguageModelV1CallSettings = {
48
48
  * by the model, calls will generate deterministic results.
49
49
  */
50
50
  seed?: number;
51
+ /**
52
+ * Abort signal for cancelling the operation.
53
+ */
54
+ abortSignal?: AbortSignal;
51
55
  };
52
56
 
53
57
  /**
@@ -103,9 +107,9 @@ interface LanguageModelV1TextPart {
103
107
  interface LanguageModelV1ImagePart {
104
108
  type: 'image';
105
109
  /**
106
- * Image data as a Uint8Array.
110
+ * Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
107
111
  */
108
- image: Uint8Array;
112
+ image: Uint8Array | URL;
109
113
  /**
110
114
  * Optional mime type of the image.
111
115
  */
@@ -231,6 +235,32 @@ type LanguageModelV1 = {
231
235
  * model has only generated text.
232
236
  */
233
237
  toolCalls?: Array<LanguageModelV1FunctionToolCall>;
238
+ /**
239
+ * Finish reason.
240
+ */
241
+ finishReason: LanguageModelV1FinishReason;
242
+ /**
243
+ * Usage information.
244
+ */
245
+ usage: {
246
+ promptTokens: number;
247
+ completionTokens: number;
248
+ };
249
+ /**
250
+ * Raw prompt and setting information for observability provider integration.
251
+ */
252
+ rawCall: {
253
+ /**
254
+ * Raw prompt after expansion and conversion to the format that the
255
+ * provider uses to send the information to their API.
256
+ */
257
+ rawPrompt: unknown;
258
+ /**
259
+ * Raw settings that are used for the API call. Includes provider-specific
260
+ * settings.
261
+ */
262
+ rawSettings: Record<string, unknown>;
263
+ };
234
264
  warnings?: LanguageModelV1CallWarning[];
235
265
  }>;
236
266
  /**
@@ -243,6 +273,21 @@ type LanguageModelV1 = {
243
273
  */
244
274
  doStream(options: LanguageModelV1CallOptions): PromiseLike<{
245
275
  stream: ReadableStream<LanguageModelV1StreamPart>;
276
+ /**
277
+ * Raw prompt and setting information for observability provider integration.
278
+ */
279
+ rawCall: {
280
+ /**
281
+ * Raw prompt after expansion and conversion to the format that the
282
+ * provider uses to send the information to their API.
283
+ */
284
+ rawPrompt: unknown;
285
+ /**
286
+ * Raw settings that are used for the API call. Includes provider-specific
287
+ * settings.
288
+ */
289
+ rawSettings: Record<string, unknown>;
290
+ };
246
291
  warnings?: LanguageModelV1CallWarning[];
247
292
  }>;
248
293
  };
@@ -268,83 +313,117 @@ type LanguageModelV1StreamPart = {
268
313
  error: unknown;
269
314
  };
270
315
 
271
- type Config$1<SETTINGS extends {
272
- id: string;
273
- }> = {
316
+ type OpenAIChatModelId = 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-4-vision-preview' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | (string & {});
317
+ interface OpenAIChatSettings {
318
+ /**
319
+ * Modify the likelihood of specified tokens appearing in the completion.
320
+ *
321
+ * Accepts a JSON object that maps tokens (specified by their token ID in
322
+ * the GPT tokenizer) to an associated bias value from -100 to 100. You
323
+ * can use this tokenizer tool to convert text to token IDs. Mathematically,
324
+ * the bias is added to the logits generated by the model prior to sampling.
325
+ * The exact effect will vary per model, but values between -1 and 1 should
326
+ * decrease or increase likelihood of selection; values like -100 or 100
327
+ * should result in a ban or exclusive selection of the relevant token.
328
+ *
329
+ * As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
330
+ * token from being generated.
331
+ */
332
+ logitBias?: Record<number, number>;
333
+ /**
334
+ * A unique identifier representing your end-user, which can help OpenAI to
335
+ * monitor and detect abuse. Learn more.
336
+ */
337
+ user?: string;
338
+ }
339
+
340
+ type OpenAIChatConfig = {
274
341
  provider: string;
275
342
  baseUrl: string;
276
- apiKey: () => string;
277
- mapSettings: (settings: SETTINGS) => Record<string, unknown> & {
278
- model: string;
279
- };
343
+ headers: () => Record<string, string | undefined>;
280
344
  };
281
- declare class OpenAIChatLanguageModel<SETTINGS extends {
282
- id: string;
283
- }> implements LanguageModelV1 {
345
+ declare class OpenAIChatLanguageModel implements LanguageModelV1 {
284
346
  readonly specificationVersion = "v1";
285
347
  readonly defaultObjectGenerationMode = "tool";
286
- readonly settings: SETTINGS;
348
+ readonly modelId: OpenAIChatModelId;
349
+ readonly settings: OpenAIChatSettings;
287
350
  private readonly config;
288
- constructor(settings: SETTINGS, config: Config$1<SETTINGS>);
351
+ constructor(modelId: OpenAIChatModelId, settings: OpenAIChatSettings, config: OpenAIChatConfig);
289
352
  get provider(): string;
290
- get modelId(): string;
291
353
  private getArgs;
292
354
  doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
293
355
  doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
294
356
  }
295
357
 
296
- type OpenAIChatModelId = 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-4-vision-preview' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | (string & {});
297
- interface OpenAIChatSettings {
358
+ type OpenAICompletionModelId = 'gpt-3.5-turbo-instruct' | (string & {});
359
+ interface OpenAICompletionSettings {
298
360
  /**
299
- * The ID of the model to use.
361
+ * Echo back the prompt in addition to the completion
362
+ */
363
+ echo?: boolean;
364
+ /**
365
+ * Modify the likelihood of specified tokens appearing in the completion.
366
+ *
367
+ * Accepts a JSON object that maps tokens (specified by their token ID in
368
+ * the GPT tokenizer) to an associated bias value from -100 to 100. You
369
+ * can use this tokenizer tool to convert text to token IDs. Mathematically,
370
+ * the bias is added to the logits generated by the model prior to sampling.
371
+ * The exact effect will vary per model, but values between -1 and 1 should
372
+ * decrease or increase likelihood of selection; values like -100 or 100
373
+ * should result in a ban or exclusive selection of the relevant token.
374
+ *
375
+ * As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
376
+ * token from being generated.
300
377
  */
301
- id: OpenAIChatModelId;
302
378
  logitBias?: Record<number, number>;
379
+ /**
380
+ * The suffix that comes after a completion of inserted text.
381
+ */
382
+ suffix?: string;
383
+ /**
384
+ * A unique identifier representing your end-user, which can help OpenAI to
385
+ * monitor and detect abuse. Learn more.
386
+ */
387
+ user?: string;
303
388
  }
304
389
 
305
- type Config<SETTINGS extends {
306
- id: string;
307
- }> = {
390
+ type OpenAICompletionConfig = {
308
391
  provider: string;
309
392
  baseUrl: string;
310
- apiKey: () => string;
311
- mapSettings: (settings: SETTINGS) => Record<string, unknown> & {
312
- model: string;
313
- };
393
+ headers: () => Record<string, string | undefined>;
314
394
  };
315
- declare class OpenAICompletionLanguageModel<SETTINGS extends {
316
- id: string;
317
- }> implements LanguageModelV1 {
395
+ declare class OpenAICompletionLanguageModel implements LanguageModelV1 {
318
396
  readonly specificationVersion = "v1";
319
397
  readonly defaultObjectGenerationMode: undefined;
320
- readonly settings: SETTINGS;
398
+ readonly modelId: OpenAICompletionModelId;
399
+ readonly settings: OpenAICompletionSettings;
321
400
  private readonly config;
322
- constructor(settings: SETTINGS, config: Config<SETTINGS>);
401
+ constructor(modelId: OpenAICompletionModelId, settings: OpenAICompletionSettings, config: OpenAICompletionConfig);
323
402
  get provider(): string;
324
- get modelId(): string;
325
403
  private getArgs;
326
404
  doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
327
405
  doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
328
406
  }
329
407
 
330
- type OpenAICompletionModelId = 'gpt-3.5-turbo-instruct' | (string & {});
331
- interface OpenAICompletionSettings {
332
- /**
333
- * The ID of the model to use.
334
- */
335
- id: OpenAICompletionModelId;
336
- logitBias?: Record<number, number>;
337
- }
338
-
408
+ /**
409
+ * OpenAI provider.
410
+ */
339
411
  declare class OpenAI {
340
412
  readonly baseUrl?: string;
341
413
  readonly apiKey?: string;
342
- constructor({ baseUrl, apiKey }?: {
414
+ readonly organization?: string;
415
+ constructor(options?: {
343
416
  baseUrl?: string;
344
417
  apiKey?: string;
418
+ organization?: string;
345
419
  });
346
- chat(settings: OpenAIChatSettings): OpenAIChatLanguageModel<OpenAIChatSettings>;
347
- completion(settings: OpenAICompletionSettings): OpenAICompletionLanguageModel<OpenAICompletionSettings>;
420
+ private get baseConfig();
421
+ chat(modelId: OpenAIChatModelId, settings?: OpenAIChatSettings): OpenAIChatLanguageModel;
422
+ completion(modelId: OpenAICompletionModelId, settings?: OpenAICompletionSettings): OpenAICompletionLanguageModel;
348
423
  }
424
+ /**
425
+ * Default OpenAI provider instance.
426
+ */
427
+ declare const openai: OpenAI;
349
428
 
350
- export { OpenAI };
429
+ export { OpenAI, openai };