@effect/ai-openai-compat 4.0.0-beta.9 → 4.0.0-beta.91
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/OpenAiClient.d.ts +264 -52
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +97 -9
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiConfig.d.ts +68 -10
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiConfig.js +36 -7
- package/dist/OpenAiConfig.js.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +186 -0
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
- package/dist/OpenAiEmbeddingModel.js +190 -0
- package/dist/OpenAiEmbeddingModel.js.map +1 -0
- package/dist/OpenAiError.d.ts +109 -35
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiError.js +14 -1
- package/dist/OpenAiLanguageModel.d.ts +304 -20
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +157 -27
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiTelemetry.d.ts +76 -26
- package/dist/OpenAiTelemetry.d.ts.map +1 -1
- package/dist/OpenAiTelemetry.js +22 -10
- package/dist/OpenAiTelemetry.js.map +1 -1
- package/dist/index.d.ts +10 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -17
- package/dist/index.js.map +1 -1
- package/dist/internal/errors.js +4 -4
- package/dist/internal/errors.js.map +1 -1
- package/dist/internal/utilities.js +0 -6
- package/dist/internal/utilities.js.map +1 -1
- package/package.json +3 -3
- package/src/OpenAiClient.ts +273 -50
- package/src/OpenAiConfig.ts +69 -11
- package/src/OpenAiEmbeddingModel.ts +332 -0
- package/src/OpenAiError.ts +111 -35
- package/src/OpenAiLanguageModel.ts +426 -43
- package/src/OpenAiTelemetry.ts +81 -32
- package/src/index.ts +11 -17
- package/src/internal/errors.ts +4 -4
- package/src/internal/utilities.ts +0 -9
package/dist/OpenAiClient.d.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import type * as Config from "effect/Config";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
3
4
|
import * as Layer from "effect/Layer";
|
|
4
5
|
import * as Redacted from "effect/Redacted";
|
|
5
6
|
import * as Schema from "effect/Schema";
|
|
6
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
7
7
|
import * as Stream from "effect/Stream";
|
|
8
8
|
import type * as AiError from "effect/unstable/ai/AiError";
|
|
9
9
|
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
10
10
|
import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Effect service interface for OpenAI-compatible chat completions and embeddings.
|
|
13
|
+
*
|
|
14
|
+
* **Details**
|
|
15
|
+
*
|
|
16
|
+
* Exposes the configured HTTP client plus helpers for non-streaming chat
|
|
17
|
+
* completions, streaming chat completions, and embeddings. Transport and
|
|
18
|
+
* schema decoding failures are mapped to `AiError`.
|
|
19
|
+
*
|
|
13
20
|
* @category models
|
|
21
|
+
* @since 4.0.0
|
|
14
22
|
*/
|
|
15
23
|
export interface Service {
|
|
16
24
|
readonly client: HttpClient.HttpClient;
|
|
@@ -24,16 +32,35 @@ export interface Service {
|
|
|
24
32
|
], AiError.AiError>;
|
|
25
33
|
readonly createEmbedding: (options: CreateEmbeddingRequestJson) => Effect.Effect<CreateEmbedding200, AiError.AiError>;
|
|
26
34
|
}
|
|
27
|
-
declare const OpenAiClient_base:
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
35
|
+
declare const OpenAiClient_base: Context.ServiceClass<OpenAiClient, "@effect/ai-openai-compat/OpenAiClient", Service>;
|
|
36
|
+
/**
|
|
37
|
+
* Service tag for the OpenAI-compatible chat completions and embeddings client.
|
|
38
|
+
*
|
|
39
|
+
* **When to use**
|
|
40
|
+
*
|
|
41
|
+
* Use when building effects that depend on the low-level OpenAI-compatible
|
|
42
|
+
* client through context rather than receiving the client as a value.
|
|
43
|
+
*
|
|
44
|
+
* **Details**
|
|
45
|
+
*
|
|
46
|
+
* The tagged service is the `Service` interface produced by `make` and provided
|
|
47
|
+
* by `layer` or `layerConfig`.
|
|
48
|
+
*
|
|
49
|
+
* @see {@link Service} for the operations provided by the service
|
|
50
|
+
* @see {@link make} for constructing the service from explicit options
|
|
51
|
+
* @see {@link layer} for providing the service from explicit options
|
|
52
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
53
|
+
*
|
|
54
|
+
* @category services
|
|
55
|
+
* @since 4.0.0
|
|
31
56
|
*/
|
|
32
57
|
export declare class OpenAiClient extends OpenAiClient_base {
|
|
33
58
|
}
|
|
34
59
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
60
|
+
* Configuration options used to construct an OpenAI-compatible client.
|
|
61
|
+
*
|
|
62
|
+
* @category options
|
|
63
|
+
* @since 4.0.0
|
|
37
64
|
*/
|
|
38
65
|
export type Options = {
|
|
39
66
|
readonly apiKey?: Redacted.Redacted<string> | undefined;
|
|
@@ -43,35 +70,89 @@ export type Options = {
|
|
|
43
70
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
44
71
|
};
|
|
45
72
|
/**
|
|
46
|
-
*
|
|
73
|
+
* Constructs an OpenAI-compatible client service from explicit options.
|
|
74
|
+
*
|
|
75
|
+
* **When to use**
|
|
76
|
+
*
|
|
77
|
+
* Use when you need the OpenAI-compatible client service value inside an effect.
|
|
78
|
+
*
|
|
79
|
+
* **Details**
|
|
80
|
+
*
|
|
81
|
+
* The returned service uses the current `HttpClient`, prepends `apiUrl` or
|
|
82
|
+
* `https://api.openai.com/v1`, adds authentication and OpenAI
|
|
83
|
+
* organization/project headers, accepts JSON responses, and applies
|
|
84
|
+
* `transformClient` when provided.
|
|
85
|
+
*
|
|
86
|
+
* **Gotchas**
|
|
87
|
+
*
|
|
88
|
+
* A scoped `OpenAiConfig.withClientTransform` is applied when request helpers
|
|
89
|
+
* run, after the `transformClient` option supplied to `make`.
|
|
90
|
+
*
|
|
91
|
+
* @see {@link layer} for providing this client from explicit options
|
|
92
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
93
|
+
*
|
|
47
94
|
* @category constructors
|
|
95
|
+
* @since 4.0.0
|
|
48
96
|
*/
|
|
49
97
|
export declare const make: (options: Options) => Effect.Effect<Service, never, HttpClient.HttpClient>;
|
|
50
98
|
/**
|
|
51
|
-
*
|
|
99
|
+
* Creates a layer that provides an OpenAI-compatible client from explicit options.
|
|
100
|
+
*
|
|
101
|
+
* **When to use**
|
|
102
|
+
*
|
|
103
|
+
* Use to install `OpenAiClient` in an application layer when the client options
|
|
104
|
+
* are already available as values rather than loaded from `Config`.
|
|
105
|
+
*
|
|
106
|
+
* @see {@link make} for constructing the client service effectfully
|
|
107
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
108
|
+
*
|
|
52
109
|
* @category layers
|
|
110
|
+
* @since 4.0.0
|
|
53
111
|
*/
|
|
54
112
|
export declare const layer: (options: Options) => Layer.Layer<OpenAiClient, never, HttpClient.HttpClient>;
|
|
55
113
|
/**
|
|
56
|
-
*
|
|
114
|
+
* Creates a layer that loads OpenAI-compatible client settings from `Config`
|
|
115
|
+
* values before constructing the service.
|
|
116
|
+
*
|
|
117
|
+
* **When to use**
|
|
118
|
+
*
|
|
119
|
+
* Use when you need client settings for OpenAI-compatible APIs to be read from
|
|
120
|
+
* Effect `Config` values while providing `OpenAiClient` as a layer.
|
|
121
|
+
*
|
|
122
|
+
* **Details**
|
|
123
|
+
*
|
|
124
|
+
* Only config values supplied in `options` are loaded. Omitted fields are
|
|
125
|
+
* passed to `make` as `undefined`, and `transformClient` is forwarded as a
|
|
126
|
+
* plain option.
|
|
127
|
+
*
|
|
128
|
+
* @see {@link make} for constructing the client service effectfully
|
|
129
|
+
* @see {@link layer} for providing the client from already-resolved options
|
|
130
|
+
*
|
|
57
131
|
* @category layers
|
|
132
|
+
* @since 4.0.0
|
|
58
133
|
*/
|
|
59
134
|
export declare const layerConfig: (options?: {
|
|
60
|
-
readonly apiKey?: Config.Config<Redacted.Redacted<string
|
|
135
|
+
readonly apiKey?: Config.Config<Redacted.Redacted<string> | undefined> | undefined;
|
|
61
136
|
readonly apiUrl?: Config.Config<string> | undefined;
|
|
62
|
-
readonly organizationId?: Config.Config<Redacted.Redacted<string
|
|
63
|
-
readonly projectId?: Config.Config<Redacted.Redacted<string
|
|
137
|
+
readonly organizationId?: Config.Config<Redacted.Redacted<string> | undefined> | undefined;
|
|
138
|
+
readonly projectId?: Config.Config<Redacted.Redacted<string> | undefined> | undefined;
|
|
64
139
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
65
140
|
}) => Layer.Layer<OpenAiClient, Config.ConfigError, HttpClient.HttpClient>;
|
|
66
141
|
type JsonObject = {
|
|
67
142
|
readonly [x: string]: Schema.Json;
|
|
68
143
|
};
|
|
69
144
|
/**
|
|
70
|
-
*
|
|
145
|
+
* Optional response fields that can be requested with the `include` parameter.
|
|
146
|
+
*
|
|
147
|
+
* @category response
|
|
148
|
+
* @since 4.0.0
|
|
71
149
|
*/
|
|
72
150
|
export type IncludeEnum = "message.input_image.image_url" | "reasoning.encrypted_content" | "message.output_text.logprobs";
|
|
73
151
|
/**
|
|
74
|
-
*
|
|
152
|
+
* Lifecycle status shared by message, reasoning, and tool-call items.
|
|
153
|
+
*
|
|
154
|
+
* @category models
|
|
155
|
+
* @since 4.0.0
|
|
75
156
|
*/
|
|
76
157
|
export type MessageStatus = "in_progress" | "completed" | "incomplete";
|
|
77
158
|
type InputTextContent = {
|
|
@@ -92,11 +173,17 @@ type InputFileContent = {
|
|
|
92
173
|
readonly file_data?: string | undefined;
|
|
93
174
|
};
|
|
94
175
|
/**
|
|
95
|
-
*
|
|
176
|
+
* Content blocks accepted in input messages.
|
|
177
|
+
*
|
|
178
|
+
* @category request
|
|
179
|
+
* @since 4.0.0
|
|
96
180
|
*/
|
|
97
181
|
export type InputContent = InputTextContent | InputImageContent | InputFileContent;
|
|
98
182
|
/**
|
|
99
|
-
*
|
|
183
|
+
* Text content block used for model-provided reasoning summaries.
|
|
184
|
+
*
|
|
185
|
+
* @category response
|
|
186
|
+
* @since 4.0.0
|
|
100
187
|
*/
|
|
101
188
|
export type SummaryTextContent = {
|
|
102
189
|
readonly type: "summary_text";
|
|
@@ -146,7 +233,10 @@ type FilePathAnnotation = {
|
|
|
146
233
|
readonly index: number;
|
|
147
234
|
};
|
|
148
235
|
/**
|
|
149
|
-
*
|
|
236
|
+
* Citation and file-path annotations attached to output text content.
|
|
237
|
+
*
|
|
238
|
+
* @category response
|
|
239
|
+
* @since 4.0.0
|
|
150
240
|
*/
|
|
151
241
|
export type Annotation = FileCitationAnnotation | UrlCitationAnnotation | ContainerFileCitationAnnotation | FilePathAnnotation;
|
|
152
242
|
type OutputTextContent = {
|
|
@@ -164,7 +254,11 @@ type OutputMessage = {
|
|
|
164
254
|
readonly status: MessageStatus;
|
|
165
255
|
};
|
|
166
256
|
/**
|
|
167
|
-
*
|
|
257
|
+
* Reasoning output item containing encrypted reasoning content, summaries, and
|
|
258
|
+
* optional reasoning text.
|
|
259
|
+
*
|
|
260
|
+
* @category response
|
|
261
|
+
* @since 4.0.0
|
|
168
262
|
*/
|
|
169
263
|
export type ReasoningItem = {
|
|
170
264
|
readonly type: "reasoning";
|
|
@@ -207,7 +301,15 @@ type ItemReference = {
|
|
|
207
301
|
readonly id: string;
|
|
208
302
|
};
|
|
209
303
|
/**
|
|
210
|
-
*
|
|
304
|
+
* Item shapes accepted by a Responses-style `input` field.
|
|
305
|
+
*
|
|
306
|
+
* **Details**
|
|
307
|
+
*
|
|
308
|
+
* Supports input messages, output messages, tool calls, tool outputs, reasoning
|
|
309
|
+
* items, custom tool interactions, and item references.
|
|
310
|
+
*
|
|
311
|
+
* @category request
|
|
312
|
+
* @since 4.0.0
|
|
211
313
|
*/
|
|
212
314
|
export type InputItem = {
|
|
213
315
|
readonly role: "user" | "assistant" | "system" | "developer";
|
|
@@ -233,7 +335,10 @@ type CustomToolParam = {
|
|
|
233
335
|
readonly format?: unknown;
|
|
234
336
|
};
|
|
235
337
|
/**
|
|
236
|
-
*
|
|
338
|
+
* Tool definitions that can be supplied to a Responses-style request.
|
|
339
|
+
*
|
|
340
|
+
* @category request
|
|
341
|
+
* @since 4.0.0
|
|
237
342
|
*/
|
|
238
343
|
export type Tool = FunctionTool | CustomToolParam;
|
|
239
344
|
type ToolChoice = "none" | "auto" | "required" | {
|
|
@@ -248,7 +353,11 @@ type ToolChoice = "none" | "auto" | "required" | {
|
|
|
248
353
|
readonly name: string;
|
|
249
354
|
};
|
|
250
355
|
/**
|
|
251
|
-
*
|
|
356
|
+
* Text output format configuration for plain text, JSON object, or JSON Schema
|
|
357
|
+
* responses.
|
|
358
|
+
*
|
|
359
|
+
* @category configuration
|
|
360
|
+
* @since 4.0.0
|
|
252
361
|
*/
|
|
253
362
|
export type TextResponseFormatConfiguration = {
|
|
254
363
|
readonly type: "text";
|
|
@@ -262,7 +371,11 @@ export type TextResponseFormatConfiguration = {
|
|
|
262
371
|
readonly type: "json_object";
|
|
263
372
|
};
|
|
264
373
|
/**
|
|
265
|
-
*
|
|
374
|
+
* Request options for creating a Responses-style response with an
|
|
375
|
+
* OpenAI-compatible provider.
|
|
376
|
+
*
|
|
377
|
+
* @category request
|
|
378
|
+
* @since 4.0.0
|
|
266
379
|
*/
|
|
267
380
|
export type CreateResponse = {
|
|
268
381
|
readonly metadata?: Readonly<Record<string, string>> | null | undefined;
|
|
@@ -298,7 +411,10 @@ export type CreateResponse = {
|
|
|
298
411
|
readonly seed?: number | undefined;
|
|
299
412
|
};
|
|
300
413
|
/**
|
|
301
|
-
*
|
|
414
|
+
* Token accounting reported on Responses-style response objects.
|
|
415
|
+
*
|
|
416
|
+
* @category response
|
|
417
|
+
* @since 4.0.0
|
|
302
418
|
*/
|
|
303
419
|
export type ResponseUsage = {
|
|
304
420
|
readonly input_tokens: number;
|
|
@@ -309,7 +425,11 @@ export type ResponseUsage = {
|
|
|
309
425
|
};
|
|
310
426
|
type OutputItem = OutputMessage | FunctionCall | ReasoningItem | CustomToolCall;
|
|
311
427
|
/**
|
|
312
|
-
*
|
|
428
|
+
* Responses-style response object returned by compatible providers or embedded
|
|
429
|
+
* in response stream lifecycle events.
|
|
430
|
+
*
|
|
431
|
+
* @category response
|
|
432
|
+
* @since 4.0.0
|
|
313
433
|
*/
|
|
314
434
|
export type Response = {
|
|
315
435
|
readonly id: string;
|
|
@@ -417,11 +537,23 @@ type UnknownResponseStreamEvent = {
|
|
|
417
537
|
readonly [key: string]: unknown;
|
|
418
538
|
};
|
|
419
539
|
/**
|
|
420
|
-
*
|
|
540
|
+
* Server-sent event shapes emitted by Responses-style response streams.
|
|
541
|
+
*
|
|
542
|
+
* @category streaming
|
|
543
|
+
* @since 4.0.0
|
|
421
544
|
*/
|
|
422
545
|
export type ResponseStreamEvent = ResponseCreatedEvent | ResponseCompletedEvent | ResponseIncompleteEvent | ResponseFailedEvent | ResponseOutputItemAddedEvent | ResponseOutputItemDoneEvent | ResponseTextDeltaEvent | ResponseOutputTextAnnotationAddedEvent | ResponseFunctionCallArgumentsDeltaEvent | ResponseReasoningSummaryPartAddedEvent | ResponseReasoningSummaryPartDoneEvent | ResponseReasoningSummaryTextDeltaEvent | ResponseErrorEvent | UnknownResponseStreamEvent;
|
|
423
546
|
/**
|
|
424
|
-
*
|
|
547
|
+
* Represents one embedding item returned by an OpenAI-compatible embeddings API.
|
|
548
|
+
*
|
|
549
|
+
* **Details**
|
|
550
|
+
*
|
|
551
|
+
* The embedding can be returned either as a numeric vector or as a base64-encoded
|
|
552
|
+
* string. The `index` field identifies the input item that produced this
|
|
553
|
+
* embedding.
|
|
554
|
+
*
|
|
555
|
+
* @category response
|
|
556
|
+
* @since 4.0.0
|
|
425
557
|
*/
|
|
426
558
|
export type Embedding = {
|
|
427
559
|
readonly embedding: ReadonlyArray<number> | string;
|
|
@@ -429,7 +561,10 @@ export type Embedding = {
|
|
|
429
561
|
readonly object?: string | undefined;
|
|
430
562
|
};
|
|
431
563
|
/**
|
|
432
|
-
*
|
|
564
|
+
* Request payload for the embeddings endpoint.
|
|
565
|
+
*
|
|
566
|
+
* @category request
|
|
567
|
+
* @since 4.0.0
|
|
433
568
|
*/
|
|
434
569
|
export type CreateEmbeddingRequest = {
|
|
435
570
|
readonly input: string | ReadonlyArray<string> | ReadonlyArray<number> | ReadonlyArray<ReadonlyArray<number>>;
|
|
@@ -439,7 +574,10 @@ export type CreateEmbeddingRequest = {
|
|
|
439
574
|
readonly user?: string | undefined;
|
|
440
575
|
};
|
|
441
576
|
/**
|
|
442
|
-
*
|
|
577
|
+
* Successful response payload returned by the embeddings endpoint.
|
|
578
|
+
*
|
|
579
|
+
* @category response
|
|
580
|
+
* @since 4.0.0
|
|
443
581
|
*/
|
|
444
582
|
export type CreateEmbeddingResponse = {
|
|
445
583
|
readonly data: ReadonlyArray<Embedding>;
|
|
@@ -451,15 +589,24 @@ export type CreateEmbeddingResponse = {
|
|
|
451
589
|
} | undefined;
|
|
452
590
|
};
|
|
453
591
|
/**
|
|
454
|
-
*
|
|
592
|
+
* JSON request body accepted by the embeddings endpoint.
|
|
593
|
+
*
|
|
594
|
+
* @category request
|
|
595
|
+
* @since 4.0.0
|
|
455
596
|
*/
|
|
456
597
|
export type CreateEmbeddingRequestJson = CreateEmbeddingRequest;
|
|
457
598
|
/**
|
|
458
|
-
*
|
|
599
|
+
* Decoded successful embeddings response body.
|
|
600
|
+
*
|
|
601
|
+
* @category response
|
|
602
|
+
* @since 4.0.0
|
|
459
603
|
*/
|
|
460
604
|
export type CreateEmbedding200 = CreateEmbeddingResponse;
|
|
461
605
|
/**
|
|
462
|
-
*
|
|
606
|
+
* Structured content parts accepted in chat completion messages.
|
|
607
|
+
*
|
|
608
|
+
* @category request
|
|
609
|
+
* @since 4.0.0
|
|
463
610
|
*/
|
|
464
611
|
export type ChatCompletionContentPart = {
|
|
465
612
|
readonly type: "text";
|
|
@@ -472,7 +619,10 @@ export type ChatCompletionContentPart = {
|
|
|
472
619
|
};
|
|
473
620
|
};
|
|
474
621
|
/**
|
|
475
|
-
*
|
|
622
|
+
* Tool call data attached to an assistant chat completion message.
|
|
623
|
+
*
|
|
624
|
+
* @category request
|
|
625
|
+
* @since 4.0.0
|
|
476
626
|
*/
|
|
477
627
|
export type ChatCompletionRequestToolCall = {
|
|
478
628
|
readonly id: string;
|
|
@@ -483,7 +633,10 @@ export type ChatCompletionRequestToolCall = {
|
|
|
483
633
|
};
|
|
484
634
|
};
|
|
485
635
|
/**
|
|
486
|
-
*
|
|
636
|
+
* Message shapes accepted by the chat completions endpoint.
|
|
637
|
+
*
|
|
638
|
+
* @category request
|
|
639
|
+
* @since 4.0.0
|
|
487
640
|
*/
|
|
488
641
|
export type ChatCompletionRequestMessage = {
|
|
489
642
|
readonly role: "system" | "developer" | "user" | "assistant";
|
|
@@ -495,7 +648,10 @@ export type ChatCompletionRequestMessage = {
|
|
|
495
648
|
readonly content: string;
|
|
496
649
|
};
|
|
497
650
|
/**
|
|
498
|
-
*
|
|
651
|
+
* Function tool definition accepted by the chat completions endpoint.
|
|
652
|
+
*
|
|
653
|
+
* @category request
|
|
654
|
+
* @since 4.0.0
|
|
499
655
|
*/
|
|
500
656
|
export type ChatCompletionTool = {
|
|
501
657
|
readonly type: "function";
|
|
@@ -507,7 +663,10 @@ export type ChatCompletionTool = {
|
|
|
507
663
|
};
|
|
508
664
|
};
|
|
509
665
|
/**
|
|
510
|
-
*
|
|
666
|
+
* Controls whether the model may call tools and can force a specific function.
|
|
667
|
+
*
|
|
668
|
+
* @category configuration
|
|
669
|
+
* @since 4.0.0
|
|
511
670
|
*/
|
|
512
671
|
export type ChatCompletionToolChoice = "none" | "auto" | "required" | {
|
|
513
672
|
readonly type: "function";
|
|
@@ -516,7 +675,10 @@ export type ChatCompletionToolChoice = "none" | "auto" | "required" | {
|
|
|
516
675
|
};
|
|
517
676
|
};
|
|
518
677
|
/**
|
|
519
|
-
*
|
|
678
|
+
* JSON response format configuration for chat completion requests.
|
|
679
|
+
*
|
|
680
|
+
* @category configuration
|
|
681
|
+
* @since 4.0.0
|
|
520
682
|
*/
|
|
521
683
|
export type ChatCompletionResponseFormat = {
|
|
522
684
|
readonly type: "json_object";
|
|
@@ -530,7 +692,10 @@ export type ChatCompletionResponseFormat = {
|
|
|
530
692
|
};
|
|
531
693
|
};
|
|
532
694
|
/**
|
|
533
|
-
*
|
|
695
|
+
* Request payload for the OpenAI-compatible chat completions endpoint.
|
|
696
|
+
*
|
|
697
|
+
* @category request
|
|
698
|
+
* @since 4.0.0
|
|
534
699
|
*/
|
|
535
700
|
export type ChatCompletionRequest = {
|
|
536
701
|
readonly model: string;
|
|
@@ -545,21 +710,32 @@ export type ChatCompletionRequest = {
|
|
|
545
710
|
readonly tools?: ReadonlyArray<ChatCompletionTool> | undefined;
|
|
546
711
|
readonly tool_choice?: ChatCompletionToolChoice | undefined;
|
|
547
712
|
readonly service_tier?: string | undefined;
|
|
713
|
+
readonly reasoning?: unknown;
|
|
548
714
|
readonly stream?: boolean | undefined;
|
|
549
715
|
readonly stream_options?: {
|
|
550
716
|
readonly include_usage?: boolean | undefined;
|
|
551
717
|
} | undefined;
|
|
718
|
+
readonly [x: string]: unknown;
|
|
552
719
|
};
|
|
553
720
|
/**
|
|
554
|
-
*
|
|
721
|
+
* JSON request body used by this client when creating a chat completion response.
|
|
722
|
+
*
|
|
723
|
+
* @category request
|
|
724
|
+
* @since 4.0.0
|
|
555
725
|
*/
|
|
556
726
|
export type CreateResponseRequestJson = ChatCompletionRequest;
|
|
557
727
|
/**
|
|
558
|
-
*
|
|
728
|
+
* Decoded successful chat completion response body returned by `createResponse`.
|
|
729
|
+
*
|
|
730
|
+
* @category response
|
|
731
|
+
* @since 4.0.0
|
|
559
732
|
*/
|
|
560
733
|
export type CreateResponse200 = ChatCompletionResponse;
|
|
561
734
|
/**
|
|
562
|
-
*
|
|
735
|
+
* Decoded server-sent event payload emitted by `createResponseStream`.
|
|
736
|
+
*
|
|
737
|
+
* @category streaming
|
|
738
|
+
* @since 4.0.0
|
|
563
739
|
*/
|
|
564
740
|
export type CreateResponse200Sse = ChatCompletionStreamEvent;
|
|
565
741
|
declare const ChatCompletionToolCall: Schema.Struct<{
|
|
@@ -574,6 +750,8 @@ declare const ChatCompletionToolCall: Schema.Struct<{
|
|
|
574
750
|
declare const ChatCompletionMessage: Schema.Struct<{
|
|
575
751
|
readonly role: Schema.optionalKey<Schema.String>;
|
|
576
752
|
readonly content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
753
|
+
readonly reasoning: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
754
|
+
readonly reasoning_content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
577
755
|
readonly tool_calls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
578
756
|
readonly id: Schema.optionalKey<Schema.String>;
|
|
579
757
|
readonly index: Schema.optionalKey<Schema.Number>;
|
|
@@ -590,6 +768,8 @@ declare const ChatCompletionChoice: Schema.Struct<{
|
|
|
590
768
|
readonly message: Schema.optionalKey<Schema.Struct<{
|
|
591
769
|
readonly role: Schema.optionalKey<Schema.String>;
|
|
592
770
|
readonly content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
771
|
+
readonly reasoning: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
772
|
+
readonly reasoning_content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
593
773
|
readonly tool_calls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
594
774
|
readonly id: Schema.optionalKey<Schema.String>;
|
|
595
775
|
readonly index: Schema.optionalKey<Schema.Number>;
|
|
@@ -603,12 +783,14 @@ declare const ChatCompletionChoice: Schema.Struct<{
|
|
|
603
783
|
readonly delta: Schema.optionalKey<Schema.Struct<{
|
|
604
784
|
readonly role: Schema.optionalKey<Schema.String>;
|
|
605
785
|
readonly content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
786
|
+
readonly reasoning: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
787
|
+
readonly reasoning_content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
606
788
|
readonly tool_calls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
607
789
|
readonly id: Schema.optionalKey<Schema.String>;
|
|
608
790
|
readonly index: Schema.optionalKey<Schema.Number>;
|
|
609
791
|
readonly type: Schema.optionalKey<Schema.String>;
|
|
610
792
|
readonly function: Schema.optionalKey<Schema.Struct<{
|
|
611
|
-
readonly name: Schema.String
|
|
793
|
+
readonly name: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
612
794
|
readonly arguments: Schema.optionalKey<Schema.String>;
|
|
613
795
|
}>>;
|
|
614
796
|
}>>>;
|
|
@@ -631,6 +813,8 @@ declare const ChatCompletionResponse: Schema.Struct<{
|
|
|
631
813
|
readonly message: Schema.optionalKey<Schema.Struct<{
|
|
632
814
|
readonly role: Schema.optionalKey<Schema.String>;
|
|
633
815
|
readonly content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
816
|
+
readonly reasoning: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
817
|
+
readonly reasoning_content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
634
818
|
readonly tool_calls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
635
819
|
readonly id: Schema.optionalKey<Schema.String>;
|
|
636
820
|
readonly index: Schema.optionalKey<Schema.Number>;
|
|
@@ -644,12 +828,14 @@ declare const ChatCompletionResponse: Schema.Struct<{
|
|
|
644
828
|
readonly delta: Schema.optionalKey<Schema.Struct<{
|
|
645
829
|
readonly role: Schema.optionalKey<Schema.String>;
|
|
646
830
|
readonly content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
831
|
+
readonly reasoning: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
832
|
+
readonly reasoning_content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
647
833
|
readonly tool_calls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
648
834
|
readonly id: Schema.optionalKey<Schema.String>;
|
|
649
835
|
readonly index: Schema.optionalKey<Schema.Number>;
|
|
650
836
|
readonly type: Schema.optionalKey<Schema.String>;
|
|
651
837
|
readonly function: Schema.optionalKey<Schema.Struct<{
|
|
652
|
-
readonly name: Schema.String
|
|
838
|
+
readonly name: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
653
839
|
readonly arguments: Schema.optionalKey<Schema.String>;
|
|
654
840
|
}>>;
|
|
655
841
|
}>>>;
|
|
@@ -674,6 +860,8 @@ declare const ChatCompletionChunk: Schema.Struct<{
|
|
|
674
860
|
readonly message: Schema.optionalKey<Schema.Struct<{
|
|
675
861
|
readonly role: Schema.optionalKey<Schema.String>;
|
|
676
862
|
readonly content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
863
|
+
readonly reasoning: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
864
|
+
readonly reasoning_content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
677
865
|
readonly tool_calls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
678
866
|
readonly id: Schema.optionalKey<Schema.String>;
|
|
679
867
|
readonly index: Schema.optionalKey<Schema.Number>;
|
|
@@ -687,12 +875,14 @@ declare const ChatCompletionChunk: Schema.Struct<{
|
|
|
687
875
|
readonly delta: Schema.optionalKey<Schema.Struct<{
|
|
688
876
|
readonly role: Schema.optionalKey<Schema.String>;
|
|
689
877
|
readonly content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
878
|
+
readonly reasoning: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
879
|
+
readonly reasoning_content: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
690
880
|
readonly tool_calls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
691
881
|
readonly id: Schema.optionalKey<Schema.String>;
|
|
692
882
|
readonly index: Schema.optionalKey<Schema.Number>;
|
|
693
883
|
readonly type: Schema.optionalKey<Schema.String>;
|
|
694
884
|
readonly function: Schema.optionalKey<Schema.Struct<{
|
|
695
|
-
readonly name: Schema.String
|
|
885
|
+
readonly name: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
696
886
|
readonly arguments: Schema.optionalKey<Schema.String>;
|
|
697
887
|
}>>;
|
|
698
888
|
}>>>;
|
|
@@ -708,31 +898,53 @@ declare const ChatCompletionChunk: Schema.Struct<{
|
|
|
708
898
|
readonly service_tier: Schema.optionalKey<Schema.String>;
|
|
709
899
|
}>;
|
|
710
900
|
/**
|
|
711
|
-
*
|
|
901
|
+
* Decoded tool-call object from a chat completion response or streaming chunk.
|
|
902
|
+
*
|
|
903
|
+
* @category response
|
|
904
|
+
* @since 4.0.0
|
|
712
905
|
*/
|
|
713
906
|
export type ChatCompletionToolCall = typeof ChatCompletionToolCall.Type;
|
|
714
907
|
/**
|
|
715
|
-
*
|
|
908
|
+
* Decoded message object from a non-streaming chat completion choice.
|
|
909
|
+
*
|
|
910
|
+
* @category response
|
|
911
|
+
* @since 4.0.0
|
|
716
912
|
*/
|
|
717
913
|
export type ChatCompletionMessage = typeof ChatCompletionMessage.Type;
|
|
718
914
|
/**
|
|
719
|
-
*
|
|
915
|
+
* Decoded choice object returned by chat completion responses and chunks.
|
|
916
|
+
*
|
|
917
|
+
* @category response
|
|
918
|
+
* @since 4.0.0
|
|
720
919
|
*/
|
|
721
920
|
export type ChatCompletionChoice = typeof ChatCompletionChoice.Type;
|
|
722
921
|
/**
|
|
723
|
-
*
|
|
922
|
+
* Decoded token usage summary returned by chat completions.
|
|
923
|
+
*
|
|
924
|
+
* @category response
|
|
925
|
+
* @since 4.0.0
|
|
724
926
|
*/
|
|
725
927
|
export type ChatCompletionUsage = typeof ChatCompletionUsage.Type;
|
|
726
928
|
/**
|
|
727
|
-
*
|
|
929
|
+
* Decoded successful response from the chat completions endpoint.
|
|
930
|
+
*
|
|
931
|
+
* @category response
|
|
932
|
+
* @since 4.0.0
|
|
728
933
|
*/
|
|
729
934
|
export type ChatCompletionResponse = typeof ChatCompletionResponse.Type;
|
|
730
935
|
/**
|
|
731
|
-
*
|
|
936
|
+
* Decoded streaming chunk emitted by the chat completions endpoint.
|
|
937
|
+
*
|
|
938
|
+
* @category streaming
|
|
939
|
+
* @since 4.0.0
|
|
732
940
|
*/
|
|
733
941
|
export type ChatCompletionChunk = typeof ChatCompletionChunk.Type;
|
|
734
942
|
/**
|
|
735
|
-
*
|
|
943
|
+
* Streaming chat completion event, including decoded chunks and the `[DONE]`
|
|
944
|
+
* sentinel.
|
|
945
|
+
*
|
|
946
|
+
* @category streaming
|
|
947
|
+
* @since 4.0.0
|
|
736
948
|
*/
|
|
737
949
|
export type ChatCompletionStreamEvent = ChatCompletionChunk | "[DONE]";
|
|
738
950
|
export {};
|