@effect/ai-openai-compat 4.0.0-beta.7 → 4.0.0-beta.71
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 +250 -51
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +108 -9
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiConfig.d.ts +83 -10
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiConfig.js +51 -7
- package/dist/OpenAiConfig.js.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +214 -0
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
- package/dist/OpenAiEmbeddingModel.js +218 -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 +326 -18
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +126 -25
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiTelemetry.d.ts +72 -22
- package/dist/OpenAiTelemetry.d.ts.map +1 -1
- package/dist/OpenAiTelemetry.js +47 -8
- 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/package.json +3 -3
- package/src/OpenAiClient.ts +283 -49
- package/src/OpenAiConfig.ts +84 -11
- package/src/OpenAiEmbeddingModel.ts +360 -0
- package/src/OpenAiError.ts +111 -35
- package/src/OpenAiLanguageModel.ts +409 -40
- package/src/OpenAiTelemetry.ts +103 -27
- package/src/index.ts +11 -17
- package/src/internal/errors.ts +4 -4
package/dist/OpenAiClient.js
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `OpenAiClient` module provides an Effect service for calling
|
|
3
|
+
* OpenAI-compatible chat completions and embeddings APIs. It builds on the
|
|
4
|
+
* Effect HTTP client, adds authentication and OpenAI header handling, and
|
|
5
|
+
* exposes typed helpers for regular responses, server-sent event streaming, and
|
|
6
|
+
* embedding requests.
|
|
7
|
+
*
|
|
8
|
+
* **Common tasks**
|
|
9
|
+
*
|
|
10
|
+
* - Create a client service directly with {@link make}
|
|
11
|
+
* - Provide the service as a layer with {@link layer} or {@link layerConfig}
|
|
12
|
+
* - Send non-streaming chat completion requests with `createResponse`
|
|
13
|
+
* - Send streaming chat completion requests with `createResponseStream`
|
|
14
|
+
* - Generate embeddings with `createEmbedding`
|
|
15
|
+
* - Reuse the exported request and response types when integrating compatible providers
|
|
16
|
+
*
|
|
17
|
+
* **Gotchas**
|
|
18
|
+
*
|
|
19
|
+
* - The default base URL is `https://api.openai.com/v1`; set `apiUrl` for other
|
|
20
|
+
* OpenAI-compatible providers.
|
|
21
|
+
* - `createResponseStream` forces `stream: true` and requests usage events with
|
|
22
|
+
* `stream_options.include_usage`.
|
|
23
|
+
* - HTTP and schema decoding failures are mapped into `AiError`.
|
|
24
|
+
*
|
|
25
|
+
* @since 4.0.0
|
|
3
26
|
*/
|
|
4
27
|
import * as Array from "effect/Array";
|
|
28
|
+
import * as Context from "effect/Context";
|
|
5
29
|
import * as Effect from "effect/Effect";
|
|
6
30
|
import { identity, pipe } from "effect/Function";
|
|
7
31
|
import * as Layer from "effect/Layer";
|
|
8
32
|
import * as Redacted from "effect/Redacted";
|
|
9
33
|
import * as Schema from "effect/Schema";
|
|
10
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
11
34
|
import * as Stream from "effect/Stream";
|
|
12
35
|
import * as Sse from "effect/unstable/encoding/Sse";
|
|
13
36
|
import * as Headers from "effect/unstable/http/Headers";
|
|
@@ -17,17 +40,56 @@ import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
|
|
|
17
40
|
import * as Errors from "./internal/errors.js";
|
|
18
41
|
import { OpenAiConfig } from "./OpenAiConfig.js";
|
|
19
42
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
43
|
+
* Context service tag for the OpenAI-compatible chat completions and embeddings client.
|
|
44
|
+
*
|
|
45
|
+
* **When to use**
|
|
46
|
+
*
|
|
47
|
+
* Use when building effects that depend on the low-level OpenAI-compatible
|
|
48
|
+
* client through context rather than receiving the client as a value.
|
|
49
|
+
*
|
|
50
|
+
* **Details**
|
|
51
|
+
*
|
|
52
|
+
* The tagged service is the `Service` interface produced by `make` and provided
|
|
53
|
+
* by `layer` or `layerConfig`.
|
|
54
|
+
*
|
|
55
|
+
* @see {@link Service} for the operations provided by the service
|
|
56
|
+
* @see {@link make} for constructing the service from explicit options
|
|
57
|
+
* @see {@link layer} for providing the service from explicit options
|
|
58
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
59
|
+
*
|
|
60
|
+
* @category services
|
|
61
|
+
* @since 4.0.0
|
|
22
62
|
*/
|
|
23
|
-
export class OpenAiClient extends /*#__PURE__*/
|
|
63
|
+
export class OpenAiClient extends /*#__PURE__*/Context.Service()("@effect/ai-openai-compat/OpenAiClient") {}
|
|
24
64
|
const RedactedOpenAiHeaders = {
|
|
25
65
|
OpenAiOrganization: "OpenAI-Organization",
|
|
26
66
|
OpenAiProject: "OpenAI-Project"
|
|
27
67
|
};
|
|
28
68
|
/**
|
|
29
|
-
*
|
|
69
|
+
* Constructs an OpenAI-compatible client service from explicit options.
|
|
70
|
+
*
|
|
71
|
+
* **When to use**
|
|
72
|
+
*
|
|
73
|
+
* Use to construct the OpenAI-compatible client service inside an effect when
|
|
74
|
+
* you need the service value directly.
|
|
75
|
+
*
|
|
76
|
+
* **Details**
|
|
77
|
+
*
|
|
78
|
+
* The returned service uses the current `HttpClient`, prepends `apiUrl` or
|
|
79
|
+
* `https://api.openai.com/v1`, adds authentication and OpenAI
|
|
80
|
+
* organization/project headers, accepts JSON responses, and applies
|
|
81
|
+
* `transformClient` when provided.
|
|
82
|
+
*
|
|
83
|
+
* **Gotchas**
|
|
84
|
+
*
|
|
85
|
+
* A scoped `OpenAiConfig.withClientTransform` is applied when request helpers
|
|
86
|
+
* run, after the `transformClient` option supplied to `make`.
|
|
87
|
+
*
|
|
88
|
+
* @see {@link layer} for providing this client from explicit options
|
|
89
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
90
|
+
*
|
|
30
91
|
* @category constructors
|
|
92
|
+
* @since 4.0.0
|
|
31
93
|
*/
|
|
32
94
|
export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
33
95
|
const baseClient = yield* HttpClient.HttpClient;
|
|
@@ -68,13 +130,40 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
68
130
|
});
|
|
69
131
|
}, /*#__PURE__*/Effect.updateService(Headers.CurrentRedactedNames, /*#__PURE__*/Array.appendAll(/*#__PURE__*/Object.values(RedactedOpenAiHeaders))));
|
|
70
132
|
/**
|
|
71
|
-
*
|
|
133
|
+
* Creates a layer that provides an OpenAI-compatible client from explicit options.
|
|
134
|
+
*
|
|
135
|
+
* **When to use**
|
|
136
|
+
*
|
|
137
|
+
* Use to install `OpenAiClient` in an application layer when the client options
|
|
138
|
+
* are already available as values rather than loaded from `Config`.
|
|
139
|
+
*
|
|
140
|
+
* @see {@link make} for constructing the client service effectfully
|
|
141
|
+
* @see {@link layerConfig} for loading client settings from `Config`
|
|
142
|
+
*
|
|
72
143
|
* @category layers
|
|
144
|
+
* @since 4.0.0
|
|
73
145
|
*/
|
|
74
146
|
export const layer = options => Layer.effect(OpenAiClient, make(options));
|
|
75
147
|
/**
|
|
76
|
-
*
|
|
148
|
+
* Creates a layer that loads OpenAI-compatible client settings from `Config`
|
|
149
|
+
* values before constructing the service.
|
|
150
|
+
*
|
|
151
|
+
* **When to use**
|
|
152
|
+
*
|
|
153
|
+
* Use when OpenAI-compatible client settings should be read from Effect
|
|
154
|
+
* `Config` values while providing `OpenAiClient` as a layer.
|
|
155
|
+
*
|
|
156
|
+
* **Details**
|
|
157
|
+
*
|
|
158
|
+
* Only config values supplied in `options` are loaded. Omitted fields are
|
|
159
|
+
* passed to `make` as `undefined`, and `transformClient` is forwarded as a
|
|
160
|
+
* plain option.
|
|
161
|
+
*
|
|
162
|
+
* @see {@link make} for constructing the client service effectfully
|
|
163
|
+
* @see {@link layer} for providing the client from already-resolved options
|
|
164
|
+
*
|
|
77
165
|
* @category layers
|
|
166
|
+
* @since 4.0.0
|
|
78
167
|
*/
|
|
79
168
|
export const layerConfig = options => Layer.effect(OpenAiClient, Effect.gen(function* () {
|
|
80
169
|
const apiKey = options?.apiKey !== undefined ? yield* options.apiKey : undefined;
|
|
@@ -107,12 +196,22 @@ const ChatCompletionToolFunction = /*#__PURE__*/Schema.Struct({
|
|
|
107
196
|
name: Schema.String,
|
|
108
197
|
arguments: /*#__PURE__*/Schema.optionalKey(Schema.String)
|
|
109
198
|
});
|
|
199
|
+
const ChatCompletionToolFunctionDelta = /*#__PURE__*/Schema.Struct({
|
|
200
|
+
name: /*#__PURE__*/Schema.optionalKey(Schema.String),
|
|
201
|
+
arguments: /*#__PURE__*/Schema.optionalKey(Schema.String)
|
|
202
|
+
});
|
|
110
203
|
const ChatCompletionToolCall = /*#__PURE__*/Schema.Struct({
|
|
111
204
|
id: /*#__PURE__*/Schema.optionalKey(Schema.String),
|
|
112
205
|
index: /*#__PURE__*/Schema.optionalKey(Schema.Number),
|
|
113
206
|
type: /*#__PURE__*/Schema.optionalKey(Schema.String),
|
|
114
207
|
function: /*#__PURE__*/Schema.optionalKey(ChatCompletionToolFunction)
|
|
115
208
|
});
|
|
209
|
+
const ChatCompletionToolCallDelta = /*#__PURE__*/Schema.Struct({
|
|
210
|
+
id: /*#__PURE__*/Schema.optionalKey(Schema.String),
|
|
211
|
+
index: /*#__PURE__*/Schema.optionalKey(Schema.Number),
|
|
212
|
+
type: /*#__PURE__*/Schema.optionalKey(Schema.String),
|
|
213
|
+
function: /*#__PURE__*/Schema.optionalKey(ChatCompletionToolFunctionDelta)
|
|
214
|
+
});
|
|
116
215
|
const ChatCompletionMessage = /*#__PURE__*/Schema.Struct({
|
|
117
216
|
role: /*#__PURE__*/Schema.optionalKey(Schema.String),
|
|
118
217
|
content: /*#__PURE__*/Schema.optionalKey(/*#__PURE__*/Schema.NullOr(Schema.String)),
|
|
@@ -121,7 +220,7 @@ const ChatCompletionMessage = /*#__PURE__*/Schema.Struct({
|
|
|
121
220
|
const ChatCompletionDelta = /*#__PURE__*/Schema.Struct({
|
|
122
221
|
role: /*#__PURE__*/Schema.optionalKey(Schema.String),
|
|
123
222
|
content: /*#__PURE__*/Schema.optionalKey(/*#__PURE__*/Schema.NullOr(Schema.String)),
|
|
124
|
-
tool_calls: /*#__PURE__*/Schema.optionalKey(/*#__PURE__*/Schema.Array(
|
|
223
|
+
tool_calls: /*#__PURE__*/Schema.optionalKey(/*#__PURE__*/Schema.Array(ChatCompletionToolCallDelta))
|
|
125
224
|
});
|
|
126
225
|
const ChatCompletionChoice = /*#__PURE__*/Schema.Struct({
|
|
127
226
|
index: Schema.Number,
|
package/dist/OpenAiClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiClient.js","names":["Array","Effect","identity","pipe","Layer","Redacted","Schema","ServiceMap","Stream","Sse","Headers","HttpClient","HttpClientRequest","HttpClientResponse","Errors","OpenAiConfig","OpenAiClient","Service","RedactedOpenAiHeaders","OpenAiOrganization","OpenAiProject","make","fnUntraced","options","baseClient","httpClient","mapRequest","request","prependUrl","apiUrl","apiKey","undefined","bearerToken","value","organizationId","setHeader","projectId","acceptJson","transformClient","resolveHttpClient","map","getOrUndefined","config","decodeResponse","schemaBodyJson","ChatCompletionResponse","createResponse","payload","flatMap","client","post","bodyJsonUnsafe","filterStatusOk","execute","response","body","catchTags","HttpClientError","error","mapHttpClientError","SchemaError","fail","mapSchemaError","buildResponseStream","stream","decodeText","pipeThroughChannel","decode","event","data","decodeChatCompletionSseData","fromIterable","takeUntil","Retry","die","fromEffect","createResponseStream","stream_options","include_usage","catchTag","decodeEmbedding","CreateEmbeddingResponseSchema","createEmbedding","of","updateService","CurrentRedactedNames","appendAll","Object","values","layer","effect","layerConfig","gen","EmbeddingSchema","Struct","embedding","Union","Number","String","index","object","optionalKey","model","Literal","usage","prompt_tokens","total_tokens","ChatCompletionToolFunction","name","arguments","ChatCompletionToolCall","id","type","function","ChatCompletionMessage","role","content","NullOr","tool_calls","ChatCompletionDelta","ChatCompletionChoice","finish_reason","message","delta","ChatCompletionUsage","completion_tokens","prompt_tokens_details","Any","completion_tokens_details","created","choices","service_tier","ChatCompletionChunk","parseJson","JSON","parse","isChatCompletionChunk","is","parsed"],"sources":["../src/OpenAiClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,QAAQ,EAAEC,IAAI,QAAQ,iBAAiB;AAChD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,GAAG,MAAM,8BAA8B;AACnD,OAAO,KAAKC,OAAO,MAAM,8BAA8B;AACvD,OAAO,KAAKC,UAAU,MAAM,iCAAiC;AAC7D,OAAO,KAAKC,iBAAiB,MAAM,wCAAwC;AAC3E,OAAO,KAAKC,kBAAkB,MAAM,yCAAyC;AAC7E,OAAO,KAAKC,MAAM,MAAM,sBAAsB;AAC9C,SAASC,YAAY,QAAQ,mBAAmB;AA4BhD;;;;AAIA,OAAM,MAAOC,YAAa,sBAAQT,UAAU,CAACU,OAAO,EAAyB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AAE7H,MAAM,CAAC+F,WAAW,CAAC/F,MAAM,CAAC4F,MAAM;CAC/C,CAAC;AA+BF,MAAMmC,SAAS,GAAIpG,KAAa,IAAa;EAC3C,IAAI;IACF,OAAOqG,IAAI,CAACC,KAAK,CAACtG,KAAK,CAAC;EAC1B,CAAC,CAAC,MAAM;IACN,OAAOF,SAAS;EAClB;AACF,CAAC;AAED,MAAMyG,qBAAqB,gBAAGlI,MAAM,CAACmI,EAAE,CAACL,mBAAmB,CAAC;AAE5D,MAAM9D,2BAA2B,GAC/BD,IAAY,IAC6B;EACzC,IAAIA,IAAI,KAAK,QAAQ,EAAE;IACrB,OAAOA,IAAI;EACb;EACA,MAAMqE,MAAM,GAAGL,SAAS,CAAChE,IAAI,CAAC;EAC9B,OAAOmE,qBAAqB,CAACE,MAAM,CAAC,GAChCA,MAAM,GACN3G,SAAS;AACf,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"OpenAiClient.js","names":["Array","Context","Effect","identity","pipe","Layer","Redacted","Schema","Stream","Sse","Headers","HttpClient","HttpClientRequest","HttpClientResponse","Errors","OpenAiConfig","OpenAiClient","Service","RedactedOpenAiHeaders","OpenAiOrganization","OpenAiProject","make","fnUntraced","options","baseClient","httpClient","mapRequest","request","prependUrl","apiUrl","apiKey","undefined","bearerToken","value","organizationId","setHeader","projectId","acceptJson","transformClient","resolveHttpClient","map","getOrUndefined","config","decodeResponse","schemaBodyJson","ChatCompletionResponse","createResponse","payload","flatMap","client","post","bodyJsonUnsafe","filterStatusOk","execute","response","body","catchTags","HttpClientError","error","mapHttpClientError","SchemaError","fail","mapSchemaError","buildResponseStream","stream","decodeText","pipeThroughChannel","decode","event","data","decodeChatCompletionSseData","fromIterable","takeUntil","Retry","die","fromEffect","createResponseStream","stream_options","include_usage","catchTag","decodeEmbedding","CreateEmbeddingResponseSchema","createEmbedding","of","updateService","CurrentRedactedNames","appendAll","Object","values","layer","effect","layerConfig","gen","EmbeddingSchema","Struct","embedding","Union","Number","String","index","object","optionalKey","model","Literal","usage","prompt_tokens","total_tokens","ChatCompletionToolFunction","name","arguments","ChatCompletionToolFunctionDelta","ChatCompletionToolCall","id","type","function","ChatCompletionToolCallDelta","ChatCompletionMessage","role","content","NullOr","tool_calls","ChatCompletionDelta","ChatCompletionChoice","finish_reason","message","delta","ChatCompletionUsage","completion_tokens","prompt_tokens_details","Any","completion_tokens_details","created","choices","service_tier","ChatCompletionChunk","parseJson","JSON","parse","isChatCompletionChunk","is","parsed"],"sources":["../src/OpenAiClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,OAAO,KAAKA,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,QAAQ,EAAEC,IAAI,QAAQ,iBAAiB;AAChD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,GAAG,MAAM,8BAA8B;AACnD,OAAO,KAAKC,OAAO,MAAM,8BAA8B;AACvD,OAAO,KAAKC,UAAU,MAAM,iCAAiC;AAC7D,OAAO,KAAKC,iBAAiB,MAAM,wCAAwC;AAC3E,OAAO,KAAKC,kBAAkB,MAAM,yCAAyC;AAC7E,OAAO,KAAKC,MAAM,MAAM,sBAAsB;AAC9C,SAASC,YAAY,QAAQ,mBAAmB;AAoChD;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAM,MAAOC,YAAa,sBAAQf,OAAO,CAACgB,OAAO,EAAyB,CACxE,uCAAuC,CACxC;AAgBD,MAAMC,qBAAqB,GAAG;EAC5BC,kBAAkB,EAAE,qBAAqB;EACzCC,aAAa,EAAE;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,OAAO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MAAM,CAACO,mBAAmB,CAAC,CAAC;EAC7DO,YAAY,eAAE9H,MAAM,CAAC8F,WAAW,CAAC9F,MAAM,CAAC2F,MAAM;CAC/C,CAAC;AAEF,MAAMoC,mBAAmB,gBAAG/H,MAAM,CAACuF,MAAM,CAAC;EACxCkB,EAAE,EAAEzG,MAAM,CAAC2F,MAAM;EACjBI,KAAK,EAAE/F,MAAM,CAAC2F,MAAM;EACpBiC,OAAO,EAAE5H,MAAM,CAAC0F,MAAM;EACtBmC,OAAO,eAAE7H,MAAM,CAACP,KAAK,CAAC0H,oBAAoB,CAAC;EAC3ClB,KAAK,eAAEjG,MAAM,CAAC8F,WAAW,cAAC9F,MAAM,CAACgH,MAAM,CAACO,mBAAmB,CAAC,CAAC;EAC7DO,YAAY,eAAE9H,MAAM,CAAC8F,WAAW,CAAC9F,MAAM,CAAC2F,MAAM;CAC/C,CAAC;AAqDF,MAAMqC,SAAS,GAAItG,KAAa,IAAa;EAC3C,IAAI;IACF,OAAOuG,IAAI,CAACC,KAAK,CAACxG,KAAK,CAAC;EAC1B,CAAC,CAAC,MAAM;IACN,OAAOF,SAAS;EAClB;AACF,CAAC;AAED,MAAM2G,qBAAqB,gBAAGnI,MAAM,CAACoI,EAAE,CAACL,mBAAmB,CAAC;AAE5D,MAAMhE,2BAA2B,GAC/BD,IAAY,IAC6B;EACzC,IAAIA,IAAI,KAAK,QAAQ,EAAE;IACrB,OAAOA,IAAI;EACb;EACA,MAAMuE,MAAM,GAAGL,SAAS,CAAClE,IAAI,CAAC;EAC9B,OAAOqE,qBAAqB,CAACE,MAAM,CAAC,GAChCA,MAAM,GACN7G,SAAS;AACf,CAAC","ignoreList":[]}
|
package/dist/OpenAiConfig.d.ts
CHANGED
|
@@ -1,45 +1,118 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `OpenAiConfig` module provides shared configuration for clients that
|
|
3
|
+
* talk to OpenAI-compatible APIs. It is used to customize the HTTP client
|
|
4
|
+
* wiring around a provider without changing the higher-level model,
|
|
5
|
+
* embeddings, or tool-calling APIs that consume the client.
|
|
6
|
+
*
|
|
7
|
+
* **Common tasks**
|
|
8
|
+
*
|
|
9
|
+
* - Install a client transform with {@link withClientTransform}
|
|
10
|
+
* - Add provider-specific HTTP behavior, such as headers, retries, proxies, or
|
|
11
|
+
* instrumentation
|
|
12
|
+
* - Read the active configuration from the Effect context when implementing
|
|
13
|
+
* OpenAI-compatible integrations
|
|
14
|
+
*
|
|
15
|
+
* **Gotchas**
|
|
16
|
+
*
|
|
17
|
+
* - The transform receives and returns an `HttpClient`, so it should preserve
|
|
18
|
+
* the existing client behavior unless it intentionally replaces it
|
|
19
|
+
* - Configuration is provided through Effect context and is scoped to the
|
|
20
|
+
* effect that receives the service
|
|
21
|
+
*
|
|
22
|
+
* @since 4.0.0
|
|
3
23
|
*/
|
|
24
|
+
import * as Context from "effect/Context";
|
|
4
25
|
import * as Effect from "effect/Effect";
|
|
5
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
6
26
|
import type { HttpClient } from "effect/unstable/http/HttpClient";
|
|
7
|
-
declare const OpenAiConfig_base:
|
|
27
|
+
declare const OpenAiConfig_base: Context.ServiceClass<OpenAiConfig, "@effect/ai-openai-compat/OpenAiConfig", OpenAiConfig.Service>;
|
|
8
28
|
/**
|
|
9
|
-
*
|
|
29
|
+
* Context service used to carry OpenAI-compatible client configuration for the
|
|
30
|
+
* current Effect scope.
|
|
31
|
+
*
|
|
32
|
+
* **When to use**
|
|
33
|
+
*
|
|
34
|
+
* Use as the context service for OpenAI-compatible client configuration when you
|
|
35
|
+
* need to provide or read scoped HTTP client transforms through Effect context.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
38
|
+
*
|
|
10
39
|
* @category services
|
|
40
|
+
* @since 4.0.0
|
|
11
41
|
*/
|
|
12
42
|
export declare class OpenAiConfig extends OpenAiConfig_base {
|
|
13
43
|
/**
|
|
14
|
-
*
|
|
44
|
+
* Gets the configured OpenAI-compatible service from the current context when present.
|
|
45
|
+
*
|
|
46
|
+
* @since 4.0.0
|
|
15
47
|
*/
|
|
16
48
|
static readonly getOrUndefined: Effect.Effect<typeof OpenAiConfig.Service | undefined>;
|
|
17
49
|
}
|
|
18
50
|
/**
|
|
19
|
-
*
|
|
51
|
+
* Types associated with the `OpenAiConfig` context service.
|
|
52
|
+
*
|
|
53
|
+
* @since 4.0.0
|
|
20
54
|
*/
|
|
21
55
|
export declare namespace OpenAiConfig {
|
|
22
56
|
/**
|
|
23
|
-
*
|
|
57
|
+
* Configuration consumed by OpenAI-compatible clients when they build or
|
|
58
|
+
* resolve the underlying HTTP client.
|
|
59
|
+
*
|
|
24
60
|
* @category models
|
|
61
|
+
* @since 4.0.0
|
|
25
62
|
*/
|
|
26
63
|
interface Service {
|
|
27
64
|
readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined;
|
|
28
65
|
}
|
|
29
66
|
}
|
|
30
67
|
/**
|
|
31
|
-
*
|
|
68
|
+
* Provides an HTTP client transform for the supplied effect.
|
|
69
|
+
*
|
|
70
|
+
* **When to use**
|
|
71
|
+
*
|
|
72
|
+
* Use to add provider-specific OpenAI-compatible HTTP behavior, such as
|
|
73
|
+
* headers, retries, instrumentation, or proxy routing.
|
|
74
|
+
*
|
|
75
|
+
* **Details**
|
|
76
|
+
*
|
|
77
|
+
* OpenAI-compatible provider services read the transform from the
|
|
78
|
+
* `OpenAiConfig` context.
|
|
79
|
+
*
|
|
32
80
|
* @category configuration
|
|
81
|
+
* @since 4.0.0
|
|
33
82
|
*/
|
|
34
83
|
export declare const withClientTransform: {
|
|
35
84
|
/**
|
|
36
|
-
*
|
|
85
|
+
* Provides an HTTP client transform for the supplied effect.
|
|
86
|
+
*
|
|
87
|
+
* **When to use**
|
|
88
|
+
*
|
|
89
|
+
* Use to add provider-specific OpenAI-compatible HTTP behavior, such as
|
|
90
|
+
* headers, retries, instrumentation, or proxy routing.
|
|
91
|
+
*
|
|
92
|
+
* **Details**
|
|
93
|
+
*
|
|
94
|
+
* OpenAI-compatible provider services read the transform from the
|
|
95
|
+
* `OpenAiConfig` context.
|
|
96
|
+
*
|
|
37
97
|
* @category configuration
|
|
98
|
+
* @since 4.0.0
|
|
38
99
|
*/
|
|
39
100
|
(transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
40
101
|
/**
|
|
41
|
-
*
|
|
102
|
+
* Provides an HTTP client transform for the supplied effect.
|
|
103
|
+
*
|
|
104
|
+
* **When to use**
|
|
105
|
+
*
|
|
106
|
+
* Use to add provider-specific OpenAI-compatible HTTP behavior, such as
|
|
107
|
+
* headers, retries, instrumentation, or proxy routing.
|
|
108
|
+
*
|
|
109
|
+
* **Details**
|
|
110
|
+
*
|
|
111
|
+
* OpenAI-compatible provider services read the transform from the
|
|
112
|
+
* `OpenAiConfig` context.
|
|
113
|
+
*
|
|
42
114
|
* @category configuration
|
|
115
|
+
* @since 4.0.0
|
|
43
116
|
*/
|
|
44
117
|
<A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>;
|
|
45
118
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiConfig.d.ts","sourceRoot":"","sources":["../src/OpenAiConfig.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"OpenAiConfig.d.ts","sourceRoot":"","sources":["../src/OpenAiConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;;AAEjE;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAa,SAAQ,iBAGU;IAC1C;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC,CAGrF;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC;;;;;;OAMG;IACH,UAAiB,OAAO;QACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,CAAC,GAAG,SAAS,CAAA;KAC5E;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,EAAE;IAChC;;;;;;;;;;;;;;;OAeG;IACH,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAClH;;;;;;;;;;;;;;;OAeG;IACH,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACN,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5B,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,GAC5C,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;CAQvB,CAAA"}
|
package/dist/OpenAiConfig.js
CHANGED
|
@@ -1,22 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `OpenAiConfig` module provides shared configuration for clients that
|
|
3
|
+
* talk to OpenAI-compatible APIs. It is used to customize the HTTP client
|
|
4
|
+
* wiring around a provider without changing the higher-level model,
|
|
5
|
+
* embeddings, or tool-calling APIs that consume the client.
|
|
6
|
+
*
|
|
7
|
+
* **Common tasks**
|
|
8
|
+
*
|
|
9
|
+
* - Install a client transform with {@link withClientTransform}
|
|
10
|
+
* - Add provider-specific HTTP behavior, such as headers, retries, proxies, or
|
|
11
|
+
* instrumentation
|
|
12
|
+
* - Read the active configuration from the Effect context when implementing
|
|
13
|
+
* OpenAI-compatible integrations
|
|
14
|
+
*
|
|
15
|
+
* **Gotchas**
|
|
16
|
+
*
|
|
17
|
+
* - The transform receives and returns an `HttpClient`, so it should preserve
|
|
18
|
+
* the existing client behavior unless it intentionally replaces it
|
|
19
|
+
* - Configuration is provided through Effect context and is scoped to the
|
|
20
|
+
* effect that receives the service
|
|
21
|
+
*
|
|
22
|
+
* @since 4.0.0
|
|
3
23
|
*/
|
|
24
|
+
import * as Context from "effect/Context";
|
|
4
25
|
import * as Effect from "effect/Effect";
|
|
5
26
|
import { dual } from "effect/Function";
|
|
6
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
7
27
|
/**
|
|
8
|
-
*
|
|
28
|
+
* Context service used to carry OpenAI-compatible client configuration for the
|
|
29
|
+
* current Effect scope.
|
|
30
|
+
*
|
|
31
|
+
* **When to use**
|
|
32
|
+
*
|
|
33
|
+
* Use as the context service for OpenAI-compatible client configuration when you
|
|
34
|
+
* need to provide or read scoped HTTP client transforms through Effect context.
|
|
35
|
+
*
|
|
36
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
37
|
+
*
|
|
9
38
|
* @category services
|
|
39
|
+
* @since 4.0.0
|
|
10
40
|
*/
|
|
11
|
-
export class OpenAiConfig extends /*#__PURE__*/
|
|
41
|
+
export class OpenAiConfig extends /*#__PURE__*/Context.Service()("@effect/ai-openai-compat/OpenAiConfig") {
|
|
12
42
|
/**
|
|
13
|
-
*
|
|
43
|
+
* Gets the configured OpenAI-compatible service from the current context when present.
|
|
44
|
+
*
|
|
45
|
+
* @since 4.0.0
|
|
14
46
|
*/
|
|
15
|
-
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.
|
|
47
|
+
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), context => context.mapUnsafe.get(OpenAiConfig.key));
|
|
16
48
|
}
|
|
17
49
|
/**
|
|
18
|
-
*
|
|
50
|
+
* Provides an HTTP client transform for the supplied effect.
|
|
51
|
+
*
|
|
52
|
+
* **When to use**
|
|
53
|
+
*
|
|
54
|
+
* Use to add provider-specific OpenAI-compatible HTTP behavior, such as
|
|
55
|
+
* headers, retries, instrumentation, or proxy routing.
|
|
56
|
+
*
|
|
57
|
+
* **Details**
|
|
58
|
+
*
|
|
59
|
+
* OpenAI-compatible provider services read the transform from the
|
|
60
|
+
* `OpenAiConfig` context.
|
|
61
|
+
*
|
|
19
62
|
* @category configuration
|
|
63
|
+
* @since 4.0.0
|
|
20
64
|
*/
|
|
21
65
|
export const withClientTransform = /*#__PURE__*/dual(2, (self, transformClient) => Effect.flatMap(OpenAiConfig.getOrUndefined, config => Effect.provideService(self, OpenAiConfig, {
|
|
22
66
|
...config,
|
package/dist/OpenAiConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiConfig.js","names":["
|
|
1
|
+
{"version":3,"file":"OpenAiConfig.js","names":["Context","Effect","dual","OpenAiConfig","Service","getOrUndefined","map","context","mapUnsafe","get","key","withClientTransform","self","transformClient","flatMap","config","provideService"],"sources":["../src/OpenAiConfig.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AAGtC;;;;;;;;;;;;;;AAcA,OAAM,MAAOC,YAAa,sBAAQH,OAAO,CAACI,OAAO,EAG9C,CAAC,uCAAuC,CAAC;EAC1C;;;;;EAKA,OAAgBC,cAAc,gBAA2DJ,MAAM,CAACK,GAAG,cACjGL,MAAM,CAACM,OAAO,EAAS,EACtBA,OAAO,IAAKA,OAAO,CAACC,SAAS,CAACC,GAAG,CAACN,YAAY,CAACO,GAAG,CAAC,CACrD;;AAqBH;;;;;;;;;;;;;;;;AAgBA,OAAO,MAAMC,mBAAmB,gBAsC5BT,IAAI,CAAC,CAAC,EAAE,CACVU,IAA4B,EAC5BC,eAAmD,KAEnDZ,MAAM,CAACa,OAAO,CACZX,YAAY,CAACE,cAAc,EAC1BU,MAAM,IAAKd,MAAM,CAACe,cAAc,CAACJ,IAAI,EAAET,YAAY,EAAE;EAAE,GAAGY,MAAM;EAAEF;AAAe,CAAE,CAAC,CACtF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
6
|
+
*
|
|
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`.
|
|
35
|
+
*
|
|
36
|
+
* @since 4.0.0
|
|
37
|
+
*/
|
|
38
|
+
import * as Context from "effect/Context";
|
|
39
|
+
import * as Effect from "effect/Effect";
|
|
40
|
+
import * as Layer from "effect/Layer";
|
|
41
|
+
import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel";
|
|
42
|
+
import * as AiModel from "effect/unstable/ai/Model";
|
|
43
|
+
import { OpenAiClient } from "./OpenAiClient.ts";
|
|
44
|
+
/**
|
|
45
|
+
* A model identifier accepted by an OpenAI-compatible embeddings endpoint.
|
|
46
|
+
*
|
|
47
|
+
* @category models
|
|
48
|
+
* @since 4.0.0
|
|
49
|
+
*/
|
|
50
|
+
export type Model = string;
|
|
51
|
+
declare const Config_base: Context.ServiceClass<Config, "@effect/ai-openai-compat/OpenAiEmbeddingModel/Config", {
|
|
52
|
+
readonly [x: string]: unknown;
|
|
53
|
+
readonly model?: string;
|
|
54
|
+
readonly user?: string | undefined | undefined;
|
|
55
|
+
readonly encoding_format?: "float" | "base64" | undefined | undefined;
|
|
56
|
+
readonly dimensions?: number | undefined | undefined;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Service definition for OpenAI embedding model configuration.
|
|
60
|
+
*
|
|
61
|
+
* **When to use**
|
|
62
|
+
*
|
|
63
|
+
* Use when you need to provide shared default request options for
|
|
64
|
+
* OpenAI-compatible embedding operations through the Effect context, such as
|
|
65
|
+
* `dimensions`, `encoding_format`, or `user`.
|
|
66
|
+
*
|
|
67
|
+
* **Details**
|
|
68
|
+
*
|
|
69
|
+
* The service stores the embedding request payload without `input`. Requests
|
|
70
|
+
* combine the selected model, layer or constructor config, and scoped context
|
|
71
|
+
* config, with scoped context config taking precedence.
|
|
72
|
+
*
|
|
73
|
+
* @see {@link withConfigOverride} for scoping embedding request overrides
|
|
74
|
+
*
|
|
75
|
+
* @category context
|
|
76
|
+
* @since 4.0.0
|
|
77
|
+
*/
|
|
78
|
+
export declare class Config extends Config_base {
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Creates an `AiModel` for an OpenAI-compatible embedding model with its configured vector dimensions.
|
|
82
|
+
*
|
|
83
|
+
* **When to use**
|
|
84
|
+
*
|
|
85
|
+
* Use to provide an OpenAI-compatible `EmbeddingModel` and its `Dimensions`
|
|
86
|
+
* service to an Effect program.
|
|
87
|
+
*
|
|
88
|
+
* @see {@link layer} for providing only the embedding model service
|
|
89
|
+
* @see {@link withConfigOverride} for scoped request configuration overrides
|
|
90
|
+
*
|
|
91
|
+
* @category constructors
|
|
92
|
+
* @since 4.0.0
|
|
93
|
+
*/
|
|
94
|
+
export declare const model: (model: string, options: {
|
|
95
|
+
readonly dimensions: number;
|
|
96
|
+
readonly config?: Omit<typeof Config.Service, "model" | "dimensions">;
|
|
97
|
+
}) => AiModel.Model<"openai", EmbeddingModel.EmbeddingModel | EmbeddingModel.Dimensions, OpenAiClient>;
|
|
98
|
+
/**
|
|
99
|
+
* Creates an OpenAI-compatible embedding model service backed by `OpenAiClient`.
|
|
100
|
+
*
|
|
101
|
+
* **When to use**
|
|
102
|
+
*
|
|
103
|
+
* Use when you need to build or provide an `EmbeddingModel` service directly
|
|
104
|
+
* from an existing `OpenAiClient`.
|
|
105
|
+
*
|
|
106
|
+
* **Details**
|
|
107
|
+
*
|
|
108
|
+
* The service sends embedding requests through `OpenAiClient.createEmbedding`.
|
|
109
|
+
* Request config is merged as the selected model, constructor config, then
|
|
110
|
+
* scoped `Config`, so scoped overrides take precedence. Provider usage
|
|
111
|
+
* `prompt_tokens` is exposed as `usage.inputTokens`.
|
|
112
|
+
*
|
|
113
|
+
* **Gotchas**
|
|
114
|
+
*
|
|
115
|
+
* Provider responses must contain one numeric vector for every requested input
|
|
116
|
+
* with unique, in-range `index` values; otherwise embedding operations fail with
|
|
117
|
+
* `AiError.InvalidOutputError`.
|
|
118
|
+
*
|
|
119
|
+
* @see {@link model} for the higher-level `AiModel` descriptor that also provides `EmbeddingModel.Dimensions`
|
|
120
|
+
* @see {@link layer} for providing the service as a `Layer`
|
|
121
|
+
* @see {@link withConfigOverride} for scoping embedding request overrides
|
|
122
|
+
*
|
|
123
|
+
* @category constructors
|
|
124
|
+
* @since 4.0.0
|
|
125
|
+
*/
|
|
126
|
+
export declare const make: (args_0: {
|
|
127
|
+
readonly model: string;
|
|
128
|
+
readonly config?: Omit<typeof Config.Service, "model"> | undefined;
|
|
129
|
+
}) => Effect.Effect<EmbeddingModel.Service, never, OpenAiClient>;
|
|
130
|
+
/**
|
|
131
|
+
* Creates a layer for an OpenAI-compatible embedding model service.
|
|
132
|
+
*
|
|
133
|
+
* **When to use**
|
|
134
|
+
*
|
|
135
|
+
* Use when composing application layers and you want an OpenAI-compatible
|
|
136
|
+
* embeddings endpoint to satisfy `EmbeddingModel.EmbeddingModel` while
|
|
137
|
+
* supplying `OpenAiClient` from another layer.
|
|
138
|
+
*
|
|
139
|
+
* @see {@link make} for constructing the embedding model service effectfully
|
|
140
|
+
* @see {@link model} for creating an `AiModel` with configured dimensions
|
|
141
|
+
*
|
|
142
|
+
* @category layers
|
|
143
|
+
* @since 4.0.0
|
|
144
|
+
*/
|
|
145
|
+
export declare const layer: (options: {
|
|
146
|
+
readonly model: string;
|
|
147
|
+
readonly config?: Omit<typeof Config.Service, "model"> | undefined;
|
|
148
|
+
}) => Layer.Layer<EmbeddingModel.EmbeddingModel, never, OpenAiClient>;
|
|
149
|
+
/**
|
|
150
|
+
* Provides scoped request config overrides for OpenAI-compatible embedding model operations.
|
|
151
|
+
*
|
|
152
|
+
* **When to use**
|
|
153
|
+
*
|
|
154
|
+
* Use to apply embedding request options to one effect without changing the
|
|
155
|
+
* model's default configuration.
|
|
156
|
+
*
|
|
157
|
+
* **Details**
|
|
158
|
+
*
|
|
159
|
+
* The overrides are merged with any existing `Config` service for the duration
|
|
160
|
+
* of the supplied effect. Fields in `overrides` take precedence over existing
|
|
161
|
+
* config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
|
|
162
|
+
* and `withConfigOverride(effect, overrides)`.
|
|
163
|
+
*
|
|
164
|
+
* @see {@link Config} for available OpenAI-compatible embedding request configuration fields
|
|
165
|
+
*
|
|
166
|
+
* @category configuration
|
|
167
|
+
* @since 4.0.0
|
|
168
|
+
*/
|
|
169
|
+
export declare const withConfigOverride: {
|
|
170
|
+
/**
|
|
171
|
+
* Provides scoped request config overrides for OpenAI-compatible embedding model operations.
|
|
172
|
+
*
|
|
173
|
+
* **When to use**
|
|
174
|
+
*
|
|
175
|
+
* Use to apply embedding request options to one effect without changing the
|
|
176
|
+
* model's default configuration.
|
|
177
|
+
*
|
|
178
|
+
* **Details**
|
|
179
|
+
*
|
|
180
|
+
* The overrides are merged with any existing `Config` service for the duration
|
|
181
|
+
* of the supplied effect. Fields in `overrides` take precedence over existing
|
|
182
|
+
* config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
|
|
183
|
+
* and `withConfigOverride(effect, overrides)`.
|
|
184
|
+
*
|
|
185
|
+
* @see {@link Config} for available OpenAI-compatible embedding request configuration fields
|
|
186
|
+
*
|
|
187
|
+
* @category configuration
|
|
188
|
+
* @since 4.0.0
|
|
189
|
+
*/
|
|
190
|
+
(overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>;
|
|
191
|
+
/**
|
|
192
|
+
* Provides scoped request config overrides for OpenAI-compatible embedding model operations.
|
|
193
|
+
*
|
|
194
|
+
* **When to use**
|
|
195
|
+
*
|
|
196
|
+
* Use to apply embedding request options to one effect without changing the
|
|
197
|
+
* model's default configuration.
|
|
198
|
+
*
|
|
199
|
+
* **Details**
|
|
200
|
+
*
|
|
201
|
+
* The overrides are merged with any existing `Config` service for the duration
|
|
202
|
+
* of the supplied effect. Fields in `overrides` take precedence over existing
|
|
203
|
+
* config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
|
|
204
|
+
* and `withConfigOverride(effect, overrides)`.
|
|
205
|
+
*
|
|
206
|
+
* @see {@link Config} for available OpenAI-compatible embedding request configuration fields
|
|
207
|
+
*
|
|
208
|
+
* @category configuration
|
|
209
|
+
* @since 4.0.0
|
|
210
|
+
*/
|
|
211
|
+
<A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>;
|
|
212
|
+
};
|
|
213
|
+
export {};
|
|
214
|
+
//# sourceMappingURL=OpenAiEmbeddingModel.d.ts.map
|