@effect/ai-openai-compat 4.0.0-beta.66 → 4.0.0-beta.67
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 +145 -41
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +41 -5
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiConfig.d.ts +56 -8
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiConfig.js +35 -4
- package/dist/OpenAiConfig.js.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +14 -9
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -1
- package/dist/OpenAiEmbeddingModel.js +9 -6
- package/dist/OpenAiEmbeddingModel.js.map +1 -1
- package/dist/OpenAiError.d.ts +85 -3
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiError.js +14 -1
- package/dist/OpenAiLanguageModel.d.ts +161 -12
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +9 -7
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiTelemetry.d.ts +13 -10
- package/dist/OpenAiTelemetry.d.ts.map +1 -1
- package/dist/OpenAiTelemetry.js +2 -2
- package/dist/OpenAiTelemetry.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +7 -7
- package/package.json +3 -3
- package/src/OpenAiClient.ts +169 -42
- package/src/OpenAiConfig.ts +56 -8
- package/src/OpenAiEmbeddingModel.ts +16 -11
- package/src/OpenAiError.ts +85 -3
- package/src/OpenAiLanguageModel.ts +164 -15
- package/src/OpenAiTelemetry.ts +14 -11
- package/src/index.ts +7 -7
package/src/OpenAiError.ts
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `OpenAiError` module defines OpenAI-specific metadata that can be
|
|
3
|
+
* attached to the shared `AiError` error types used by the AI packages. It is
|
|
4
|
+
* primarily used by OpenAI-compatible clients to preserve provider details
|
|
5
|
+
* such as error codes, error types, request IDs, and rate limit headers while
|
|
6
|
+
* still exposing errors through the provider-neutral Effect AI error model.
|
|
7
|
+
*
|
|
8
|
+
* Use this module when mapping OpenAI API failures into `AiError` values and
|
|
9
|
+
* when consumers need enough structured metadata to debug failed requests,
|
|
10
|
+
* inspect quota or rate limit responses, or correlate an error with OpenAI
|
|
11
|
+
* support. The exported types are metadata shapes only; the module augmentation
|
|
12
|
+
* makes those shapes available on the corresponding shared AI error metadata
|
|
13
|
+
* interfaces without defining new runtime error classes.
|
|
14
|
+
*
|
|
15
|
+
* @since 4.0.0
|
|
3
16
|
*/
|
|
4
17
|
|
|
5
18
|
/**
|
|
6
19
|
* OpenAI-specific error metadata fields.
|
|
7
20
|
*
|
|
8
|
-
* @since 1.0.0
|
|
9
21
|
* @category models
|
|
22
|
+
* @since 4.0.0
|
|
10
23
|
*/
|
|
11
24
|
export type OpenAiErrorMetadata = {
|
|
12
25
|
/**
|
|
@@ -29,8 +42,8 @@ export type OpenAiErrorMetadata = {
|
|
|
29
42
|
* Extends base error metadata with rate limit specific information from
|
|
30
43
|
* OpenAI's rate limit headers.
|
|
31
44
|
*
|
|
32
|
-
* @since 1.0.0
|
|
33
45
|
* @category models
|
|
46
|
+
* @since 4.0.0
|
|
34
47
|
*/
|
|
35
48
|
export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
|
|
36
49
|
/**
|
|
@@ -52,42 +65,111 @@ export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
|
|
|
52
65
|
}
|
|
53
66
|
|
|
54
67
|
declare module "effect/unstable/ai/AiError" {
|
|
68
|
+
/**
|
|
69
|
+
* Metadata attached to rate limit errors returned by OpenAI-compatible APIs.
|
|
70
|
+
*
|
|
71
|
+
* @category models
|
|
72
|
+
* @since 4.0.0
|
|
73
|
+
*/
|
|
55
74
|
export interface RateLimitErrorMetadata {
|
|
56
75
|
readonly openai?: OpenAiRateLimitMetadata | null
|
|
57
76
|
}
|
|
58
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Metadata attached when an OpenAI-compatible provider reports that quota or
|
|
80
|
+
* billing limits have been exhausted.
|
|
81
|
+
*
|
|
82
|
+
* @category models
|
|
83
|
+
* @since 4.0.0
|
|
84
|
+
*/
|
|
59
85
|
export interface QuotaExhaustedErrorMetadata {
|
|
60
86
|
readonly openai?: OpenAiErrorMetadata | null
|
|
61
87
|
}
|
|
62
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Metadata attached to authentication failures from OpenAI-compatible APIs,
|
|
91
|
+
* such as invalid, missing, or unauthorized API credentials.
|
|
92
|
+
*
|
|
93
|
+
* @category models
|
|
94
|
+
* @since 4.0.0
|
|
95
|
+
*/
|
|
63
96
|
export interface AuthenticationErrorMetadata {
|
|
64
97
|
readonly openai?: OpenAiErrorMetadata | null
|
|
65
98
|
}
|
|
66
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Metadata attached when an OpenAI-compatible provider rejects content because
|
|
102
|
+
* it violates a safety or usage policy.
|
|
103
|
+
*
|
|
104
|
+
* @category models
|
|
105
|
+
* @since 4.0.0
|
|
106
|
+
*/
|
|
67
107
|
export interface ContentPolicyErrorMetadata {
|
|
68
108
|
readonly openai?: OpenAiErrorMetadata | null
|
|
69
109
|
}
|
|
70
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Metadata attached to malformed or unsupported requests rejected by an
|
|
113
|
+
* OpenAI-compatible API before model execution.
|
|
114
|
+
*
|
|
115
|
+
* @category models
|
|
116
|
+
* @since 4.0.0
|
|
117
|
+
*/
|
|
71
118
|
export interface InvalidRequestErrorMetadata {
|
|
72
119
|
readonly openai?: OpenAiErrorMetadata | null
|
|
73
120
|
}
|
|
74
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Metadata attached to unexpected server-side failures reported by an
|
|
124
|
+
* OpenAI-compatible provider.
|
|
125
|
+
*
|
|
126
|
+
* @category models
|
|
127
|
+
* @since 4.0.0
|
|
128
|
+
*/
|
|
75
129
|
export interface InternalProviderErrorMetadata {
|
|
76
130
|
readonly openai?: OpenAiErrorMetadata | null
|
|
77
131
|
}
|
|
78
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Metadata attached when an OpenAI-compatible response cannot be converted
|
|
135
|
+
* into the expected AI package output shape.
|
|
136
|
+
*
|
|
137
|
+
* @category models
|
|
138
|
+
* @since 4.0.0
|
|
139
|
+
*/
|
|
79
140
|
export interface InvalidOutputErrorMetadata {
|
|
80
141
|
readonly openai?: OpenAiErrorMetadata | null
|
|
81
142
|
}
|
|
82
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Metadata attached when an OpenAI-compatible structured output response does
|
|
146
|
+
* not satisfy the requested schema or parsing constraints.
|
|
147
|
+
*
|
|
148
|
+
* @category models
|
|
149
|
+
* @since 4.0.0
|
|
150
|
+
*/
|
|
83
151
|
export interface StructuredOutputErrorMetadata {
|
|
84
152
|
readonly openai?: OpenAiErrorMetadata | null
|
|
85
153
|
}
|
|
86
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Metadata attached when an OpenAI-compatible provider cannot support the
|
|
157
|
+
* schema supplied for structured output or tool definitions.
|
|
158
|
+
*
|
|
159
|
+
* @category models
|
|
160
|
+
* @since 4.0.0
|
|
161
|
+
*/
|
|
87
162
|
export interface UnsupportedSchemaErrorMetadata {
|
|
88
163
|
readonly openai?: OpenAiErrorMetadata | null
|
|
89
164
|
}
|
|
90
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Metadata attached when an OpenAI-compatible error response cannot be mapped
|
|
168
|
+
* to a more specific shared AI error category.
|
|
169
|
+
*
|
|
170
|
+
* @category models
|
|
171
|
+
* @since 4.0.0
|
|
172
|
+
*/
|
|
91
173
|
export interface UnknownErrorMetadata {
|
|
92
174
|
readonly openai?: OpenAiErrorMetadata | null
|
|
93
175
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Provides a LanguageModel implementation for OpenAI's chat completions API,
|
|
5
5
|
* supporting text generation, structured output, tool calling, and streaming.
|
|
6
6
|
*
|
|
7
|
-
* @since
|
|
7
|
+
* @since 4.0.0
|
|
8
8
|
*/
|
|
9
9
|
import * as Context from "effect/Context"
|
|
10
10
|
import * as DateTime from "effect/DateTime"
|
|
@@ -61,8 +61,8 @@ type ImageDetail = "auto" | "low" | "high"
|
|
|
61
61
|
/**
|
|
62
62
|
* Service definition for OpenAI language model configuration.
|
|
63
63
|
*
|
|
64
|
-
* @since 1.0.0
|
|
65
64
|
* @category context
|
|
65
|
+
* @since 4.0.0
|
|
66
66
|
*/
|
|
67
67
|
export class Config extends Context.Service<
|
|
68
68
|
Config,
|
|
@@ -112,7 +112,13 @@ export class Config extends Context.Service<
|
|
|
112
112
|
// =============================================================================
|
|
113
113
|
|
|
114
114
|
declare module "effect/unstable/ai/Prompt" {
|
|
115
|
+
/**
|
|
116
|
+
* OpenAI-compatible options for file prompt parts.
|
|
117
|
+
*/
|
|
115
118
|
export interface FilePartOptions extends ProviderOptions {
|
|
119
|
+
/**
|
|
120
|
+
* Provider-specific file options for OpenAI-compatible APIs.
|
|
121
|
+
*/
|
|
116
122
|
readonly openai?: {
|
|
117
123
|
/**
|
|
118
124
|
* The detail level of the image to be sent to the model. One of `high`, `low`, or `auto`. Defaults to `auto`.
|
|
@@ -121,7 +127,13 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
121
127
|
} | null
|
|
122
128
|
}
|
|
123
129
|
|
|
130
|
+
/**
|
|
131
|
+
* OpenAI-compatible options for reasoning prompt parts.
|
|
132
|
+
*/
|
|
124
133
|
export interface ReasoningPartOptions extends ProviderOptions {
|
|
134
|
+
/**
|
|
135
|
+
* Provider-specific reasoning options for OpenAI-compatible APIs.
|
|
136
|
+
*/
|
|
125
137
|
readonly openai?: {
|
|
126
138
|
/**
|
|
127
139
|
* The ID of the item to reference.
|
|
@@ -136,40 +148,58 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
136
148
|
} | null
|
|
137
149
|
}
|
|
138
150
|
|
|
151
|
+
/**
|
|
152
|
+
* OpenAI-compatible options for assistant tool-call prompt parts.
|
|
153
|
+
*/
|
|
139
154
|
export interface ToolCallPartOptions extends ProviderOptions {
|
|
155
|
+
/**
|
|
156
|
+
* Provider-specific tool-call options for OpenAI-compatible APIs.
|
|
157
|
+
*/
|
|
140
158
|
readonly openai?: {
|
|
141
159
|
/**
|
|
142
160
|
* The ID of the item to reference.
|
|
143
161
|
*/
|
|
144
162
|
readonly itemId?: string | null
|
|
145
163
|
/**
|
|
146
|
-
* The status
|
|
164
|
+
* The status to send for the tool-call item.
|
|
147
165
|
*/
|
|
148
166
|
readonly status?: MessageStatus | null
|
|
149
167
|
} | null
|
|
150
168
|
}
|
|
151
169
|
|
|
170
|
+
/**
|
|
171
|
+
* OpenAI-compatible options for tool-result prompt parts.
|
|
172
|
+
*/
|
|
152
173
|
export interface ToolResultPartOptions extends ProviderOptions {
|
|
174
|
+
/**
|
|
175
|
+
* Provider-specific tool-result options for OpenAI-compatible APIs.
|
|
176
|
+
*/
|
|
153
177
|
readonly openai?: {
|
|
154
178
|
/**
|
|
155
179
|
* The ID of the item to reference.
|
|
156
180
|
*/
|
|
157
181
|
readonly itemId?: string | null
|
|
158
182
|
/**
|
|
159
|
-
* The status
|
|
183
|
+
* The status to send for the tool-result item.
|
|
160
184
|
*/
|
|
161
185
|
readonly status?: MessageStatus | null
|
|
162
186
|
} | null
|
|
163
187
|
}
|
|
164
188
|
|
|
189
|
+
/**
|
|
190
|
+
* OpenAI-compatible options for text prompt parts.
|
|
191
|
+
*/
|
|
165
192
|
export interface TextPartOptions extends ProviderOptions {
|
|
193
|
+
/**
|
|
194
|
+
* Provider-specific text options for OpenAI-compatible APIs.
|
|
195
|
+
*/
|
|
166
196
|
readonly openai?: {
|
|
167
197
|
/**
|
|
168
198
|
* The ID of the item to reference.
|
|
169
199
|
*/
|
|
170
200
|
readonly itemId?: string | null
|
|
171
201
|
/**
|
|
172
|
-
* The status
|
|
202
|
+
* The status to send for the text item.
|
|
173
203
|
*/
|
|
174
204
|
readonly status?: MessageStatus | null
|
|
175
205
|
/**
|
|
@@ -181,8 +211,17 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
181
211
|
}
|
|
182
212
|
|
|
183
213
|
declare module "effect/unstable/ai/Response" {
|
|
214
|
+
/**
|
|
215
|
+
* OpenAI-compatible metadata attached to a complete text response part.
|
|
216
|
+
*/
|
|
184
217
|
export interface TextPartMetadata extends ProviderMetadata {
|
|
218
|
+
/**
|
|
219
|
+
* Provider-specific metadata returned for the text part.
|
|
220
|
+
*/
|
|
185
221
|
readonly openai?: {
|
|
222
|
+
/**
|
|
223
|
+
* The OpenAI item ID associated with the text part.
|
|
224
|
+
*/
|
|
186
225
|
readonly itemId?: string | null
|
|
187
226
|
/**
|
|
188
227
|
* If the model emits a refusal content part, the refusal explanation
|
|
@@ -191,7 +230,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
191
230
|
*/
|
|
192
231
|
readonly refusal?: string | null
|
|
193
232
|
/**
|
|
194
|
-
* The status
|
|
233
|
+
* The status returned for the text item.
|
|
195
234
|
*/
|
|
196
235
|
readonly status?: MessageStatus | null
|
|
197
236
|
/**
|
|
@@ -201,55 +240,139 @@ declare module "effect/unstable/ai/Response" {
|
|
|
201
240
|
}
|
|
202
241
|
}
|
|
203
242
|
|
|
243
|
+
/**
|
|
244
|
+
* OpenAI-compatible metadata emitted when a streamed text part starts.
|
|
245
|
+
*/
|
|
204
246
|
export interface TextStartPartMetadata extends ProviderMetadata {
|
|
247
|
+
/**
|
|
248
|
+
* Provider-specific metadata returned for the streamed text start.
|
|
249
|
+
*/
|
|
205
250
|
readonly openai?: {
|
|
251
|
+
/**
|
|
252
|
+
* The OpenAI item ID associated with the streamed text part.
|
|
253
|
+
*/
|
|
206
254
|
readonly itemId?: string | null
|
|
207
255
|
} | null
|
|
208
256
|
}
|
|
209
257
|
|
|
258
|
+
/**
|
|
259
|
+
* OpenAI-compatible metadata emitted when a streamed text part ends.
|
|
260
|
+
*/
|
|
210
261
|
export interface TextEndPartMetadata extends ProviderMetadata {
|
|
262
|
+
/**
|
|
263
|
+
* Provider-specific metadata returned for the streamed text end.
|
|
264
|
+
*/
|
|
211
265
|
readonly openai?: {
|
|
266
|
+
/**
|
|
267
|
+
* The OpenAI item ID associated with the streamed text part.
|
|
268
|
+
*/
|
|
212
269
|
readonly itemId?: string | null
|
|
270
|
+
/**
|
|
271
|
+
* The annotations collected for the completed streamed text part.
|
|
272
|
+
*/
|
|
213
273
|
readonly annotations?: ReadonlyArray<Annotation> | null
|
|
214
274
|
} | null
|
|
215
275
|
}
|
|
216
276
|
|
|
277
|
+
/**
|
|
278
|
+
* OpenAI-compatible metadata attached to a complete reasoning response part.
|
|
279
|
+
*/
|
|
217
280
|
export interface ReasoningPartMetadata extends ProviderMetadata {
|
|
281
|
+
/**
|
|
282
|
+
* Provider-specific metadata returned for the reasoning part.
|
|
283
|
+
*/
|
|
218
284
|
readonly openai?: {
|
|
285
|
+
/**
|
|
286
|
+
* The OpenAI item ID associated with the reasoning part.
|
|
287
|
+
*/
|
|
219
288
|
readonly itemId?: string | null
|
|
289
|
+
/**
|
|
290
|
+
* Encrypted reasoning content that can be sent back in later requests.
|
|
291
|
+
*/
|
|
220
292
|
readonly encryptedContent?: string | null
|
|
221
293
|
} | null
|
|
222
294
|
}
|
|
223
295
|
|
|
296
|
+
/**
|
|
297
|
+
* OpenAI-compatible metadata emitted when a streamed reasoning part starts.
|
|
298
|
+
*/
|
|
224
299
|
export interface ReasoningStartPartMetadata extends ProviderMetadata {
|
|
300
|
+
/**
|
|
301
|
+
* Provider-specific metadata returned for the streamed reasoning start.
|
|
302
|
+
*/
|
|
225
303
|
readonly openai?: {
|
|
304
|
+
/**
|
|
305
|
+
* The OpenAI item ID associated with the reasoning part.
|
|
306
|
+
*/
|
|
226
307
|
readonly itemId?: string | null
|
|
308
|
+
/**
|
|
309
|
+
* Encrypted reasoning content that can be sent back in later requests.
|
|
310
|
+
*/
|
|
227
311
|
readonly encryptedContent?: string | null
|
|
228
312
|
} | null
|
|
229
313
|
}
|
|
230
314
|
|
|
315
|
+
/**
|
|
316
|
+
* OpenAI-compatible metadata emitted for a streamed reasoning delta.
|
|
317
|
+
*/
|
|
231
318
|
export interface ReasoningDeltaPartMetadata extends ProviderMetadata {
|
|
319
|
+
/**
|
|
320
|
+
* Provider-specific metadata returned for the streamed reasoning delta.
|
|
321
|
+
*/
|
|
232
322
|
readonly openai?: {
|
|
323
|
+
/**
|
|
324
|
+
* The OpenAI item ID associated with the reasoning part.
|
|
325
|
+
*/
|
|
233
326
|
readonly itemId?: string | null
|
|
234
327
|
} | null
|
|
235
328
|
}
|
|
236
329
|
|
|
330
|
+
/**
|
|
331
|
+
* OpenAI-compatible metadata emitted when a streamed reasoning part ends.
|
|
332
|
+
*/
|
|
237
333
|
export interface ReasoningEndPartMetadata extends ProviderMetadata {
|
|
334
|
+
/**
|
|
335
|
+
* Provider-specific metadata returned for the streamed reasoning end.
|
|
336
|
+
*/
|
|
238
337
|
readonly openai?: {
|
|
338
|
+
/**
|
|
339
|
+
* The OpenAI item ID associated with the reasoning part.
|
|
340
|
+
*/
|
|
239
341
|
readonly itemId?: string | null
|
|
342
|
+
/**
|
|
343
|
+
* Encrypted reasoning content that can be sent back in later requests.
|
|
344
|
+
*/
|
|
240
345
|
readonly encryptedContent?: string
|
|
241
346
|
} | null
|
|
242
347
|
}
|
|
243
348
|
|
|
349
|
+
/**
|
|
350
|
+
* OpenAI-compatible metadata attached to tool-call response parts.
|
|
351
|
+
*/
|
|
244
352
|
export interface ToolCallPartMetadata extends ProviderMetadata {
|
|
353
|
+
/**
|
|
354
|
+
* Provider-specific metadata returned for the tool call.
|
|
355
|
+
*/
|
|
245
356
|
readonly openai?: {
|
|
357
|
+
/**
|
|
358
|
+
* The OpenAI item ID associated with the tool call.
|
|
359
|
+
*/
|
|
246
360
|
readonly itemId?: string | null
|
|
247
361
|
} | null
|
|
248
362
|
}
|
|
249
363
|
|
|
364
|
+
/**
|
|
365
|
+
* OpenAI-compatible metadata attached to document source citations.
|
|
366
|
+
*/
|
|
250
367
|
export interface DocumentSourcePartMetadata extends ProviderMetadata {
|
|
368
|
+
/**
|
|
369
|
+
* Provider-specific citation metadata for OpenAI-compatible APIs.
|
|
370
|
+
*/
|
|
251
371
|
readonly openai?:
|
|
252
372
|
| {
|
|
373
|
+
/**
|
|
374
|
+
* Identifies a citation to an uploaded file.
|
|
375
|
+
*/
|
|
253
376
|
readonly type: "file_citation"
|
|
254
377
|
/**
|
|
255
378
|
* The index of the file in the list of files.
|
|
@@ -261,6 +384,9 @@ declare module "effect/unstable/ai/Response" {
|
|
|
261
384
|
readonly fileId: string
|
|
262
385
|
}
|
|
263
386
|
| {
|
|
387
|
+
/**
|
|
388
|
+
* Identifies a citation to a generated file path.
|
|
389
|
+
*/
|
|
264
390
|
readonly type: "file_path"
|
|
265
391
|
/**
|
|
266
392
|
* The index of the file in the list of files.
|
|
@@ -272,6 +398,9 @@ declare module "effect/unstable/ai/Response" {
|
|
|
272
398
|
readonly fileId: string
|
|
273
399
|
}
|
|
274
400
|
| {
|
|
401
|
+
/**
|
|
402
|
+
* Identifies a citation to a file inside a container.
|
|
403
|
+
*/
|
|
275
404
|
readonly type: "container_file_citation"
|
|
276
405
|
/**
|
|
277
406
|
* The ID of the file.
|
|
@@ -285,8 +414,17 @@ declare module "effect/unstable/ai/Response" {
|
|
|
285
414
|
| null
|
|
286
415
|
}
|
|
287
416
|
|
|
417
|
+
/**
|
|
418
|
+
* OpenAI-compatible metadata attached to URL source citations.
|
|
419
|
+
*/
|
|
288
420
|
export interface UrlSourcePartMetadata extends ProviderMetadata {
|
|
421
|
+
/**
|
|
422
|
+
* Provider-specific URL citation metadata for OpenAI-compatible APIs.
|
|
423
|
+
*/
|
|
289
424
|
readonly openai?: {
|
|
425
|
+
/**
|
|
426
|
+
* Identifies a citation to a URL.
|
|
427
|
+
*/
|
|
290
428
|
readonly type: "url_citation"
|
|
291
429
|
/**
|
|
292
430
|
* The index of the first character of the URL citation in the message.
|
|
@@ -299,8 +437,17 @@ declare module "effect/unstable/ai/Response" {
|
|
|
299
437
|
} | null
|
|
300
438
|
}
|
|
301
439
|
|
|
440
|
+
/**
|
|
441
|
+
* OpenAI-compatible metadata attached to finish response parts.
|
|
442
|
+
*/
|
|
302
443
|
export interface FinishPartMetadata extends ProviderMetadata {
|
|
444
|
+
/**
|
|
445
|
+
* Provider-specific metadata returned when generation finishes.
|
|
446
|
+
*/
|
|
303
447
|
readonly openai?: {
|
|
448
|
+
/**
|
|
449
|
+
* The service tier reported by the OpenAI-compatible provider.
|
|
450
|
+
*/
|
|
304
451
|
readonly serviceTier?: "default" | "auto" | "flex" | "scale" | "priority" | null
|
|
305
452
|
} | null
|
|
306
453
|
}
|
|
@@ -311,8 +458,10 @@ declare module "effect/unstable/ai/Response" {
|
|
|
311
458
|
// =============================================================================
|
|
312
459
|
|
|
313
460
|
/**
|
|
314
|
-
*
|
|
461
|
+
* Creates an AI model descriptor for an OpenAI-compatible language model.
|
|
462
|
+
*
|
|
315
463
|
* @category constructors
|
|
464
|
+
* @since 4.0.0
|
|
316
465
|
*/
|
|
317
466
|
export const model = (
|
|
318
467
|
model: string,
|
|
@@ -322,7 +471,7 @@ export const model = (
|
|
|
322
471
|
|
|
323
472
|
// TODO
|
|
324
473
|
// /**
|
|
325
|
-
// * @since
|
|
474
|
+
// * @since 4.0.0
|
|
326
475
|
// * @category constructors
|
|
327
476
|
// */
|
|
328
477
|
// export const modelWithTokenizer = (
|
|
@@ -334,8 +483,8 @@ export const model = (
|
|
|
334
483
|
/**
|
|
335
484
|
* Creates an OpenAI language model service.
|
|
336
485
|
*
|
|
337
|
-
* @since 1.0.0
|
|
338
486
|
* @category constructors
|
|
487
|
+
* @since 4.0.0
|
|
339
488
|
*/
|
|
340
489
|
export const make = Effect.fnUntraced(function*({ model, config: providerConfig }: {
|
|
341
490
|
readonly model: string
|
|
@@ -433,8 +582,8 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
|
|
|
433
582
|
/**
|
|
434
583
|
* Creates a layer for the OpenAI language model.
|
|
435
584
|
*
|
|
436
|
-
* @since 1.0.0
|
|
437
585
|
* @category layers
|
|
586
|
+
* @since 4.0.0
|
|
438
587
|
*/
|
|
439
588
|
export const layer = (options: {
|
|
440
589
|
readonly model: string
|
|
@@ -445,37 +594,37 @@ export const layer = (options: {
|
|
|
445
594
|
/**
|
|
446
595
|
* Provides config overrides for OpenAI language model operations.
|
|
447
596
|
*
|
|
448
|
-
* @since 1.0.0
|
|
449
597
|
* @category configuration
|
|
598
|
+
* @since 4.0.0
|
|
450
599
|
*/
|
|
451
600
|
export const withConfigOverride: {
|
|
452
601
|
/**
|
|
453
602
|
* Provides config overrides for OpenAI language model operations.
|
|
454
603
|
*
|
|
455
|
-
* @since 1.0.0
|
|
456
604
|
* @category configuration
|
|
605
|
+
* @since 4.0.0
|
|
457
606
|
*/
|
|
458
607
|
(overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
|
|
459
608
|
/**
|
|
460
609
|
* Provides config overrides for OpenAI language model operations.
|
|
461
610
|
*
|
|
462
|
-
* @since 1.0.0
|
|
463
611
|
* @category configuration
|
|
612
|
+
* @since 4.0.0
|
|
464
613
|
*/
|
|
465
614
|
<A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
|
|
466
615
|
} = dual<
|
|
467
616
|
/**
|
|
468
617
|
* Provides config overrides for OpenAI language model operations.
|
|
469
618
|
*
|
|
470
|
-
* @since 1.0.0
|
|
471
619
|
* @category configuration
|
|
620
|
+
* @since 4.0.0
|
|
472
621
|
*/
|
|
473
622
|
(overrides: typeof Config.Service) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>,
|
|
474
623
|
/**
|
|
475
624
|
* Provides config overrides for OpenAI language model operations.
|
|
476
625
|
*
|
|
477
|
-
* @since 1.0.0
|
|
478
626
|
* @category configuration
|
|
627
|
+
* @since 4.0.0
|
|
479
628
|
*/
|
|
480
629
|
<A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service) => Effect.Effect<A, E, Exclude<R, Config>>
|
|
481
630
|
>(2, (self, overrides) =>
|
package/src/OpenAiTelemetry.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* semantic conventions, extending the base GenAI attributes with OpenAI-specific
|
|
6
6
|
* request and response metadata.
|
|
7
7
|
*
|
|
8
|
-
* @since
|
|
8
|
+
* @since 4.0.0
|
|
9
9
|
*/
|
|
10
10
|
import { dual } from "effect/Function"
|
|
11
11
|
import * as String from "effect/String"
|
|
@@ -19,8 +19,8 @@ import * as Telemetry from "effect/unstable/ai/Telemetry"
|
|
|
19
19
|
*
|
|
20
20
|
* {@see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/}
|
|
21
21
|
*
|
|
22
|
-
* @since 1.0.0
|
|
23
22
|
* @category models
|
|
23
|
+
* @since 4.0.0
|
|
24
24
|
*/
|
|
25
25
|
export type OpenAiTelemetryAttributes = Simplify<
|
|
26
26
|
& Telemetry.GenAITelemetryAttributes
|
|
@@ -32,8 +32,8 @@ export type OpenAiTelemetryAttributes = Simplify<
|
|
|
32
32
|
* All telemetry attributes which are part of the GenAI specification,
|
|
33
33
|
* including the OpenAi-specific attributes.
|
|
34
34
|
*
|
|
35
|
-
* @since 1.0.0
|
|
36
35
|
* @category models
|
|
36
|
+
* @since 4.0.0
|
|
37
37
|
*/
|
|
38
38
|
export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & ResponseAttributes
|
|
39
39
|
|
|
@@ -41,8 +41,8 @@ export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & Respon
|
|
|
41
41
|
* Telemetry attributes which are part of the GenAI specification and are
|
|
42
42
|
* namespaced by `gen_ai.openai.request`.
|
|
43
43
|
*
|
|
44
|
-
* @since 1.0.0
|
|
45
44
|
* @category models
|
|
45
|
+
* @since 4.0.0
|
|
46
46
|
*/
|
|
47
47
|
export interface RequestAttributes {
|
|
48
48
|
/**
|
|
@@ -59,8 +59,8 @@ export interface RequestAttributes {
|
|
|
59
59
|
* Telemetry attributes which are part of the GenAI specification and are
|
|
60
60
|
* namespaced by `gen_ai.openai.response`.
|
|
61
61
|
*
|
|
62
|
-
* @since 1.0.0
|
|
63
62
|
* @category models
|
|
63
|
+
* @since 4.0.0
|
|
64
64
|
*/
|
|
65
65
|
export interface ResponseAttributes {
|
|
66
66
|
/**
|
|
@@ -81,8 +81,8 @@ export interface ResponseAttributes {
|
|
|
81
81
|
* If one of them applies, then the respective value **MUST** be used;
|
|
82
82
|
* otherwise, a custom value **MAY** be used.
|
|
83
83
|
*
|
|
84
|
-
* @since 1.0.0
|
|
85
84
|
* @category models
|
|
85
|
+
* @since 4.0.0
|
|
86
86
|
*/
|
|
87
87
|
export type WellKnownResponseFormat = "json_object" | "json_schema" | "text"
|
|
88
88
|
|
|
@@ -93,13 +93,16 @@ export type WellKnownResponseFormat = "json_object" | "json_schema" | "text"
|
|
|
93
93
|
* If one of them applies, then the respective value **MUST** be used;
|
|
94
94
|
* otherwise, a custom value **MAY** be used.
|
|
95
95
|
*
|
|
96
|
-
* @since 1.0.0
|
|
97
96
|
* @category models
|
|
97
|
+
* @since 4.0.0
|
|
98
98
|
*/
|
|
99
99
|
export type WellKnownServiceTier = "auto" | "default"
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
102
|
+
* Options accepted by `addGenAIAnnotations`, combining standard GenAI telemetry
|
|
103
|
+
* attributes with optional OpenAI-compatible request and response attributes.
|
|
104
|
+
*
|
|
105
|
+
* @since 4.0.0
|
|
103
106
|
* @since models
|
|
104
107
|
*/
|
|
105
108
|
export type OpenAiTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
|
|
@@ -122,7 +125,7 @@ const addOpenAiResponseAttributes = Telemetry.addSpanAttributes("gen_ai.openai.r
|
|
|
122
125
|
*
|
|
123
126
|
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
124
127
|
*
|
|
125
|
-
* @since
|
|
128
|
+
* @since 4.0.0
|
|
126
129
|
* @since utilities
|
|
127
130
|
*/
|
|
128
131
|
export const addGenAIAnnotations: {
|
|
@@ -132,7 +135,7 @@ export const addGenAIAnnotations: {
|
|
|
132
135
|
*
|
|
133
136
|
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
134
137
|
*
|
|
135
|
-
* @since
|
|
138
|
+
* @since 4.0.0
|
|
136
139
|
* @since utilities
|
|
137
140
|
*/
|
|
138
141
|
(options: OpenAiTelemetryAttributeOptions): (span: Span) => void
|
|
@@ -142,7 +145,7 @@ export const addGenAIAnnotations: {
|
|
|
142
145
|
*
|
|
143
146
|
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
144
147
|
*
|
|
145
|
-
* @since
|
|
148
|
+
* @since 4.0.0
|
|
146
149
|
* @since utilities
|
|
147
150
|
*/
|
|
148
151
|
(span: Span, options: OpenAiTelemetryAttributeOptions): void
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @since
|
|
8
|
+
* @since 4.0.0
|
|
9
9
|
*/
|
|
10
10
|
export * as OpenAiClient from "./OpenAiClient.ts"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @since
|
|
13
|
+
* @since 4.0.0
|
|
14
14
|
*/
|
|
15
15
|
export * as OpenAiConfig from "./OpenAiConfig.ts"
|
|
16
16
|
|
|
@@ -19,12 +19,12 @@ export * as OpenAiConfig from "./OpenAiConfig.ts"
|
|
|
19
19
|
*
|
|
20
20
|
* Provides an EmbeddingModel implementation for OpenAI-compatible embeddings APIs.
|
|
21
21
|
*
|
|
22
|
-
* @since
|
|
22
|
+
* @since 4.0.0
|
|
23
23
|
*/
|
|
24
24
|
export * as OpenAiEmbeddingModel from "./OpenAiEmbeddingModel.ts"
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* @since
|
|
27
|
+
* @since 4.0.0
|
|
28
28
|
*/
|
|
29
29
|
export * as OpenAiError from "./OpenAiError.ts"
|
|
30
30
|
|
|
@@ -34,7 +34,7 @@ export * as OpenAiError from "./OpenAiError.ts"
|
|
|
34
34
|
* Provides a LanguageModel implementation for OpenAI's chat completions API,
|
|
35
35
|
* supporting text generation, structured output, tool calling, and streaming.
|
|
36
36
|
*
|
|
37
|
-
* @since
|
|
37
|
+
* @since 4.0.0
|
|
38
38
|
*/
|
|
39
39
|
export * as OpenAiLanguageModel from "./OpenAiLanguageModel.ts"
|
|
40
40
|
|
|
@@ -45,6 +45,6 @@ export * as OpenAiLanguageModel from "./OpenAiLanguageModel.ts"
|
|
|
45
45
|
* semantic conventions, extending the base GenAI attributes with OpenAI-specific
|
|
46
46
|
* request and response metadata.
|
|
47
47
|
*
|
|
48
|
-
* @since
|
|
48
|
+
* @since 4.0.0
|
|
49
49
|
*/
|
|
50
50
|
export * as OpenAiTelemetry from "./OpenAiTelemetry.ts"
|