@effect/ai-openai 4.0.0-beta.6 → 4.0.0-beta.60
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/Generated.d.ts +66011 -38686
- package/dist/Generated.d.ts.map +1 -1
- package/dist/Generated.js +1 -1
- package/dist/Generated.js.map +1 -1
- package/dist/OpenAiClient.d.ts +63 -17
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +210 -33
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiClientGenerated.d.ts +91 -0
- package/dist/OpenAiClientGenerated.d.ts.map +1 -0
- package/dist/OpenAiClientGenerated.js +84 -0
- package/dist/OpenAiClientGenerated.js.map +1 -0
- package/dist/OpenAiConfig.d.ts +2 -2
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiConfig.js +3 -3
- package/dist/OpenAiConfig.js.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +85 -0
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
- package/dist/OpenAiEmbeddingModel.js +119 -0
- package/dist/OpenAiEmbeddingModel.js.map +1 -0
- package/dist/OpenAiError.d.ts +22 -32
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.d.ts +43 -49
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +296 -152
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiSchema.d.ts +1920 -0
- package/dist/OpenAiSchema.d.ts.map +1 -0
- package/dist/OpenAiSchema.js +536 -0
- package/dist/OpenAiSchema.js.map +1 -0
- package/dist/OpenAiTool.d.ts +8 -7
- package/dist/OpenAiTool.d.ts.map +1 -1
- package/dist/OpenAiTool.js +2 -1
- package/dist/OpenAiTool.js.map +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -0
- 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/Generated.ts +7416 -4257
- package/src/OpenAiClient.ts +377 -81
- package/src/OpenAiClientGenerated.ts +202 -0
- package/src/OpenAiConfig.ts +3 -3
- package/src/OpenAiEmbeddingModel.ts +203 -0
- package/src/OpenAiError.ts +24 -32
- package/src/OpenAiLanguageModel.ts +420 -144
- package/src/OpenAiSchema.ts +875 -0
- package/src/OpenAiTool.ts +2 -1
- package/src/index.ts +21 -0
- package/src/internal/errors.ts +6 -4
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Array from "effect/Array";
|
|
5
|
+
import * as Context from "effect/Context";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import { identity } from "effect/Function";
|
|
8
|
+
import * as Function from "effect/Function";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
import * as Predicate from "effect/Predicate";
|
|
11
|
+
import * as Redacted from "effect/Redacted";
|
|
12
|
+
import * as Headers from "effect/unstable/http/Headers";
|
|
13
|
+
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
14
|
+
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
|
15
|
+
import * as Generated from "./Generated.js";
|
|
16
|
+
import { OpenAiConfig } from "./OpenAiConfig.js";
|
|
17
|
+
// =============================================================================
|
|
18
|
+
// Service Identifier
|
|
19
|
+
// =============================================================================
|
|
20
|
+
/**
|
|
21
|
+
* Service identifier for the generated OpenAI client.
|
|
22
|
+
*
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
* @category service
|
|
25
|
+
*/
|
|
26
|
+
export class OpenAiClientGenerated extends /*#__PURE__*/Context.Service()("@effect/ai-openai/OpenAiClientGenerated") {}
|
|
27
|
+
const RedactedOpenAiHeaders = {
|
|
28
|
+
OpenAiOrganization: "OpenAI-Organization",
|
|
29
|
+
OpenAiProject: "OpenAI-Project"
|
|
30
|
+
};
|
|
31
|
+
// =============================================================================
|
|
32
|
+
// Constructor
|
|
33
|
+
// =============================================================================
|
|
34
|
+
/**
|
|
35
|
+
* Creates a generated OpenAI client service with the given options.
|
|
36
|
+
*
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
* @category constructors
|
|
39
|
+
*/
|
|
40
|
+
export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
41
|
+
const baseClient = yield* HttpClient.HttpClient;
|
|
42
|
+
const apiUrl = options.apiUrl ?? "https://api.openai.com/v1";
|
|
43
|
+
const httpClient = baseClient.pipe(HttpClient.mapRequest(Function.flow(HttpClientRequest.prependUrl(apiUrl), options.apiKey ? HttpClientRequest.bearerToken(Redacted.value(options.apiKey)) : identity, options.organizationId ? HttpClientRequest.setHeader(RedactedOpenAiHeaders.OpenAiOrganization, Redacted.value(options.organizationId)) : identity, options.projectId ? HttpClientRequest.setHeader(RedactedOpenAiHeaders.OpenAiProject, Redacted.value(options.projectId)) : identity, HttpClientRequest.acceptJson)), options.transformClient ? options.transformClient : identity);
|
|
44
|
+
return Generated.make(httpClient, {
|
|
45
|
+
transformClient: Effect.fnUntraced(function* (client) {
|
|
46
|
+
const config = yield* OpenAiConfig.getOrUndefined;
|
|
47
|
+
if (Predicate.isNotUndefined(config?.transformClient)) {
|
|
48
|
+
return config.transformClient(client);
|
|
49
|
+
}
|
|
50
|
+
return client;
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
}, /*#__PURE__*/Effect.updateService(Headers.CurrentRedactedNames, /*#__PURE__*/Array.appendAll(/*#__PURE__*/Object.values(RedactedOpenAiHeaders))));
|
|
54
|
+
// =============================================================================
|
|
55
|
+
// Layers
|
|
56
|
+
// =============================================================================
|
|
57
|
+
/**
|
|
58
|
+
* Creates a layer for the generated OpenAI client with the given options.
|
|
59
|
+
*
|
|
60
|
+
* @since 1.0.0
|
|
61
|
+
* @category layers
|
|
62
|
+
*/
|
|
63
|
+
export const layer = options => Layer.effect(OpenAiClientGenerated, make(options));
|
|
64
|
+
/**
|
|
65
|
+
* Creates a layer for the generated OpenAI client, loading the requisite
|
|
66
|
+
* configuration via Effect's `Config` module.
|
|
67
|
+
*
|
|
68
|
+
* @since 1.0.0
|
|
69
|
+
* @category layers
|
|
70
|
+
*/
|
|
71
|
+
export const layerConfig = options => Layer.effect(OpenAiClientGenerated, Effect.gen(function* () {
|
|
72
|
+
const apiKey = Predicate.isNotUndefined(options?.apiKey) ? yield* options.apiKey : undefined;
|
|
73
|
+
const apiUrl = Predicate.isNotUndefined(options?.apiUrl) ? yield* options.apiUrl : undefined;
|
|
74
|
+
const organizationId = Predicate.isNotUndefined(options?.organizationId) ? yield* options.organizationId : undefined;
|
|
75
|
+
const projectId = Predicate.isNotUndefined(options?.projectId) ? yield* options.projectId : undefined;
|
|
76
|
+
return yield* make({
|
|
77
|
+
apiKey,
|
|
78
|
+
apiUrl,
|
|
79
|
+
organizationId,
|
|
80
|
+
projectId,
|
|
81
|
+
transformClient: options?.transformClient
|
|
82
|
+
});
|
|
83
|
+
}));
|
|
84
|
+
//# sourceMappingURL=OpenAiClientGenerated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAiClientGenerated.js","names":["Array","Context","Effect","identity","Function","Layer","Predicate","Redacted","Headers","HttpClient","HttpClientRequest","Generated","OpenAiConfig","OpenAiClientGenerated","Service","RedactedOpenAiHeaders","OpenAiOrganization","OpenAiProject","make","fnUntraced","options","baseClient","apiUrl","httpClient","pipe","mapRequest","flow","prependUrl","apiKey","bearerToken","value","organizationId","setHeader","projectId","acceptJson","transformClient","client","config","getOrUndefined","isNotUndefined","updateService","CurrentRedactedNames","appendAll","Object","values","layer","effect","layerConfig","gen","undefined"],"sources":["../src/OpenAiClientGenerated.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,OAAO,MAAM,gB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AAM,GACvBqB,SAAS;EACX,MAAM3B,MAAM,GAAGhB,SAAS,CAACiC,cAAc,CAACnB,OAAO,EAAEE,MAAM,CAAC,GACpD,OAAOF,OAAO,CAACE,MAAM,GACvB2B,SAAS;EACX,MAAMlB,cAAc,GAAGzB,SAAS,CAACiC,cAAc,CAACnB,OAAO,EAAEW,cAAc,CAAC,GACpE,OAAOX,OAAO,CAACW,cAAc,GAC7BkB,SAAS;EACb,MAAMhB,SAAS,GAAG3B,SAAS,CAACiC,cAAc,CAACnB,OAAO,EAAEa,SAAS,CAAC,GAC1D,OAAOb,OAAO,CAACa,SAAS,GAC1BgB,SAAS;EACX,OAAO,OAAO/B,IAAI,CAAC;IACjBU,MAAM;IACNN,MAAM;IACNS,cAAc;IACdE,SAAS;IACTE,eAAe,EAAEf,OAAO,EAAEe;GAC3B,CAAC;AACJ,CAAC,CAAC,CACH","ignoreList":[]}
|
package/dist/OpenAiConfig.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
+
import * as Context from "effect/Context";
|
|
4
5
|
import * as Effect from "effect/Effect";
|
|
5
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
6
6
|
import type { HttpClient } from "effect/unstable/http/HttpClient";
|
|
7
|
-
declare const OpenAiConfig_base:
|
|
7
|
+
declare const OpenAiConfig_base: Context.ServiceClass<OpenAiConfig, "@effect/ai-openai/OpenAiConfig", OpenAiConfig.Service>;
|
|
8
8
|
/**
|
|
9
9
|
* @since 1.0.0
|
|
10
10
|
* @category services
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiConfig.d.ts","sourceRoot":"","sources":["../src/OpenAiConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"OpenAiConfig.d.ts","sourceRoot":"","sources":["../src/OpenAiConfig.ts"],"names":[],"mappings":"AAAA;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|
4
|
+
import * as Context from "effect/Context";
|
|
4
5
|
import * as Effect from "effect/Effect";
|
|
5
6
|
import { dual } from "effect/Function";
|
|
6
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
7
7
|
/**
|
|
8
8
|
* @since 1.0.0
|
|
9
9
|
* @category services
|
|
10
10
|
*/
|
|
11
|
-
export class OpenAiConfig extends /*#__PURE__*/
|
|
11
|
+
export class OpenAiConfig extends /*#__PURE__*/Context.Service()("@effect/ai-openai/OpenAiConfig") {
|
|
12
12
|
/**
|
|
13
13
|
* @since 1.0.0
|
|
14
14
|
*/
|
|
15
|
-
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.
|
|
15
|
+
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), context => context.mapUnsafe.get(OpenAiConfig.key));
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* @since 1.0.0
|
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;;;AAGA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AAGtC;;;;AAIA,OAAM,MAAOC,YAAa,sBAAQH,OAAO,CAACI,OAAO,EAG9C,CAAC,gCAAgC,CAAC;EACnC;;;EAGA,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;;AAgBH;;;;AAIA,OAAO,MAAMC,mBAAmB,gBAc5BT,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,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Embedding Model implementation.
|
|
3
|
+
*
|
|
4
|
+
* Provides an EmbeddingModel implementation for OpenAI's embeddings API.
|
|
5
|
+
*
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
import * as Context from "effect/Context";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Layer from "effect/Layer";
|
|
11
|
+
import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel";
|
|
12
|
+
import * as AiModel from "effect/unstable/ai/Model";
|
|
13
|
+
import { OpenAiClient } from "./OpenAiClient.ts";
|
|
14
|
+
/**
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
* @category models
|
|
17
|
+
*/
|
|
18
|
+
export type Model = "text-embedding-ada-002" | "text-embedding-3-small" | "text-embedding-3-large";
|
|
19
|
+
declare const Config_base: Context.ServiceClass<Config, "@effect/ai-openai/OpenAiEmbeddingModel/Config", {
|
|
20
|
+
readonly [x: string]: unknown;
|
|
21
|
+
readonly encoding_format?: "float" | "base64";
|
|
22
|
+
readonly dimensions?: number;
|
|
23
|
+
readonly user?: string;
|
|
24
|
+
readonly model?: string;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Service definition for OpenAI embedding model configuration.
|
|
28
|
+
*
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
* @category services
|
|
31
|
+
*/
|
|
32
|
+
export declare class Config extends Config_base {
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @since 1.0.0
|
|
36
|
+
* @category constructors
|
|
37
|
+
*/
|
|
38
|
+
export declare const model: (model: (string & {}) | Model, options: {
|
|
39
|
+
readonly dimensions: number;
|
|
40
|
+
readonly config?: Omit<typeof Config.Service, "model" | "dimensions">;
|
|
41
|
+
}) => AiModel.Model<"openai", EmbeddingModel.EmbeddingModel | EmbeddingModel.Dimensions, OpenAiClient>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates an OpenAI embedding model service.
|
|
44
|
+
*
|
|
45
|
+
* @since 1.0.0
|
|
46
|
+
* @category constructors
|
|
47
|
+
*/
|
|
48
|
+
export declare const make: (args_0: {
|
|
49
|
+
readonly model: (string & {}) | Model;
|
|
50
|
+
readonly config?: Omit<typeof Config.Service, "model"> | undefined;
|
|
51
|
+
}) => Effect.Effect<EmbeddingModel.Service, never, OpenAiClient>;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a layer for the OpenAI embedding model.
|
|
54
|
+
*
|
|
55
|
+
* @since 1.0.0
|
|
56
|
+
* @category layers
|
|
57
|
+
*/
|
|
58
|
+
export declare const layer: (options: {
|
|
59
|
+
readonly model: (string & {}) | Model;
|
|
60
|
+
readonly config?: Omit<typeof Config.Service, "model"> | undefined;
|
|
61
|
+
}) => Layer.Layer<EmbeddingModel.EmbeddingModel, never, OpenAiClient>;
|
|
62
|
+
/**
|
|
63
|
+
* Provides config overrides for OpenAI embedding model operations.
|
|
64
|
+
*
|
|
65
|
+
* @since 1.0.0
|
|
66
|
+
* @category configuration
|
|
67
|
+
*/
|
|
68
|
+
export declare const withConfigOverride: {
|
|
69
|
+
/**
|
|
70
|
+
* Provides config overrides for OpenAI embedding model operations.
|
|
71
|
+
*
|
|
72
|
+
* @since 1.0.0
|
|
73
|
+
* @category configuration
|
|
74
|
+
*/
|
|
75
|
+
(overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>;
|
|
76
|
+
/**
|
|
77
|
+
* Provides config overrides for OpenAI embedding model operations.
|
|
78
|
+
*
|
|
79
|
+
* @since 1.0.0
|
|
80
|
+
* @category configuration
|
|
81
|
+
*/
|
|
82
|
+
<A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>;
|
|
83
|
+
};
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=OpenAiEmbeddingModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAiEmbeddingModel.d.ts","sourceRoot":"","sources":["../src/OpenAiEmbeddingModel.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,cAAc,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD;;;GAGG;AACH,MAAM,MAAM,KAAK,GAAG,wBAAwB,GAAG,wBAAwB,GAAG,wBAAwB,CAAA;;;;;;;;AAElG;;;;;GAKG;AACH,qBAAa,MAAO,SAAQ,WAawB;CAAG;AAEvD;;;GAGG;AACH,eAAO,MAAM,KAAK,GAChB,OAAO,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,KAAK,EAC5B,SAAS;IACP,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,CAAC,CAAA;CACtE,KACA,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,cAAc,CAAC,cAAc,GAAG,cAAc,CAAC,UAAU,EAAE,YAAY,CAc/F,CAAA;AAEH;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|
+
* Provides an EmbeddingModel implementation for OpenAI's embeddings API.
|
|
5
|
+
*
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
import * as Context from "effect/Context";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import { dual } from "effect/Function";
|
|
11
|
+
import * as Layer from "effect/Layer";
|
|
12
|
+
import * as AiError from "effect/unstable/ai/AiError";
|
|
13
|
+
import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel";
|
|
14
|
+
import * as AiModel from "effect/unstable/ai/Model";
|
|
15
|
+
import { OpenAiClient } from "./OpenAiClient.js";
|
|
16
|
+
/**
|
|
17
|
+
* Service definition for OpenAI embedding model configuration.
|
|
18
|
+
*
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
* @category services
|
|
21
|
+
*/
|
|
22
|
+
export class Config extends /*#__PURE__*/Context.Service()("@effect/ai-openai/OpenAiEmbeddingModel/Config") {}
|
|
23
|
+
/**
|
|
24
|
+
* @since 1.0.0
|
|
25
|
+
* @category constructors
|
|
26
|
+
*/
|
|
27
|
+
export const model = (model, options) => AiModel.make("openai", model, Layer.merge(layer({
|
|
28
|
+
model,
|
|
29
|
+
config: {
|
|
30
|
+
...options.config,
|
|
31
|
+
dimensions: options.dimensions
|
|
32
|
+
}
|
|
33
|
+
}), Layer.succeed(EmbeddingModel.Dimensions, options.dimensions)));
|
|
34
|
+
/**
|
|
35
|
+
* Creates an OpenAI embedding model service.
|
|
36
|
+
*
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
* @category constructors
|
|
39
|
+
*/
|
|
40
|
+
export const make = /*#__PURE__*/Effect.fnUntraced(function* ({
|
|
41
|
+
model,
|
|
42
|
+
config: providerConfig
|
|
43
|
+
}) {
|
|
44
|
+
const client = yield* OpenAiClient;
|
|
45
|
+
const makeConfig = Effect.gen(function* () {
|
|
46
|
+
const services = yield* Effect.context();
|
|
47
|
+
return {
|
|
48
|
+
model,
|
|
49
|
+
...providerConfig,
|
|
50
|
+
...services.mapUnsafe.get(Config.key)
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
return yield* EmbeddingModel.make({
|
|
54
|
+
embedMany: Effect.fnUntraced(function* ({
|
|
55
|
+
inputs
|
|
56
|
+
}) {
|
|
57
|
+
const config = yield* makeConfig;
|
|
58
|
+
const response = yield* client.createEmbedding({
|
|
59
|
+
...config,
|
|
60
|
+
input: inputs
|
|
61
|
+
});
|
|
62
|
+
return yield* mapProviderResponse(inputs.length, response);
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* Creates a layer for the OpenAI embedding model.
|
|
68
|
+
*
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
* @category layers
|
|
71
|
+
*/
|
|
72
|
+
export const layer = options => Layer.effect(EmbeddingModel.EmbeddingModel, make(options));
|
|
73
|
+
/**
|
|
74
|
+
* Provides config overrides for OpenAI embedding model operations.
|
|
75
|
+
*
|
|
76
|
+
* @since 1.0.0
|
|
77
|
+
* @category configuration
|
|
78
|
+
*/
|
|
79
|
+
export const withConfigOverride = /*#__PURE__*/dual(2, (self, overrides) => Effect.flatMap(Effect.serviceOption(Config), config => Effect.provideService(self, Config, {
|
|
80
|
+
...(config._tag === "Some" ? config.value : {}),
|
|
81
|
+
...overrides
|
|
82
|
+
})));
|
|
83
|
+
const mapProviderResponse = (inputLength, response) => {
|
|
84
|
+
if (response.data.length !== inputLength) {
|
|
85
|
+
return Effect.fail(invalidOutput("Provider returned " + response.data.length + " embeddings but expected " + inputLength));
|
|
86
|
+
}
|
|
87
|
+
const results = new Array(inputLength);
|
|
88
|
+
const seen = new Set();
|
|
89
|
+
for (const entry of response.data) {
|
|
90
|
+
if (!Number.isInteger(entry.index) || entry.index < 0 || entry.index >= inputLength) {
|
|
91
|
+
return Effect.fail(invalidOutput("Provider returned invalid embedding index: " + entry.index));
|
|
92
|
+
}
|
|
93
|
+
if (seen.has(entry.index)) {
|
|
94
|
+
return Effect.fail(invalidOutput("Provider returned duplicate embedding index: " + entry.index));
|
|
95
|
+
}
|
|
96
|
+
if (!Array.isArray(entry.embedding)) {
|
|
97
|
+
return Effect.fail(invalidOutput("Provider returned non-vector embedding at index " + entry.index));
|
|
98
|
+
}
|
|
99
|
+
seen.add(entry.index);
|
|
100
|
+
results[entry.index] = [...entry.embedding];
|
|
101
|
+
}
|
|
102
|
+
if (seen.size !== inputLength) {
|
|
103
|
+
return Effect.fail(invalidOutput("Provider returned embeddings for " + seen.size + " inputs but expected " + inputLength));
|
|
104
|
+
}
|
|
105
|
+
return Effect.succeed({
|
|
106
|
+
results,
|
|
107
|
+
usage: {
|
|
108
|
+
inputTokens: response.usage?.prompt_tokens
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const invalidOutput = description => AiError.make({
|
|
113
|
+
module: "OpenAiEmbeddingModel",
|
|
114
|
+
method: "embedMany",
|
|
115
|
+
reason: new AiError.InvalidOutputError({
|
|
116
|
+
description
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
//# sourceMappingURL=OpenAiEmbeddingModel.js.map
|
|
@@ -0,0 +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;;;;;;;AAOA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAA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M,EAAE,IAAIhE,OAAO,CAACiE,kBAAkB,CAAC;IAAEJ;EAAW,CAAE;CACvD,CAAC","ignoreList":[]}
|
package/dist/OpenAiError.d.ts
CHANGED
|
@@ -54,45 +54,35 @@ export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & {
|
|
|
54
54
|
readonly resetTokens: string | null;
|
|
55
55
|
};
|
|
56
56
|
declare module "effect/unstable/ai/AiError" {
|
|
57
|
-
interface
|
|
58
|
-
readonly
|
|
59
|
-
readonly openai?: OpenAiRateLimitMetadata | null;
|
|
60
|
-
};
|
|
57
|
+
interface RateLimitErrorMetadata {
|
|
58
|
+
readonly openai?: OpenAiRateLimitMetadata | null;
|
|
61
59
|
}
|
|
62
|
-
interface
|
|
63
|
-
readonly
|
|
64
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
65
|
-
};
|
|
60
|
+
interface QuotaExhaustedErrorMetadata {
|
|
61
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
66
62
|
}
|
|
67
|
-
interface
|
|
68
|
-
readonly
|
|
69
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
70
|
-
};
|
|
63
|
+
interface AuthenticationErrorMetadata {
|
|
64
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
71
65
|
}
|
|
72
|
-
interface
|
|
73
|
-
readonly
|
|
74
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
75
|
-
};
|
|
66
|
+
interface ContentPolicyErrorMetadata {
|
|
67
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
76
68
|
}
|
|
77
|
-
interface
|
|
78
|
-
readonly
|
|
79
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
80
|
-
};
|
|
69
|
+
interface InvalidRequestErrorMetadata {
|
|
70
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
81
71
|
}
|
|
82
|
-
interface
|
|
83
|
-
readonly
|
|
84
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
85
|
-
};
|
|
72
|
+
interface InternalProviderErrorMetadata {
|
|
73
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
86
74
|
}
|
|
87
|
-
interface
|
|
88
|
-
readonly
|
|
89
|
-
readonly openai?: OpenAiErrorMetadata | null;
|
|
90
|
-
};
|
|
75
|
+
interface InvalidOutputErrorMetadata {
|
|
76
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
91
77
|
}
|
|
92
|
-
interface
|
|
93
|
-
readonly
|
|
94
|
-
|
|
95
|
-
|
|
78
|
+
interface StructuredOutputErrorMetadata {
|
|
79
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
80
|
+
}
|
|
81
|
+
interface UnsupportedSchemaErrorMetadata {
|
|
82
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
83
|
+
}
|
|
84
|
+
interface UnknownErrorMetadata {
|
|
85
|
+
readonly openai?: OpenAiErrorMetadata | null;
|
|
96
86
|
}
|
|
97
87
|
}
|
|
98
88
|
//# sourceMappingURL=OpenAiError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiError.d.ts","sourceRoot":"","sources":["../src/OpenAiError.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,GAAG;IAC1D;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC;;OAEG;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,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED,UAAiB,2BAA2B;QAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED,UAAiB,6BAA6B;QAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED,UAAiB,0BAA0B;QACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED,UAAiB,6BAA6B;QAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED,UAAiB,8BAA8B;QAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;IAED,UAAiB,oBAAoB;QACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAA;KAC7C;CACF"}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Language Model implementation.
|
|
3
|
+
*
|
|
4
|
+
* Provides a LanguageModel implementation for OpenAI's responses API,
|
|
5
|
+
* supporting text generation, structured output, tool calling, and streaming.
|
|
6
|
+
*
|
|
7
|
+
* @since 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
import * as Context from "effect/Context";
|
|
1
10
|
import * as Effect from "effect/Effect";
|
|
2
11
|
import * as Layer from "effect/Layer";
|
|
3
12
|
import * as Schema from "effect/Schema";
|
|
4
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
5
13
|
import * as LanguageModel from "effect/unstable/ai/LanguageModel";
|
|
6
14
|
import * as AiModel from "effect/unstable/ai/Model";
|
|
7
|
-
import * as Generated from "./Generated.ts";
|
|
8
15
|
import { OpenAiClient } from "./OpenAiClient.ts";
|
|
16
|
+
import type * as OpenAiSchema from "./OpenAiSchema.ts";
|
|
9
17
|
declare const ResponseModelIds: Schema.Literals<readonly ["o1-pro", "o1-pro-2025-03-19", "o3-pro", "o3-pro-2025-06-10", "o3-deep-research", "o3-deep-research-2025-06-26", "o4-mini-deep-research", "o4-mini-deep-research-2025-06-26", "computer-use-preview", "computer-use-preview-2025-03-11", "gpt-5-codex", "gpt-5-pro", "gpt-5-pro-2025-10-06", "gpt-5.1-codex-max"]>;
|
|
10
|
-
declare const SharedModelIds: Schema.Literals<readonly ["gpt-5.2", "gpt-5.2-2025-12-11", "gpt-5.2-chat-latest", "gpt-5.2-pro", "gpt-5.2-pro-2025-12-11", "gpt-5.1", "gpt-5.1-2025-11-13", "gpt-5.1-codex", "gpt-5.1-mini", "gpt-5.1-chat-latest", "gpt-5", "gpt-5-mini", "gpt-5-nano", "gpt-5-2025-08-07", "gpt-5-mini-2025-08-07", "gpt-5-nano-2025-08-07", "gpt-5-chat-latest", "gpt-4.1", "gpt-4.1-mini", "gpt-4.1-nano", "gpt-4.1-2025-04-14", "gpt-4.1-mini-2025-04-14", "gpt-4.1-nano-2025-04-14", "o4-mini", "o4-mini-2025-04-16", "o3", "o3-2025-04-16", "o3-mini", "o3-mini-2025-01-31", "o1", "o1-2024-12-17", "o1-preview", "o1-preview-2024-09-12", "o1-mini", "o1-mini-2024-09-12", "gpt-4o", "gpt-4o-2024-11-20", "gpt-4o-2024-08-06", "gpt-4o-2024-05-13", "gpt-4o-audio-preview", "gpt-4o-audio-preview-2024-10-01", "gpt-4o-audio-preview-2024-12-17", "gpt-4o-audio-preview-2025-06-03", "gpt-4o-mini-audio-preview", "gpt-4o-mini-audio-preview-2024-12-17", "gpt-4o-search-preview", "gpt-4o-mini-search-preview", "gpt-4o-search-preview-2025-03-11", "gpt-4o-mini-search-preview-2025-03-11", "chatgpt-4o-latest", "codex-mini-latest", "gpt-4o-mini", "gpt-4o-mini-2024-07-18", "gpt-4-turbo", "gpt-4-turbo-2024-04-09", "gpt-4-0125-preview", "gpt-4-turbo-preview", "gpt-4-1106-preview", "gpt-4-vision-preview", "gpt-4", "gpt-4-0314", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-1106", "gpt-3.5-turbo-0125", "gpt-3.5-turbo-16k-0613"]>;
|
|
18
|
+
declare const SharedModelIds: Schema.Literals<readonly ["gpt-5.4", "gpt-5.4-mini", "gpt-5.4-nano", "gpt-5.4-mini-2026-03-17", "gpt-5.4-nano-2026-03-17", "gpt-5.3-chat-latest", "gpt-5.2", "gpt-5.2-2025-12-11", "gpt-5.2-chat-latest", "gpt-5.2-pro", "gpt-5.2-pro-2025-12-11", "gpt-5.1", "gpt-5.1-2025-11-13", "gpt-5.1-codex", "gpt-5.1-mini", "gpt-5.1-chat-latest", "gpt-5", "gpt-5-mini", "gpt-5-nano", "gpt-5-2025-08-07", "gpt-5-mini-2025-08-07", "gpt-5-nano-2025-08-07", "gpt-5-chat-latest", "gpt-4.1", "gpt-4.1-mini", "gpt-4.1-nano", "gpt-4.1-2025-04-14", "gpt-4.1-mini-2025-04-14", "gpt-4.1-nano-2025-04-14", "o4-mini", "o4-mini-2025-04-16", "o3", "o3-2025-04-16", "o3-mini", "o3-mini-2025-01-31", "o1", "o1-2024-12-17", "o1-preview", "o1-preview-2024-09-12", "o1-mini", "o1-mini-2024-09-12", "gpt-4o", "gpt-4o-2024-11-20", "gpt-4o-2024-08-06", "gpt-4o-2024-05-13", "gpt-4o-audio-preview", "gpt-4o-audio-preview-2024-10-01", "gpt-4o-audio-preview-2024-12-17", "gpt-4o-audio-preview-2025-06-03", "gpt-4o-mini-audio-preview", "gpt-4o-mini-audio-preview-2024-12-17", "gpt-4o-search-preview", "gpt-4o-mini-search-preview", "gpt-4o-search-preview-2025-03-11", "gpt-4o-mini-search-preview-2025-03-11", "chatgpt-4o-latest", "codex-mini-latest", "gpt-4o-mini", "gpt-4o-mini-2024-07-18", "gpt-4-turbo", "gpt-4-turbo-2024-04-09", "gpt-4-0125-preview", "gpt-4-turbo-preview", "gpt-4-1106-preview", "gpt-4-vision-preview", "gpt-4", "gpt-4-0314", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-1106", "gpt-3.5-turbo-0125", "gpt-3.5-turbo-16k-0613"]>;
|
|
11
19
|
/**
|
|
12
20
|
* @since 1.0.0
|
|
13
21
|
* @category models
|
|
@@ -17,46 +25,32 @@ export type Model = typeof ResponseModelIds.Encoded | typeof SharedModelIds.Enco
|
|
|
17
25
|
* Image detail level for vision requests.
|
|
18
26
|
*/
|
|
19
27
|
type ImageDetail = "auto" | "low" | "high";
|
|
20
|
-
declare const Config_base:
|
|
21
|
-
readonly metadata?: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
readonly
|
|
25
|
-
readonly
|
|
26
|
-
readonly
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
readonly
|
|
32
|
-
readonly
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
readonly service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null;
|
|
38
|
-
readonly include?: readonly ("file_search_call.results" | "web_search_call.results" | "web_search_call.action.sources" | "message.input_image.image_url" | "computer_call_output.output.image_url" | "code_interpreter_call.outputs" | "reasoning.encrypted_content" | "message.output_text.logprobs")[] | null;
|
|
39
|
-
readonly stream_options?: {
|
|
40
|
-
readonly include_obfuscation?: boolean;
|
|
41
|
-
} | null;
|
|
42
|
-
readonly max_output_tokens?: number | null;
|
|
28
|
+
declare const Config_base: Context.ServiceClass<Config, "@effect/ai-openai/OpenAiLanguageModel/Config", {
|
|
29
|
+
readonly metadata?: {
|
|
30
|
+
readonly [x: string]: string;
|
|
31
|
+
} | undefined;
|
|
32
|
+
readonly top_logprobs?: number | undefined;
|
|
33
|
+
readonly user?: string | undefined;
|
|
34
|
+
readonly model?: string | undefined;
|
|
35
|
+
readonly temperature?: number | undefined;
|
|
36
|
+
readonly top_p?: number | undefined;
|
|
37
|
+
readonly background?: boolean | undefined;
|
|
38
|
+
readonly conversation?: string | undefined;
|
|
39
|
+
readonly modalities?: readonly ("text" | "audio")[] | undefined;
|
|
40
|
+
readonly service_tier?: string | undefined;
|
|
41
|
+
readonly seed?: number | undefined;
|
|
42
|
+
readonly include?: readonly ("web_search_call.action.sources" | "message.input_image.image_url" | "code_interpreter_call.outputs" | "reasoning.encrypted_content" | "message.output_text.logprobs")[] | undefined;
|
|
43
|
+
readonly instructions?: string | undefined;
|
|
44
|
+
readonly max_output_tokens?: number | undefined;
|
|
43
45
|
readonly reasoning?: {
|
|
44
|
-
readonly summary?: "auto" | "concise" | "detailed" |
|
|
45
|
-
readonly effort?: "low" | "high" | "none" | "minimal" | "medium" | "xhigh" |
|
|
46
|
-
readonly generate_summary?: "auto" | "concise" | "detailed" |
|
|
47
|
-
} |
|
|
48
|
-
readonly truncation?: "auto" | "disabled" |
|
|
49
|
-
readonly
|
|
50
|
-
readonly
|
|
51
|
-
readonly
|
|
52
|
-
readonly prompt_cache_retention?: "in-memory" | "24h" | null;
|
|
53
|
-
readonly store?: boolean | null;
|
|
54
|
-
readonly previous_response_id?: string | null;
|
|
55
|
-
readonly max_tool_calls?: number | null;
|
|
56
|
-
readonly context_management?: readonly {
|
|
57
|
-
readonly type: string;
|
|
58
|
-
readonly compact_threshold?: number | null;
|
|
59
|
-
}[] | null;
|
|
46
|
+
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
47
|
+
readonly effort?: "low" | "high" | "none" | "minimal" | "medium" | "xhigh" | undefined;
|
|
48
|
+
readonly generate_summary?: "auto" | "concise" | "detailed" | undefined;
|
|
49
|
+
} | undefined;
|
|
50
|
+
readonly truncation?: "auto" | "disabled" | undefined;
|
|
51
|
+
readonly store?: boolean | undefined;
|
|
52
|
+
readonly previous_response_id?: string | undefined;
|
|
53
|
+
readonly max_tool_calls?: number | undefined;
|
|
60
54
|
readonly fileIdPrefixes?: readonly string[] | undefined;
|
|
61
55
|
readonly text?: {
|
|
62
56
|
/**
|
|
@@ -116,7 +110,7 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
116
110
|
/**
|
|
117
111
|
* The status of item.
|
|
118
112
|
*/
|
|
119
|
-
readonly status?: typeof
|
|
113
|
+
readonly status?: typeof OpenAiSchema.MessageStatus.Encoded | null;
|
|
120
114
|
/**
|
|
121
115
|
* The ID of the approval request.
|
|
122
116
|
*/
|
|
@@ -132,7 +126,7 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
132
126
|
/**
|
|
133
127
|
* The status of item.
|
|
134
128
|
*/
|
|
135
|
-
readonly status?: typeof
|
|
129
|
+
readonly status?: typeof OpenAiSchema.MessageStatus.Encoded | null;
|
|
136
130
|
/**
|
|
137
131
|
* The ID of the approval request.
|
|
138
132
|
*/
|
|
@@ -148,11 +142,11 @@ declare module "effect/unstable/ai/Prompt" {
|
|
|
148
142
|
/**
|
|
149
143
|
* The status of item.
|
|
150
144
|
*/
|
|
151
|
-
readonly status?: typeof
|
|
145
|
+
readonly status?: typeof OpenAiSchema.MessageStatus.Encoded | null;
|
|
152
146
|
/**
|
|
153
147
|
* A list of annotations that apply to the output text.
|
|
154
148
|
*/
|
|
155
|
-
readonly annotations?: ReadonlyArray<typeof
|
|
149
|
+
readonly annotations?: ReadonlyArray<typeof OpenAiSchema.Annotation.Encoded> | null;
|
|
156
150
|
} | null;
|
|
157
151
|
}
|
|
158
152
|
}
|
|
@@ -169,11 +163,11 @@ declare module "effect/unstable/ai/Response" {
|
|
|
169
163
|
/**
|
|
170
164
|
* The status of item.
|
|
171
165
|
*/
|
|
172
|
-
readonly status?: typeof
|
|
166
|
+
readonly status?: typeof OpenAiSchema.MessageStatus.Encoded | null;
|
|
173
167
|
/**
|
|
174
168
|
* The text content part annotations.
|
|
175
169
|
*/
|
|
176
|
-
readonly annotations?: ReadonlyArray<typeof
|
|
170
|
+
readonly annotations?: ReadonlyArray<typeof OpenAiSchema.Annotation.Encoded> | null;
|
|
177
171
|
};
|
|
178
172
|
}
|
|
179
173
|
interface TextStartPartMetadata extends ProviderMetadata {
|
|
@@ -184,7 +178,7 @@ declare module "effect/unstable/ai/Response" {
|
|
|
184
178
|
interface TextEndPartMetadata extends ProviderMetadata {
|
|
185
179
|
readonly openai?: {
|
|
186
180
|
readonly itemId?: string | null;
|
|
187
|
-
readonly annotations?: ReadonlyArray<typeof
|
|
181
|
+
readonly annotations?: ReadonlyArray<typeof OpenAiSchema.Annotation.Encoded> | null;
|
|
188
182
|
} | null;
|
|
189
183
|
}
|
|
190
184
|
interface ReasoningPartMetadata extends ProviderMetadata {
|