@effect/ai-openai-compat 4.0.0-beta.70 → 4.0.0-beta.72
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 +55 -4
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +55 -4
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiConfig.d.ts +12 -5
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiConfig.js +10 -3
- package/dist/OpenAiConfig.js.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +134 -10
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -1
- package/dist/OpenAiEmbeddingModel.js +104 -8
- package/dist/OpenAiEmbeddingModel.js.map +1 -1
- package/dist/OpenAiLanguageModel.d.ts +112 -10
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +86 -8
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiTelemetry.d.ts +39 -1
- package/dist/OpenAiTelemetry.d.ts.map +1 -1
- package/dist/OpenAiTelemetry.js +41 -4
- package/dist/OpenAiTelemetry.js.map +1 -1
- package/dist/index.d.ts +0 -71
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -71
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/OpenAiClient.ts +55 -4
- package/src/OpenAiConfig.ts +12 -5
- package/src/OpenAiEmbeddingModel.ts +164 -12
- package/src/OpenAiLanguageModel.ts +138 -12
- package/src/OpenAiTelemetry.ts +69 -5
- package/src/index.ts +0 -71
|
@@ -1,7 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `OpenAiEmbeddingModel` module adapts OpenAI-compatible embeddings
|
|
3
|
+
* endpoints to Effect's embedding model service. It sends embedding requests
|
|
4
|
+
* through {@link OpenAiClient}, exposes constructors for layers and `AiModel`
|
|
5
|
+
* values, and supports scoped request configuration overrides.
|
|
3
6
|
*
|
|
4
|
-
*
|
|
7
|
+
* **Mental model**
|
|
8
|
+
*
|
|
9
|
+
* - {@link make} builds the `EmbeddingModel` service when an
|
|
10
|
+
* {@link OpenAiClient} is already available.
|
|
11
|
+
* - {@link layer} provides that service as a `Layer`.
|
|
12
|
+
* - {@link model} creates an `AiModel` and also provides the configured vector
|
|
13
|
+
* dimensions service expected by embedding consumers.
|
|
14
|
+
* - {@link Config} and {@link withConfigOverride} merge default request options
|
|
15
|
+
* with scoped overrides for individual operations.
|
|
16
|
+
*
|
|
17
|
+
* **Common tasks**
|
|
18
|
+
*
|
|
19
|
+
* - Use {@link model} when application code wants a named `AiModel` with known
|
|
20
|
+
* dimensions.
|
|
21
|
+
* - Use {@link layer} when composing services around an existing
|
|
22
|
+
* {@link OpenAiClient} layer.
|
|
23
|
+
* - Use {@link withConfigOverride} to set per-operation options such as `user`,
|
|
24
|
+
* `dimensions`, or provider-specific request fields.
|
|
25
|
+
*
|
|
26
|
+
* **Gotchas**
|
|
27
|
+
*
|
|
28
|
+
* - {@link Model} is `string` because OpenAI-compatible providers use their
|
|
29
|
+
* own embedding model identifiers.
|
|
30
|
+
* - {@link model} requires explicit dimensions because compatible providers do
|
|
31
|
+
* not expose a shared way to infer vector width.
|
|
32
|
+
* - Provider responses must contain one numeric vector per input with unique,
|
|
33
|
+
* in-range indexes; base64 embeddings or malformed indexes fail with
|
|
34
|
+
* `InvalidOutputError`.
|
|
5
35
|
*
|
|
6
36
|
* @since 4.0.0
|
|
7
37
|
*/
|
|
@@ -14,15 +44,36 @@ import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel";
|
|
|
14
44
|
import * as AiModel from "effect/unstable/ai/Model";
|
|
15
45
|
import { OpenAiClient } from "./OpenAiClient.js";
|
|
16
46
|
/**
|
|
17
|
-
*
|
|
47
|
+
* Context service for OpenAI embedding model configuration.
|
|
48
|
+
*
|
|
49
|
+
* **When to use**
|
|
50
|
+
*
|
|
51
|
+
* Use when you need to provide shared default request options for
|
|
52
|
+
* OpenAI-compatible embedding operations through the Effect context, such as
|
|
53
|
+
* `dimensions`, `encoding_format`, or `user`.
|
|
54
|
+
*
|
|
55
|
+
* **Details**
|
|
56
|
+
*
|
|
57
|
+
* The service stores the embedding request payload without `input`. Requests
|
|
58
|
+
* combine the selected model, layer or constructor config, and scoped context
|
|
59
|
+
* config, with scoped context config taking precedence.
|
|
60
|
+
*
|
|
61
|
+
* @see {@link withConfigOverride} for scoping embedding request overrides
|
|
18
62
|
*
|
|
19
63
|
* @category context
|
|
20
64
|
* @since 4.0.0
|
|
21
65
|
*/
|
|
22
66
|
export class Config extends /*#__PURE__*/Context.Service()("@effect/ai-openai-compat/OpenAiEmbeddingModel/Config") {}
|
|
23
67
|
/**
|
|
24
|
-
* Creates an OpenAI-compatible embedding model
|
|
25
|
-
*
|
|
68
|
+
* Creates an `AiModel` for an OpenAI-compatible embedding model with its configured vector dimensions.
|
|
69
|
+
*
|
|
70
|
+
* **When to use**
|
|
71
|
+
*
|
|
72
|
+
* Use to provide an OpenAI-compatible `EmbeddingModel` and its `Dimensions`
|
|
73
|
+
* service to an Effect program.
|
|
74
|
+
*
|
|
75
|
+
* @see {@link layer} for providing only the embedding model service
|
|
76
|
+
* @see {@link withConfigOverride} for scoped request configuration overrides
|
|
26
77
|
*
|
|
27
78
|
* @category constructors
|
|
28
79
|
* @since 4.0.0
|
|
@@ -35,7 +86,29 @@ export const model = (model, options) => AiModel.make("openai", model, Layer.mer
|
|
|
35
86
|
}
|
|
36
87
|
}), Layer.succeed(EmbeddingModel.Dimensions, options.dimensions)));
|
|
37
88
|
/**
|
|
38
|
-
* Creates an OpenAI embedding model service
|
|
89
|
+
* Creates an OpenAI-compatible embedding model service backed by `OpenAiClient`.
|
|
90
|
+
*
|
|
91
|
+
* **When to use**
|
|
92
|
+
*
|
|
93
|
+
* Use when you need to build or provide an `EmbeddingModel` service directly
|
|
94
|
+
* from an existing `OpenAiClient`.
|
|
95
|
+
*
|
|
96
|
+
* **Details**
|
|
97
|
+
*
|
|
98
|
+
* The service sends embedding requests through `OpenAiClient.createEmbedding`.
|
|
99
|
+
* Request config is merged as the selected model, constructor config, then
|
|
100
|
+
* scoped `Config`, so scoped overrides take precedence. Provider usage
|
|
101
|
+
* `prompt_tokens` is exposed as `usage.inputTokens`.
|
|
102
|
+
*
|
|
103
|
+
* **Gotchas**
|
|
104
|
+
*
|
|
105
|
+
* Provider responses must contain one numeric vector for every requested input
|
|
106
|
+
* with unique, in-range `index` values; otherwise embedding operations fail with
|
|
107
|
+
* `AiError.InvalidOutputError`.
|
|
108
|
+
*
|
|
109
|
+
* @see {@link model} for the higher-level `AiModel` descriptor that also provides `EmbeddingModel.Dimensions`
|
|
110
|
+
* @see {@link layer} for providing the service as a `Layer`
|
|
111
|
+
* @see {@link withConfigOverride} for scoping embedding request overrides
|
|
39
112
|
*
|
|
40
113
|
* @category constructors
|
|
41
114
|
* @since 4.0.0
|
|
@@ -67,14 +140,37 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
67
140
|
});
|
|
68
141
|
});
|
|
69
142
|
/**
|
|
70
|
-
* Creates a layer for
|
|
143
|
+
* Creates a layer for an OpenAI-compatible embedding model service.
|
|
144
|
+
*
|
|
145
|
+
* **When to use**
|
|
146
|
+
*
|
|
147
|
+
* Use when composing application layers and you want an OpenAI-compatible
|
|
148
|
+
* embeddings endpoint to satisfy `EmbeddingModel.EmbeddingModel` while
|
|
149
|
+
* supplying `OpenAiClient` from another layer.
|
|
150
|
+
*
|
|
151
|
+
* @see {@link make} for constructing the embedding model service effectfully
|
|
152
|
+
* @see {@link model} for creating an `AiModel` with configured dimensions
|
|
71
153
|
*
|
|
72
154
|
* @category layers
|
|
73
155
|
* @since 4.0.0
|
|
74
156
|
*/
|
|
75
157
|
export const layer = options => Layer.effect(EmbeddingModel.EmbeddingModel, make(options));
|
|
76
158
|
/**
|
|
77
|
-
* Provides config overrides for OpenAI embedding model operations.
|
|
159
|
+
* Provides scoped request config overrides for OpenAI-compatible embedding model operations.
|
|
160
|
+
*
|
|
161
|
+
* **When to use**
|
|
162
|
+
*
|
|
163
|
+
* Use to apply embedding request options to one effect without changing the
|
|
164
|
+
* model's default configuration.
|
|
165
|
+
*
|
|
166
|
+
* **Details**
|
|
167
|
+
*
|
|
168
|
+
* The overrides are merged with any existing `Config` service for the duration
|
|
169
|
+
* of the supplied effect. Fields in `overrides` take precedence over existing
|
|
170
|
+
* config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
|
|
171
|
+
* and `withConfigOverride(effect, overrides)`.
|
|
172
|
+
*
|
|
173
|
+
* @see {@link Config} for available OpenAI-compatible embedding request configuration fields
|
|
78
174
|
*
|
|
79
175
|
* @category configuration
|
|
80
176
|
* @since 4.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiEmbeddingModel.js","names":["Context","Effect","dual","Layer","AiError","EmbeddingModel","AiModel","OpenAiClient","Config","Service","model","options","make","merge","layer","config","dimensions","succeed","Dimensions","fnUntraced","providerConfig","client","makeConfig","gen","services","context","mapUnsafe","get","key","embedMany","inputs","response","createEmbedding","input","mapProviderResponse","length","effect","withConfigOverride","self","overrides","flatMap","serviceOption","provideService","_tag","value","inputLength","data","fail","invalidOutput","results","Array","seen","Set","entry","Number","isInteger","index","has","isArray","embedding","add","size","usage","inputTokens","prompt_tokens","description","module","method","reason","InvalidOutputError"],"sources":["../src/OpenAiEmbeddingModel.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"OpenAiEmbeddingModel.js","names":["Context","Effect","dual","Layer","AiError","EmbeddingModel","AiModel","OpenAiClient","Config","Service","model","options","make","merge","layer","config","dimensions","succeed","Dimensions","fnUntraced","providerConfig","client","makeConfig","gen","services","context","mapUnsafe","get","key","embedMany","inputs","response","createEmbedding","input","mapProviderResponse","length","effect","withConfigOverride","self","overrides","flatMap","serviceOption","provideService","_tag","value","inputLength","data","fail","invalidOutput","results","Array","seen","Set","entry","Number","isInteger","index","has","isArray","embedding","add","size","usage","inputTokens","prompt_tokens","description","module","method","reason","InvalidOutputError"],"sources":["../src/OpenAiEmbeddingModel.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,OAAO,MAAM,4BAA4B;AACrD,OAAO,KAAKC,cAAc,MAAM,mCAAmC;AACnE,OAAO,KAAKC,OAAO,MAAM,0BAA0B;AAEnD,SAASC,YAAY,QAAQ,mBAAmB;AAUhD;;;;;;;;;;;;;;;;;;;;AAoBA,OAAM,MAAOC,MAAO,sBAAQR,OAAO,CAACS,OAAO,EAaxC,CAAC,sDAAsD,CAAC;AAE3D;;;;;;;;;;;;;;AAcA,OAAO,MAAMC,KAAK,GAAGA,CACnBA,KAAa,EACbC,OAGC,KAEDL,OAAO,CAACM,IAAI,CACV,QAAQ,EACRF,KAAK,EACLP,KAAK,CAACU,KAAK,CACTC,KAAK,CAAC;EACJJ,KAAK;EACLK,MAAM,EAAE;IACN,GAAGJ,OAAO,CAACI,MAAM;IACjBC,UAAU,EAAEL,OAAO,CAACK;;CAEvB,CAAC,EACFb,KAAK,CAACc,OAAO,CAACZ,cAAc,CAACa,UAAU,EAAEP,OAAO,CAACK,UAAU,CAAC,CAC7D,CACF;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,OAAO,MAAMJ,IAAI,gBAAGX,MAAM,CAACkB,UAAU,CAAC,WAAU;EAAET,KAAK;EAAEK,MAAM,EAAEK;AAAc,CAG9E;EACC,MAAMC,MAAM,GAAG,OAAOd,YAAY;EAElC,MAAMe,UAAU,GAAGrB,MAAM,CAACsB,GAAG,CAAC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AACU,IAAI,wBAAwBhB,WAAW,EAAE,CAAC,CAClG;EACH;EAEA,OAAO5C,MAAM,CAACgB,OAAO,CAAC;IACpBgC,OAAO;IACPa,KAAK,EAAE;MACLC,WAAW,EAAEhC,QAAQ,CAAC+B,KAAK,EAAEE;;GAEhC,CAAC;AACJ,CAAC;AAED,MAAMhB,aAAa,GAAIiB,WAAmB,IACxC7D,OAAO,CAACQ,IAAI,CAAC;EACXsD,MAAM,EAAE,sBAAsB;EAC9BC,MAAM,EAAE,WAAW;EACnBC,MAAM,EAAE,IAAIhE,OAAO,CAACiE,kBAAkB,CAAC;IAAEJ;EAAW,CAAE;CACvD,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `OpenAiLanguageModel` module adapts OpenAI-compatible chat-completions
|
|
3
|
+
* providers to the shared Effect AI `LanguageModel` interface. It translates
|
|
4
|
+
* provider-neutral prompts, tools, structured output schemas, and streaming
|
|
5
|
+
* responses into the request and response shapes used by `OpenAiClient`.
|
|
3
6
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
7
|
+
* Use this module when an application wants to talk to OpenAI-compatible
|
|
8
|
+
* endpoints through Effect AI abstractions rather than constructing provider
|
|
9
|
+
* payloads directly. The exported constructors build a language model service
|
|
10
|
+
* from a model id, while `Config` and {@link withConfigOverride} provide scoped
|
|
11
|
+
* defaults for request fields such as temperature, reasoning options, text
|
|
12
|
+
* format, and provider-specific file handling.
|
|
13
|
+
*
|
|
14
|
+
* **Common tasks**
|
|
15
|
+
*
|
|
16
|
+
* - Create a model descriptor with {@link model}
|
|
17
|
+
* - Build or provide the `LanguageModel` service with {@link make} or
|
|
18
|
+
* {@link layer}
|
|
19
|
+
* - Scope request defaults with {@link Config} and {@link withConfigOverride}
|
|
20
|
+
* - Send tool calls, structured output schemas, images, files, and reasoning
|
|
21
|
+
* metadata through the provider-neutral Effect AI prompt types
|
|
22
|
+
*
|
|
23
|
+
* **Gotchas**
|
|
24
|
+
*
|
|
25
|
+
* - The module requires an `OpenAiClient` service; configure authentication,
|
|
26
|
+
* base URL, and HTTP behavior through that client layer.
|
|
27
|
+
* - Compatibility depends on the provider supporting the OpenAI request fields
|
|
28
|
+
* being used. Optional capabilities such as strict JSON schemas, reasoning
|
|
29
|
+
* metadata, and tool status fields may vary across providers.
|
|
30
|
+
* - `fileIdPrefixes` tells the prompt conversion which file references are
|
|
31
|
+
* provider file IDs instead of base64 file contents.
|
|
6
32
|
*
|
|
7
33
|
* @since 4.0.0
|
|
8
34
|
*/
|
|
@@ -61,7 +87,15 @@ declare const Config_base: Context.ServiceClass<Config, "@effect/ai-openai-compa
|
|
|
61
87
|
readonly strictJsonSchema?: boolean | undefined | undefined;
|
|
62
88
|
}>;
|
|
63
89
|
/**
|
|
64
|
-
*
|
|
90
|
+
* Context service for OpenAI language model configuration.
|
|
91
|
+
*
|
|
92
|
+
* **When to use**
|
|
93
|
+
*
|
|
94
|
+
* Use as the context service for OpenAI-compatible language model request
|
|
95
|
+
* configuration, especially when a scoped operation should override the defaults
|
|
96
|
+
* supplied to `model`, `make`, or `layer`.
|
|
97
|
+
*
|
|
98
|
+
* @see {@link withConfigOverride} for scoping language model request overrides
|
|
65
99
|
*
|
|
66
100
|
* @category context
|
|
67
101
|
* @since 4.0.0
|
|
@@ -439,14 +473,37 @@ declare module "effect/unstable/ai/Response" {
|
|
|
439
473
|
}
|
|
440
474
|
}
|
|
441
475
|
/**
|
|
442
|
-
* Creates an
|
|
476
|
+
* Creates an OpenAI-compatible model descriptor that can be provided with `Effect.provide`.
|
|
477
|
+
*
|
|
478
|
+
* **When to use**
|
|
479
|
+
*
|
|
480
|
+
* Use when you want an OpenAI-compatible language model value that carries
|
|
481
|
+
* provider and model metadata and can be supplied directly to an Effect program.
|
|
482
|
+
*
|
|
483
|
+
* @see {@link layer} for creating a `LanguageModel.LanguageModel` layer directly
|
|
484
|
+
* @see {@link make} for constructing the language model service effectfully
|
|
443
485
|
*
|
|
444
486
|
* @category constructors
|
|
445
487
|
* @since 4.0.0
|
|
446
488
|
*/
|
|
447
489
|
export declare const model: (model: string, config?: Omit<typeof Config.Service, "model">) => AiModel.Model<"openai", LanguageModel.LanguageModel, OpenAiClient>;
|
|
448
490
|
/**
|
|
449
|
-
* Creates an OpenAI
|
|
491
|
+
* Creates an OpenAI-compatible `LanguageModel` service from a model identifier and optional request defaults.
|
|
492
|
+
*
|
|
493
|
+
* **When to use**
|
|
494
|
+
*
|
|
495
|
+
* Use when an Effect needs to construct a `LanguageModel.Service` value backed
|
|
496
|
+
* by `OpenAiClient`.
|
|
497
|
+
*
|
|
498
|
+
* **Details**
|
|
499
|
+
*
|
|
500
|
+
* The returned effect requires `OpenAiClient`. Request defaults from the
|
|
501
|
+
* `config` option are merged with any `Config` service in the context, with
|
|
502
|
+
* context values taking precedence. The service supports both `generateText` and
|
|
503
|
+
* `streamText`.
|
|
504
|
+
*
|
|
505
|
+
* @see {@link layer} for providing the service as a `Layer`
|
|
506
|
+
* @see {@link model} for creating a model descriptor for `AiModel.provide`
|
|
450
507
|
*
|
|
451
508
|
* @category constructors
|
|
452
509
|
* @since 4.0.0
|
|
@@ -456,7 +513,16 @@ export declare const make: (args_0: {
|
|
|
456
513
|
readonly config?: Omit<typeof Config.Service, "model"> | undefined;
|
|
457
514
|
}) => Effect.Effect<LanguageModel.Service, never, OpenAiClient>;
|
|
458
515
|
/**
|
|
459
|
-
* Creates a layer for the OpenAI language model.
|
|
516
|
+
* Creates a layer for the OpenAI-compatible language model.
|
|
517
|
+
*
|
|
518
|
+
* **When to use**
|
|
519
|
+
*
|
|
520
|
+
* Use when composing application layers and you want OpenAI-compatible APIs to
|
|
521
|
+
* satisfy `LanguageModel.LanguageModel` while supplying `OpenAiClient` from
|
|
522
|
+
* another layer.
|
|
523
|
+
*
|
|
524
|
+
* @see {@link make} for constructing the language model service effectfully
|
|
525
|
+
* @see {@link model} for creating an AI model descriptor
|
|
460
526
|
*
|
|
461
527
|
* @category layers
|
|
462
528
|
* @since 4.0.0
|
|
@@ -466,21 +532,57 @@ export declare const layer: (options: {
|
|
|
466
532
|
readonly config?: Omit<typeof Config.Service, "model"> | undefined;
|
|
467
533
|
}) => Layer.Layer<LanguageModel.LanguageModel, never, OpenAiClient>;
|
|
468
534
|
/**
|
|
469
|
-
* Provides config overrides for OpenAI language model operations.
|
|
535
|
+
* Provides scoped config overrides for OpenAI-compatible language model operations.
|
|
536
|
+
*
|
|
537
|
+
* **When to use**
|
|
538
|
+
*
|
|
539
|
+
* Use to override request configuration for a single language model effect
|
|
540
|
+
* without changing the defaults supplied to `model`, `make`, or `layer`.
|
|
541
|
+
*
|
|
542
|
+
* **Details**
|
|
543
|
+
*
|
|
544
|
+
* Existing `Config` values from the Effect context are merged with `overrides`,
|
|
545
|
+
* and the override values take precedence.
|
|
546
|
+
*
|
|
547
|
+
* @see {@link Config} for the configuration shape
|
|
470
548
|
*
|
|
471
549
|
* @category configuration
|
|
472
550
|
* @since 4.0.0
|
|
473
551
|
*/
|
|
474
552
|
export declare const withConfigOverride: {
|
|
475
553
|
/**
|
|
476
|
-
* Provides config overrides for OpenAI language model operations.
|
|
554
|
+
* Provides scoped config overrides for OpenAI-compatible language model operations.
|
|
555
|
+
*
|
|
556
|
+
* **When to use**
|
|
557
|
+
*
|
|
558
|
+
* Use to override request configuration for a single language model effect
|
|
559
|
+
* without changing the defaults supplied to `model`, `make`, or `layer`.
|
|
560
|
+
*
|
|
561
|
+
* **Details**
|
|
562
|
+
*
|
|
563
|
+
* Existing `Config` values from the Effect context are merged with `overrides`,
|
|
564
|
+
* and the override values take precedence.
|
|
565
|
+
*
|
|
566
|
+
* @see {@link Config} for the configuration shape
|
|
477
567
|
*
|
|
478
568
|
* @category configuration
|
|
479
569
|
* @since 4.0.0
|
|
480
570
|
*/
|
|
481
571
|
(overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>;
|
|
482
572
|
/**
|
|
483
|
-
* Provides config overrides for OpenAI language model operations.
|
|
573
|
+
* Provides scoped config overrides for OpenAI-compatible language model operations.
|
|
574
|
+
*
|
|
575
|
+
* **When to use**
|
|
576
|
+
*
|
|
577
|
+
* Use to override request configuration for a single language model effect
|
|
578
|
+
* without changing the defaults supplied to `model`, `make`, or `layer`.
|
|
579
|
+
*
|
|
580
|
+
* **Details**
|
|
581
|
+
*
|
|
582
|
+
* Existing `Config` values from the Effect context are merged with `overrides`,
|
|
583
|
+
* and the override values take precedence.
|
|
584
|
+
*
|
|
585
|
+
* @see {@link Config} for the configuration shape
|
|
484
586
|
*
|
|
485
587
|
* @category configuration
|
|
486
588
|
* @since 4.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiLanguageModel.d.ts","sourceRoot":"","sources":["../src/OpenAiLanguageModel.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"OpenAiLanguageModel.d.ts","sourceRoot":"","sources":["../src/OpenAiLanguageModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAUrC,OAAO,KAAK,aAAa,MAAM,kCAAkC,CAAA;AACjE,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAA;AAQnD,OAAO,EACL,KAAK,UAAU,EAMf,KAAK,WAAW,EAGhB,KAAK,aAAa,EAClB,YAAY,EAKb,MAAM,mBAAmB,CAAA;AAG1B;;GAEG;AACH,KAAK,WAAW,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;oBA0CpB;QACd;;;;;;WAMG;QACH,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MA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AAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;CAgDhH,CAAA"}
|
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `OpenAiLanguageModel` module adapts OpenAI-compatible chat-completions
|
|
3
|
+
* providers to the shared Effect AI `LanguageModel` interface. It translates
|
|
4
|
+
* provider-neutral prompts, tools, structured output schemas, and streaming
|
|
5
|
+
* responses into the request and response shapes used by `OpenAiClient`.
|
|
3
6
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
7
|
+
* Use this module when an application wants to talk to OpenAI-compatible
|
|
8
|
+
* endpoints through Effect AI abstractions rather than constructing provider
|
|
9
|
+
* payloads directly. The exported constructors build a language model service
|
|
10
|
+
* from a model id, while `Config` and {@link withConfigOverride} provide scoped
|
|
11
|
+
* defaults for request fields such as temperature, reasoning options, text
|
|
12
|
+
* format, and provider-specific file handling.
|
|
13
|
+
*
|
|
14
|
+
* **Common tasks**
|
|
15
|
+
*
|
|
16
|
+
* - Create a model descriptor with {@link model}
|
|
17
|
+
* - Build or provide the `LanguageModel` service with {@link make} or
|
|
18
|
+
* {@link layer}
|
|
19
|
+
* - Scope request defaults with {@link Config} and {@link withConfigOverride}
|
|
20
|
+
* - Send tool calls, structured output schemas, images, files, and reasoning
|
|
21
|
+
* metadata through the provider-neutral Effect AI prompt types
|
|
22
|
+
*
|
|
23
|
+
* **Gotchas**
|
|
24
|
+
*
|
|
25
|
+
* - The module requires an `OpenAiClient` service; configure authentication,
|
|
26
|
+
* base URL, and HTTP behavior through that client layer.
|
|
27
|
+
* - Compatibility depends on the provider supporting the OpenAI request fields
|
|
28
|
+
* being used. Optional capabilities such as strict JSON schemas, reasoning
|
|
29
|
+
* metadata, and tool status fields may vary across providers.
|
|
30
|
+
* - `fileIdPrefixes` tells the prompt conversion which file references are
|
|
31
|
+
* provider file IDs instead of base64 file contents.
|
|
6
32
|
*
|
|
7
33
|
* @since 4.0.0
|
|
8
34
|
*/
|
|
@@ -29,7 +55,15 @@ import { addGenAIAnnotations } from "./OpenAiTelemetry.js";
|
|
|
29
55
|
// Configuration
|
|
30
56
|
// =============================================================================
|
|
31
57
|
/**
|
|
32
|
-
*
|
|
58
|
+
* Context service for OpenAI language model configuration.
|
|
59
|
+
*
|
|
60
|
+
* **When to use**
|
|
61
|
+
*
|
|
62
|
+
* Use as the context service for OpenAI-compatible language model request
|
|
63
|
+
* configuration, especially when a scoped operation should override the defaults
|
|
64
|
+
* supplied to `model`, `make`, or `layer`.
|
|
65
|
+
*
|
|
66
|
+
* @see {@link withConfigOverride} for scoping language model request overrides
|
|
33
67
|
*
|
|
34
68
|
* @category context
|
|
35
69
|
* @since 4.0.0
|
|
@@ -39,7 +73,15 @@ export class Config extends /*#__PURE__*/Context.Service()("@effect/ai-openai-co
|
|
|
39
73
|
// Language Model
|
|
40
74
|
// =============================================================================
|
|
41
75
|
/**
|
|
42
|
-
* Creates an
|
|
76
|
+
* Creates an OpenAI-compatible model descriptor that can be provided with `Effect.provide`.
|
|
77
|
+
*
|
|
78
|
+
* **When to use**
|
|
79
|
+
*
|
|
80
|
+
* Use when you want an OpenAI-compatible language model value that carries
|
|
81
|
+
* provider and model metadata and can be supplied directly to an Effect program.
|
|
82
|
+
*
|
|
83
|
+
* @see {@link layer} for creating a `LanguageModel.LanguageModel` layer directly
|
|
84
|
+
* @see {@link make} for constructing the language model service effectfully
|
|
43
85
|
*
|
|
44
86
|
* @category constructors
|
|
45
87
|
* @since 4.0.0
|
|
@@ -59,7 +101,22 @@ export const model = (model, config) => AiModel.make("openai", model, layer({
|
|
|
59
101
|
// ): AiModel.Model<"openai", LanguageModel.LanguageModel | Tokenizer.Tokenizer, OpenAiClient> =>
|
|
60
102
|
// AiModel.make("openai", model, layerWithTokenizer({ model, config }))
|
|
61
103
|
/**
|
|
62
|
-
* Creates an OpenAI
|
|
104
|
+
* Creates an OpenAI-compatible `LanguageModel` service from a model identifier and optional request defaults.
|
|
105
|
+
*
|
|
106
|
+
* **When to use**
|
|
107
|
+
*
|
|
108
|
+
* Use when an Effect needs to construct a `LanguageModel.Service` value backed
|
|
109
|
+
* by `OpenAiClient`.
|
|
110
|
+
*
|
|
111
|
+
* **Details**
|
|
112
|
+
*
|
|
113
|
+
* The returned effect requires `OpenAiClient`. Request defaults from the
|
|
114
|
+
* `config` option are merged with any `Config` service in the context, with
|
|
115
|
+
* context values taking precedence. The service supports both `generateText` and
|
|
116
|
+
* `streamText`.
|
|
117
|
+
*
|
|
118
|
+
* @see {@link layer} for providing the service as a `Layer`
|
|
119
|
+
* @see {@link model} for creating a model descriptor for `AiModel.provide`
|
|
63
120
|
*
|
|
64
121
|
* @category constructors
|
|
65
122
|
* @since 4.0.0
|
|
@@ -166,14 +223,35 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
|
166
223
|
});
|
|
167
224
|
});
|
|
168
225
|
/**
|
|
169
|
-
* Creates a layer for the OpenAI language model.
|
|
226
|
+
* Creates a layer for the OpenAI-compatible language model.
|
|
227
|
+
*
|
|
228
|
+
* **When to use**
|
|
229
|
+
*
|
|
230
|
+
* Use when composing application layers and you want OpenAI-compatible APIs to
|
|
231
|
+
* satisfy `LanguageModel.LanguageModel` while supplying `OpenAiClient` from
|
|
232
|
+
* another layer.
|
|
233
|
+
*
|
|
234
|
+
* @see {@link make} for constructing the language model service effectfully
|
|
235
|
+
* @see {@link model} for creating an AI model descriptor
|
|
170
236
|
*
|
|
171
237
|
* @category layers
|
|
172
238
|
* @since 4.0.0
|
|
173
239
|
*/
|
|
174
240
|
export const layer = options => Layer.effect(LanguageModel.LanguageModel, make(options));
|
|
175
241
|
/**
|
|
176
|
-
* Provides config overrides for OpenAI language model operations.
|
|
242
|
+
* Provides scoped config overrides for OpenAI-compatible language model operations.
|
|
243
|
+
*
|
|
244
|
+
* **When to use**
|
|
245
|
+
*
|
|
246
|
+
* Use to override request configuration for a single language model effect
|
|
247
|
+
* without changing the defaults supplied to `model`, `make`, or `layer`.
|
|
248
|
+
*
|
|
249
|
+
* **Details**
|
|
250
|
+
*
|
|
251
|
+
* Existing `Config` values from the Effect context are merged with `overrides`,
|
|
252
|
+
* and the override values take precedence.
|
|
253
|
+
*
|
|
254
|
+
* @see {@link Config} for the configuration shape
|
|
177
255
|
*
|
|
178
256
|
* @category configuration
|
|
179
257
|
* @since 4.0.0
|