@effect/ai-openai-compat 4.0.0-rc.117 → 4.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/AGENTS.md +4 -4
- package/CLAUDE.md +4 -4
- package/README.md +15 -4
- package/ai-docs/package.json +1 -1
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +1 -1
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +1 -1
- package/ai-docs/src/03_stream/30_encoding.ts +1 -1
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +2 -2
- package/ai-docs/src/08_observability/index.md +1 -1
- package/ai-docs/src/40_sql/10_basics.ts +2 -2
- package/ai-docs/src/40_sql/index.md +1 -1
- package/ai-docs/src/50_http-client/10_basics.ts +1 -1
- package/ai-docs/src/51_http-server/10_basics.ts +2 -2
- package/ai-docs/src/51_http-server/20_testing.ts +2 -2
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +1 -1
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +1 -1
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +1 -1
- package/ai-docs/src/60_child-process/index.md +1 -1
- package/ai-docs/src/70_cli/10_basics.ts +1 -1
- package/ai-docs/src/70_cli/index.md +1 -1
- package/ai-docs/src/71_ai/10_language-model.ts +2 -2
- package/ai-docs/src/71_ai/20_tools.ts +2 -2
- package/ai-docs/src/71_ai/30_chat.ts +2 -2
- package/ai-docs/src/80_cluster/10_entities.ts +3 -3
- package/dist/OpenAiClient.d.ts +61 -9
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +13 -16
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiConfig.d.ts +1 -1
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +10 -11
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -1
- package/dist/OpenAiEmbeddingModel.js +9 -3
- package/dist/OpenAiEmbeddingModel.js.map +1 -1
- package/dist/OpenAiError.d.ts +1 -1
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.d.ts +27 -14
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +17 -8
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiTelemetry.d.ts +9 -1
- package/dist/OpenAiTelemetry.d.ts.map +1 -1
- package/dist/OpenAiTelemetry.js +1 -1
- package/dist/OpenAiTelemetry.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/errors.js +1 -1
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/OpenAiClient.ts +53 -8
- package/src/OpenAiConfig.ts +1 -1
- package/src/OpenAiEmbeddingModel.ts +14 -3
- package/src/OpenAiError.ts +1 -1
- package/src/OpenAiLanguageModel.ts +44 -14
- package/src/OpenAiTelemetry.ts +1 -1
- package/src/index.ts +3 -0
- package/src/internal/errors.ts +6 -6
- package/src/internal/utilities.ts +1 -1
package/src/OpenAiClient.ts
CHANGED
|
@@ -5,23 +5,24 @@
|
|
|
5
5
|
* typed helpers for non-streaming chat completions, streaming chat completions,
|
|
6
6
|
* and embedding requests.
|
|
7
7
|
*
|
|
8
|
+
* @stability unstable
|
|
8
9
|
* @since 4.0.0
|
|
9
10
|
*/
|
|
11
|
+
import type * as AiError from "effect/ai/AiError"
|
|
10
12
|
import * as Array from "effect/Array"
|
|
11
13
|
import type * as Config from "effect/Config"
|
|
12
14
|
import * as Context from "effect/Context"
|
|
13
15
|
import * as Effect from "effect/Effect"
|
|
16
|
+
import * as Sse from "effect/encoding/Sse"
|
|
14
17
|
import { identity } from "effect/Function"
|
|
18
|
+
import * as Headers from "effect/http/Headers"
|
|
19
|
+
import * as HttpClient from "effect/http/HttpClient"
|
|
20
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest"
|
|
21
|
+
import * as HttpClientResponse from "effect/http/HttpClientResponse"
|
|
15
22
|
import * as Layer from "effect/Layer"
|
|
16
23
|
import * as Redacted from "effect/Redacted"
|
|
17
24
|
import * as Schema from "effect/Schema"
|
|
18
25
|
import * as Stream from "effect/Stream"
|
|
19
|
-
import type * as AiError from "effect/unstable/ai/AiError"
|
|
20
|
-
import * as Sse from "effect/unstable/encoding/Sse"
|
|
21
|
-
import * as Headers from "effect/unstable/http/Headers"
|
|
22
|
-
import * as HttpClient from "effect/unstable/http/HttpClient"
|
|
23
|
-
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest"
|
|
24
|
-
import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse"
|
|
25
26
|
import * as Errors from "./internal/errors.ts"
|
|
26
27
|
import { OpenAiConfig } from "./OpenAiConfig.ts"
|
|
27
28
|
|
|
@@ -34,6 +35,7 @@ import { OpenAiConfig } from "./OpenAiConfig.ts"
|
|
|
34
35
|
* completions, streaming chat completions, and embeddings. Transport and
|
|
35
36
|
* schema decoding failures are mapped to `AiError`.
|
|
36
37
|
*
|
|
38
|
+
* @stability unstable
|
|
37
39
|
* @category services
|
|
38
40
|
* @since 4.0.0
|
|
39
41
|
*/
|
|
@@ -77,6 +79,7 @@ export interface Service {
|
|
|
77
79
|
* @see {@link layer} for providing the service from explicit options
|
|
78
80
|
* @see {@link layerConfig} for loading client settings from `Config`
|
|
79
81
|
*
|
|
82
|
+
* @stability unstable
|
|
80
83
|
* @category services
|
|
81
84
|
* @since 4.0.0
|
|
82
85
|
*/
|
|
@@ -87,6 +90,7 @@ export class OpenAiClient extends Context.Service<OpenAiClient, Service>()(
|
|
|
87
90
|
/**
|
|
88
91
|
* Configuration options used to construct an OpenAI-compatible client.
|
|
89
92
|
*
|
|
93
|
+
* @stability unstable
|
|
90
94
|
* @category options
|
|
91
95
|
* @since 4.0.0
|
|
92
96
|
*/
|
|
@@ -130,6 +134,7 @@ const withRedactedHeaders = Effect.updateService(
|
|
|
130
134
|
* @see {@link layer} for providing this client from explicit options
|
|
131
135
|
* @see {@link layerConfig} for loading client settings from `Config`
|
|
132
136
|
*
|
|
137
|
+
* @stability unstable
|
|
133
138
|
* @category constructors
|
|
134
139
|
* @since 4.0.0
|
|
135
140
|
*/
|
|
@@ -288,6 +293,7 @@ export const make = Effect.fnUntraced(
|
|
|
288
293
|
* @see {@link make} for constructing the client service effectfully
|
|
289
294
|
* @see {@link layerConfig} for loading client settings from `Config`
|
|
290
295
|
*
|
|
296
|
+
* @stability unstable
|
|
291
297
|
* @category layers
|
|
292
298
|
* @since 4.0.0
|
|
293
299
|
*/
|
|
@@ -312,6 +318,7 @@ export const layer = (options: Options): Layer.Layer<OpenAiClient, never, HttpCl
|
|
|
312
318
|
* @see {@link make} for constructing the client service effectfully
|
|
313
319
|
* @see {@link layer} for providing the client from already-resolved options
|
|
314
320
|
*
|
|
321
|
+
* @stability unstable
|
|
315
322
|
* @category layers
|
|
316
323
|
* @since 4.0.0
|
|
317
324
|
*/
|
|
@@ -352,6 +359,7 @@ type JsonObject = { readonly [x: string]: Schema.Json }
|
|
|
352
359
|
/**
|
|
353
360
|
* Optional response fields that can be requested with the `include` parameter.
|
|
354
361
|
*
|
|
362
|
+
* @stability unstable
|
|
355
363
|
* @category models
|
|
356
364
|
* @since 4.0.0
|
|
357
365
|
*/
|
|
@@ -363,6 +371,7 @@ export type IncludeEnum =
|
|
|
363
371
|
/**
|
|
364
372
|
* Lifecycle status shared by message, reasoning, and tool-call items.
|
|
365
373
|
*
|
|
374
|
+
* @stability unstable
|
|
366
375
|
* @category models
|
|
367
376
|
* @since 4.0.0
|
|
368
377
|
*/
|
|
@@ -391,6 +400,7 @@ type InputFileContent = {
|
|
|
391
400
|
/**
|
|
392
401
|
* Content blocks accepted in input messages.
|
|
393
402
|
*
|
|
403
|
+
* @stability unstable
|
|
394
404
|
* @category models
|
|
395
405
|
* @since 4.0.0
|
|
396
406
|
*/
|
|
@@ -399,6 +409,7 @@ export type InputContent = InputTextContent | InputImageContent | InputFileConte
|
|
|
399
409
|
/**
|
|
400
410
|
* Text content block used for model-provided reasoning summaries.
|
|
401
411
|
*
|
|
412
|
+
* @stability unstable
|
|
402
413
|
* @category models
|
|
403
414
|
* @since 4.0.0
|
|
404
415
|
*/
|
|
@@ -461,6 +472,7 @@ type FilePathAnnotation = {
|
|
|
461
472
|
/**
|
|
462
473
|
* Citation and file-path annotations attached to output text content.
|
|
463
474
|
*
|
|
475
|
+
* @stability unstable
|
|
464
476
|
* @category models
|
|
465
477
|
* @since 4.0.0
|
|
466
478
|
*/
|
|
@@ -500,6 +512,7 @@ type OutputMessage = {
|
|
|
500
512
|
* Reasoning output item containing encrypted reasoning content, summaries, and
|
|
501
513
|
* optional reasoning text.
|
|
502
514
|
*
|
|
515
|
+
* @stability unstable
|
|
503
516
|
* @category models
|
|
504
517
|
* @since 4.0.0
|
|
505
518
|
*/
|
|
@@ -557,6 +570,7 @@ type ItemReference = {
|
|
|
557
570
|
* Supports input messages, output messages, tool calls, tool outputs, reasoning
|
|
558
571
|
* items, custom tool interactions, and item references.
|
|
559
572
|
*
|
|
573
|
+
* @stability unstable
|
|
560
574
|
* @category models
|
|
561
575
|
* @since 4.0.0
|
|
562
576
|
*/
|
|
@@ -598,6 +612,7 @@ type CustomToolParam = {
|
|
|
598
612
|
/**
|
|
599
613
|
* Tool definitions that can be supplied to a Responses-style request.
|
|
600
614
|
*
|
|
615
|
+
* @stability unstable
|
|
601
616
|
* @category models
|
|
602
617
|
* @since 4.0.0
|
|
603
618
|
*/
|
|
@@ -627,6 +642,7 @@ type ToolChoice =
|
|
|
627
642
|
* Text output format configuration for plain text, JSON object, or JSON Schema
|
|
628
643
|
* responses.
|
|
629
644
|
*
|
|
645
|
+
* @stability unstable
|
|
630
646
|
* @category configuration
|
|
631
647
|
* @since 4.0.0
|
|
632
648
|
*/
|
|
@@ -649,6 +665,7 @@ export type TextResponseFormatConfiguration =
|
|
|
649
665
|
* Request options for creating a Responses-style response with an
|
|
650
666
|
* OpenAI-compatible provider.
|
|
651
667
|
*
|
|
668
|
+
* @stability unstable
|
|
652
669
|
* @category models
|
|
653
670
|
* @since 4.0.0
|
|
654
671
|
*/
|
|
@@ -689,6 +706,7 @@ export type CreateResponse = {
|
|
|
689
706
|
/**
|
|
690
707
|
* Token accounting reported on Responses-style response objects.
|
|
691
708
|
*
|
|
709
|
+
* @stability unstable
|
|
692
710
|
* @category models
|
|
693
711
|
* @since 4.0.0
|
|
694
712
|
*/
|
|
@@ -710,6 +728,7 @@ type OutputItem =
|
|
|
710
728
|
* Responses-style response object returned by compatible providers or embedded
|
|
711
729
|
* in response stream lifecycle events.
|
|
712
730
|
*
|
|
731
|
+
* @stability unstable
|
|
713
732
|
* @category models
|
|
714
733
|
* @since 4.0.0
|
|
715
734
|
*/
|
|
@@ -839,6 +858,7 @@ type UnknownResponseStreamEvent = {
|
|
|
839
858
|
/**
|
|
840
859
|
* Server-sent event shapes emitted by Responses-style response streams.
|
|
841
860
|
*
|
|
861
|
+
* @stability unstable
|
|
842
862
|
* @category streaming
|
|
843
863
|
* @since 4.0.0
|
|
844
864
|
*/
|
|
@@ -867,6 +887,7 @@ export type ResponseStreamEvent =
|
|
|
867
887
|
* string. The `index` field identifies the input item that produced this
|
|
868
888
|
* embedding.
|
|
869
889
|
*
|
|
890
|
+
* @stability unstable
|
|
870
891
|
* @category models
|
|
871
892
|
* @since 4.0.0
|
|
872
893
|
*/
|
|
@@ -879,6 +900,7 @@ export type Embedding = {
|
|
|
879
900
|
/**
|
|
880
901
|
* Request payload for the embeddings endpoint.
|
|
881
902
|
*
|
|
903
|
+
* @stability unstable
|
|
882
904
|
* @category models
|
|
883
905
|
* @since 4.0.0
|
|
884
906
|
*/
|
|
@@ -893,6 +915,7 @@ export type CreateEmbeddingRequest = {
|
|
|
893
915
|
/**
|
|
894
916
|
* Successful response payload returned by the embeddings endpoint.
|
|
895
917
|
*
|
|
918
|
+
* @stability unstable
|
|
896
919
|
* @category models
|
|
897
920
|
* @since 4.0.0
|
|
898
921
|
*/
|
|
@@ -909,6 +932,7 @@ export type CreateEmbeddingResponse = {
|
|
|
909
932
|
/**
|
|
910
933
|
* JSON request body accepted by the embeddings endpoint.
|
|
911
934
|
*
|
|
935
|
+
* @stability unstable
|
|
912
936
|
* @category models
|
|
913
937
|
* @since 4.0.0
|
|
914
938
|
*/
|
|
@@ -916,6 +940,7 @@ export type CreateEmbeddingRequestJson = CreateEmbeddingRequest
|
|
|
916
940
|
/**
|
|
917
941
|
* Decoded successful embeddings response body.
|
|
918
942
|
*
|
|
943
|
+
* @stability unstable
|
|
919
944
|
* @category models
|
|
920
945
|
* @since 4.0.0
|
|
921
946
|
*/
|
|
@@ -923,6 +948,7 @@ export type CreateEmbedding200 = CreateEmbeddingResponse
|
|
|
923
948
|
/**
|
|
924
949
|
* Structured content parts accepted in chat completion messages.
|
|
925
950
|
*
|
|
951
|
+
* @stability unstable
|
|
926
952
|
* @category models
|
|
927
953
|
* @since 4.0.0
|
|
928
954
|
*/
|
|
@@ -941,6 +967,7 @@ export type ChatCompletionContentPart =
|
|
|
941
967
|
/**
|
|
942
968
|
* Tool call data attached to an assistant chat completion message.
|
|
943
969
|
*
|
|
970
|
+
* @stability unstable
|
|
944
971
|
* @category models
|
|
945
972
|
* @since 4.0.0
|
|
946
973
|
*/
|
|
@@ -955,6 +982,7 @@ export type ChatCompletionRequestToolCall = {
|
|
|
955
982
|
/**
|
|
956
983
|
* Message shapes accepted by the chat completions endpoint.
|
|
957
984
|
*
|
|
985
|
+
* @stability unstable
|
|
958
986
|
* @category models
|
|
959
987
|
* @since 4.0.0
|
|
960
988
|
*/
|
|
@@ -972,6 +1000,7 @@ export type ChatCompletionRequestMessage =
|
|
|
972
1000
|
/**
|
|
973
1001
|
* Function tool definition accepted by the chat completions endpoint.
|
|
974
1002
|
*
|
|
1003
|
+
* @stability unstable
|
|
975
1004
|
* @category models
|
|
976
1005
|
* @since 4.0.0
|
|
977
1006
|
*/
|
|
@@ -987,6 +1016,7 @@ export type ChatCompletionTool = {
|
|
|
987
1016
|
/**
|
|
988
1017
|
* Controls whether the model may call tools and can force a specific function.
|
|
989
1018
|
*
|
|
1019
|
+
* @stability unstable
|
|
990
1020
|
* @category configuration
|
|
991
1021
|
* @since 4.0.0
|
|
992
1022
|
*/
|
|
@@ -1003,6 +1033,7 @@ export type ChatCompletionToolChoice =
|
|
|
1003
1033
|
/**
|
|
1004
1034
|
* JSON response format configuration for chat completion requests.
|
|
1005
1035
|
*
|
|
1036
|
+
* @stability unstable
|
|
1006
1037
|
* @category configuration
|
|
1007
1038
|
* @since 4.0.0
|
|
1008
1039
|
*/
|
|
@@ -1022,6 +1053,7 @@ export type ChatCompletionResponseFormat =
|
|
|
1022
1053
|
/**
|
|
1023
1054
|
* Request payload for the OpenAI-compatible chat completions endpoint.
|
|
1024
1055
|
*
|
|
1056
|
+
* @stability unstable
|
|
1025
1057
|
* @category models
|
|
1026
1058
|
* @since 4.0.0
|
|
1027
1059
|
*/
|
|
@@ -1048,6 +1080,7 @@ export type ChatCompletionRequest = {
|
|
|
1048
1080
|
/**
|
|
1049
1081
|
* JSON request body used by this client when creating a chat completion response.
|
|
1050
1082
|
*
|
|
1083
|
+
* @stability unstable
|
|
1051
1084
|
* @category models
|
|
1052
1085
|
* @since 4.0.0
|
|
1053
1086
|
*/
|
|
@@ -1055,6 +1088,7 @@ export type CreateResponseRequestJson = ChatCompletionRequest
|
|
|
1055
1088
|
/**
|
|
1056
1089
|
* Decoded successful chat completion response body returned by `createResponse`.
|
|
1057
1090
|
*
|
|
1091
|
+
* @stability unstable
|
|
1058
1092
|
* @category models
|
|
1059
1093
|
* @since 4.0.0
|
|
1060
1094
|
*/
|
|
@@ -1062,6 +1096,7 @@ export type CreateResponse200 = ChatCompletionResponse
|
|
|
1062
1096
|
/**
|
|
1063
1097
|
* Decoded server-sent event payload emitted by `createResponseStream`.
|
|
1064
1098
|
*
|
|
1099
|
+
* @stability unstable
|
|
1065
1100
|
* @category streaming
|
|
1066
1101
|
* @since 4.0.0
|
|
1067
1102
|
*/
|
|
@@ -1104,7 +1139,8 @@ const ChatCompletionToolCall = Schema.Struct({
|
|
|
1104
1139
|
})
|
|
1105
1140
|
|
|
1106
1141
|
const ChatCompletionToolCallDelta = Schema.Struct({
|
|
1107
|
-
id:
|
|
1142
|
+
// Some providers send `id: null` on tool-call continuation fragments.
|
|
1143
|
+
id: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
1108
1144
|
index: Schema.optionalKey(Schema.Int),
|
|
1109
1145
|
type: Schema.optionalKey(Schema.String),
|
|
1110
1146
|
function: Schema.optionalKey(ChatCompletionToolFunctionDelta)
|
|
@@ -1119,7 +1155,8 @@ const ChatCompletionMessage = Schema.Struct({
|
|
|
1119
1155
|
})
|
|
1120
1156
|
|
|
1121
1157
|
const ChatCompletionDelta = Schema.Struct({
|
|
1122
|
-
role:
|
|
1158
|
+
// Some providers send `role: null` on streamed text deltas.
|
|
1159
|
+
role: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
1123
1160
|
content: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
1124
1161
|
reasoning: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
1125
1162
|
reasoning_content: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
@@ -1165,6 +1202,7 @@ const ChatCompletionChunk = Schema.Struct({
|
|
|
1165
1202
|
/**
|
|
1166
1203
|
* Decoded tool-call object from a chat completion response or streaming chunk.
|
|
1167
1204
|
*
|
|
1205
|
+
* @stability unstable
|
|
1168
1206
|
* @category models
|
|
1169
1207
|
* @since 4.0.0
|
|
1170
1208
|
*/
|
|
@@ -1172,6 +1210,7 @@ export type ChatCompletionToolCall = typeof ChatCompletionToolCall.Type
|
|
|
1172
1210
|
/**
|
|
1173
1211
|
* Decoded message object from a non-streaming chat completion choice.
|
|
1174
1212
|
*
|
|
1213
|
+
* @stability unstable
|
|
1175
1214
|
* @category models
|
|
1176
1215
|
* @since 4.0.0
|
|
1177
1216
|
*/
|
|
@@ -1179,6 +1218,7 @@ export type ChatCompletionMessage = typeof ChatCompletionMessage.Type
|
|
|
1179
1218
|
/**
|
|
1180
1219
|
* Decoded choice object returned by chat completion responses and chunks.
|
|
1181
1220
|
*
|
|
1221
|
+
* @stability unstable
|
|
1182
1222
|
* @category models
|
|
1183
1223
|
* @since 4.0.0
|
|
1184
1224
|
*/
|
|
@@ -1186,6 +1226,7 @@ export type ChatCompletionChoice = typeof ChatCompletionChoice.Type
|
|
|
1186
1226
|
/**
|
|
1187
1227
|
* Decoded token usage summary returned by chat completions.
|
|
1188
1228
|
*
|
|
1229
|
+
* @stability unstable
|
|
1189
1230
|
* @category models
|
|
1190
1231
|
* @since 4.0.0
|
|
1191
1232
|
*/
|
|
@@ -1193,6 +1234,7 @@ export type ChatCompletionUsage = typeof ChatCompletionUsage.Type
|
|
|
1193
1234
|
/**
|
|
1194
1235
|
* Decoded successful response from the chat completions endpoint.
|
|
1195
1236
|
*
|
|
1237
|
+
* @stability unstable
|
|
1196
1238
|
* @category models
|
|
1197
1239
|
* @since 4.0.0
|
|
1198
1240
|
*/
|
|
@@ -1200,6 +1242,7 @@ export type ChatCompletionResponse = typeof ChatCompletionResponse.Type
|
|
|
1200
1242
|
/**
|
|
1201
1243
|
* Decoded streaming chunk emitted by the chat completions endpoint.
|
|
1202
1244
|
*
|
|
1245
|
+
* @stability unstable
|
|
1203
1246
|
* @category streaming
|
|
1204
1247
|
* @since 4.0.0
|
|
1205
1248
|
*/
|
|
@@ -1207,6 +1250,7 @@ export type ChatCompletionChunk = typeof ChatCompletionChunk.Type
|
|
|
1207
1250
|
/**
|
|
1208
1251
|
* A parsed chat completion event that does not match the expected chunk schema.
|
|
1209
1252
|
*
|
|
1253
|
+
* @stability unstable
|
|
1210
1254
|
* @category streaming
|
|
1211
1255
|
* @since 4.0.0
|
|
1212
1256
|
*/
|
|
@@ -1218,6 +1262,7 @@ export interface UnknownChatCompletionEvent {
|
|
|
1218
1262
|
* Streaming chat completion event, including decoded chunks, unknown parsed
|
|
1219
1263
|
* events, and the `[DONE]` sentinel.
|
|
1220
1264
|
*
|
|
1265
|
+
* @stability unstable
|
|
1221
1266
|
* @category streaming
|
|
1222
1267
|
* @since 4.0.0
|
|
1223
1268
|
*/
|
package/src/OpenAiConfig.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import * as Context from "effect/Context"
|
|
10
10
|
import * as Effect from "effect/Effect"
|
|
11
11
|
import { dual } from "effect/Function"
|
|
12
|
-
import type { HttpClient } from "effect/
|
|
12
|
+
import type { HttpClient } from "effect/http/HttpClient"
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Context service for OpenAI-compatible client configuration in the current
|
|
@@ -5,22 +5,24 @@
|
|
|
5
5
|
* values, supports scoped request configuration overrides, and checks that the
|
|
6
6
|
* provider returns one numeric vector for each requested input.
|
|
7
7
|
*
|
|
8
|
+
* @stability unstable
|
|
8
9
|
* @since 4.0.0
|
|
9
10
|
*/
|
|
11
|
+
import * as AiError from "effect/ai/AiError"
|
|
12
|
+
import * as EmbeddingModel from "effect/ai/EmbeddingModel"
|
|
13
|
+
import * as AiModel from "effect/ai/Model"
|
|
10
14
|
import * as Context from "effect/Context"
|
|
11
15
|
import * as Effect from "effect/Effect"
|
|
12
16
|
import { dual } from "effect/Function"
|
|
13
17
|
import * as Layer from "effect/Layer"
|
|
14
18
|
import type { Simplify } from "effect/Types"
|
|
15
|
-
import * as AiError from "effect/unstable/ai/AiError"
|
|
16
|
-
import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel"
|
|
17
|
-
import * as AiModel from "effect/unstable/ai/Model"
|
|
18
19
|
import type { CreateEmbedding200, CreateEmbeddingRequestJson } from "./OpenAiClient.ts"
|
|
19
20
|
import { OpenAiClient } from "./OpenAiClient.ts"
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* A model identifier accepted by an OpenAI-compatible embeddings endpoint.
|
|
23
24
|
*
|
|
25
|
+
* @stability unstable
|
|
24
26
|
* @category models
|
|
25
27
|
* @since 4.0.0
|
|
26
28
|
*/
|
|
@@ -46,6 +48,7 @@ type ModelConfig = Omit<ConfigOptions, "model"> & { readonly [x: string]: unknow
|
|
|
46
48
|
*
|
|
47
49
|
* @see {@link withConfigOverride} for scoping embedding request overrides
|
|
48
50
|
*
|
|
51
|
+
* @stability unstable
|
|
49
52
|
* @category services
|
|
50
53
|
* @since 4.0.0
|
|
51
54
|
*/
|
|
@@ -65,6 +68,7 @@ export class Config extends Context.Service<
|
|
|
65
68
|
* @see {@link layer} for providing only the embedding model service
|
|
66
69
|
* @see {@link withConfigOverride} for scoped request configuration overrides
|
|
67
70
|
*
|
|
71
|
+
* @stability unstable
|
|
68
72
|
* @category constructors
|
|
69
73
|
* @since 4.0.0
|
|
70
74
|
*/
|
|
@@ -112,6 +116,7 @@ export const model = (
|
|
|
112
116
|
* @see {@link layer} for providing the service as a `Layer`
|
|
113
117
|
* @see {@link withConfigOverride} for scoping embedding request overrides
|
|
114
118
|
*
|
|
119
|
+
* @stability unstable
|
|
115
120
|
* @category constructors
|
|
116
121
|
* @since 4.0.0
|
|
117
122
|
*/
|
|
@@ -146,6 +151,7 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
|
|
|
146
151
|
* @see {@link make} for constructing the embedding model service effectfully
|
|
147
152
|
* @see {@link model} for creating an `AiModel` with configured dimensions
|
|
148
153
|
*
|
|
154
|
+
* @stability unstable
|
|
149
155
|
* @category layers
|
|
150
156
|
* @since 4.0.0
|
|
151
157
|
*/
|
|
@@ -172,6 +178,7 @@ export const layer = (options: {
|
|
|
172
178
|
*
|
|
173
179
|
* @see {@link Config} for available OpenAI-compatible embedding request configuration fields
|
|
174
180
|
*
|
|
181
|
+
* @stability unstable
|
|
175
182
|
* @category configuration
|
|
176
183
|
* @since 4.0.0
|
|
177
184
|
*/
|
|
@@ -193,6 +200,7 @@ export const withConfigOverride: {
|
|
|
193
200
|
*
|
|
194
201
|
* @see {@link Config} for available OpenAI-compatible embedding request configuration fields
|
|
195
202
|
*
|
|
203
|
+
* @stability unstable
|
|
196
204
|
* @category configuration
|
|
197
205
|
* @since 4.0.0
|
|
198
206
|
*/
|
|
@@ -214,6 +222,7 @@ export const withConfigOverride: {
|
|
|
214
222
|
*
|
|
215
223
|
* @see {@link Config} for available OpenAI-compatible embedding request configuration fields
|
|
216
224
|
*
|
|
225
|
+
* @stability unstable
|
|
217
226
|
* @category configuration
|
|
218
227
|
* @since 4.0.0
|
|
219
228
|
*/
|
|
@@ -236,6 +245,7 @@ export const withConfigOverride: {
|
|
|
236
245
|
*
|
|
237
246
|
* @see {@link Config} for available OpenAI-compatible embedding request configuration fields
|
|
238
247
|
*
|
|
248
|
+
* @stability unstable
|
|
239
249
|
* @category configuration
|
|
240
250
|
* @since 4.0.0
|
|
241
251
|
*/
|
|
@@ -257,6 +267,7 @@ export const withConfigOverride: {
|
|
|
257
267
|
*
|
|
258
268
|
* @see {@link Config} for available OpenAI-compatible embedding request configuration fields
|
|
259
269
|
*
|
|
270
|
+
* @stability unstable
|
|
260
271
|
* @category configuration
|
|
261
272
|
* @since 4.0.0
|
|
262
273
|
*/
|
package/src/OpenAiError.ts
CHANGED
|
@@ -66,7 +66,7 @@ export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
|
|
|
66
66
|
readonly resetTokens: string | null
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
declare module "effect/
|
|
69
|
+
declare module "effect/ai/AiError" {
|
|
70
70
|
/**
|
|
71
71
|
* Metadata attached to rate limit errors returned by OpenAI-compatible APIs.
|
|
72
72
|
*
|