@effect/ai-openai 4.0.0-beta.8 → 4.0.0-beta.80

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.
Files changed (58) hide show
  1. package/dist/Generated.d.ts +66675 -37672
  2. package/dist/Generated.d.ts.map +1 -1
  3. package/dist/Generated.js +1 -1
  4. package/dist/Generated.js.map +1 -1
  5. package/dist/OpenAiClient.d.ts +170 -29
  6. package/dist/OpenAiClient.d.ts.map +1 -1
  7. package/dist/OpenAiClient.js +321 -46
  8. package/dist/OpenAiClient.js.map +1 -1
  9. package/dist/OpenAiClientGenerated.d.ts +91 -0
  10. package/dist/OpenAiClientGenerated.d.ts.map +1 -0
  11. package/dist/OpenAiClientGenerated.js +84 -0
  12. package/dist/OpenAiClientGenerated.js.map +1 -0
  13. package/dist/OpenAiConfig.d.ts +88 -10
  14. package/dist/OpenAiConfig.d.ts.map +1 -1
  15. package/dist/OpenAiConfig.js +42 -7
  16. package/dist/OpenAiConfig.js.map +1 -1
  17. package/dist/OpenAiEmbeddingModel.d.ts +188 -0
  18. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
  19. package/dist/OpenAiEmbeddingModel.js +194 -0
  20. package/dist/OpenAiEmbeddingModel.js.map +1 -0
  21. package/dist/OpenAiError.d.ts +168 -35
  22. package/dist/OpenAiError.d.ts.map +1 -1
  23. package/dist/OpenAiError.js +1 -1
  24. package/dist/OpenAiLanguageModel.d.ts +357 -63
  25. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  26. package/dist/OpenAiLanguageModel.js +390 -168
  27. package/dist/OpenAiLanguageModel.js.map +1 -1
  28. package/dist/OpenAiSchema.d.ts +2325 -0
  29. package/dist/OpenAiSchema.d.ts.map +1 -0
  30. package/dist/OpenAiSchema.js +811 -0
  31. package/dist/OpenAiSchema.js.map +1 -0
  32. package/dist/OpenAiTelemetry.d.ts +63 -22
  33. package/dist/OpenAiTelemetry.d.ts.map +1 -1
  34. package/dist/OpenAiTelemetry.js +20 -10
  35. package/dist/OpenAiTelemetry.js.map +1 -1
  36. package/dist/OpenAiTool.d.ts +148 -62
  37. package/dist/OpenAiTool.d.ts.map +1 -1
  38. package/dist/OpenAiTool.js +125 -39
  39. package/dist/OpenAiTool.js.map +1 -1
  40. package/dist/index.d.ts +19 -33
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +19 -33
  43. package/dist/index.js.map +1 -1
  44. package/dist/internal/errors.js +4 -4
  45. package/dist/internal/errors.js.map +1 -1
  46. package/package.json +3 -3
  47. package/src/Generated.ts +9717 -4887
  48. package/src/OpenAiClient.ts +499 -98
  49. package/src/OpenAiClientGenerated.ts +202 -0
  50. package/src/OpenAiConfig.ts +89 -11
  51. package/src/OpenAiEmbeddingModel.ts +332 -0
  52. package/src/OpenAiError.ts +170 -35
  53. package/src/OpenAiLanguageModel.ts +776 -169
  54. package/src/OpenAiSchema.ts +1286 -0
  55. package/src/OpenAiTelemetry.ts +69 -28
  56. package/src/OpenAiTool.ts +126 -40
  57. package/src/index.ts +22 -33
  58. package/src/internal/errors.ts +6 -4
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @since 4.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 4.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 4.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 4.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 4.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,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,OAAO,MAAM,8BAA8B;AACvD,OAAO,KAA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,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":[]}
@@ -1,45 +1,123 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `OpenAiConfig` module lets a workflow temporarily customize the HTTP
3
+ * client used by `@effect/ai-openai` request helpers. OpenAI client, language
4
+ * model, and embedding code read this scoped transform when they execute
5
+ * provider calls.
6
+ *
7
+ * @since 4.0.0
3
8
  */
9
+ import * as Context from "effect/Context";
4
10
  import * as Effect from "effect/Effect";
5
- import * as ServiceMap from "effect/ServiceMap";
6
11
  import type { HttpClient } from "effect/unstable/http/HttpClient";
7
- declare const OpenAiConfig_base: ServiceMap.ServiceClass<OpenAiConfig, "@effect/ai-openai/OpenAiConfig", OpenAiConfig.Service>;
12
+ declare const OpenAiConfig_base: Context.ServiceClass<OpenAiConfig, "@effect/ai-openai/OpenAiConfig", OpenAiConfig.Service>;
8
13
  /**
9
- * @since 1.0.0
14
+ * Context service for scoped OpenAI configuration used by provider operations.
15
+ *
16
+ * **When to use**
17
+ *
18
+ * Use to provide scoped OpenAI client configuration, such as an HTTP client
19
+ * transform, to OpenAI provider operations without passing it through each call.
20
+ *
21
+ * @see {@link withClientTransform} for scoping an HTTP client transformation
22
+ *
10
23
  * @category services
24
+ * @since 4.0.0
11
25
  */
12
26
  export declare class OpenAiConfig extends OpenAiConfig_base {
13
27
  /**
14
- * @since 1.0.0
28
+ * Gets the configured OpenAI service from the current context when present.
29
+ *
30
+ * @since 4.0.0
15
31
  */
16
32
  static readonly getOrUndefined: Effect.Effect<typeof OpenAiConfig.Service | undefined>;
17
33
  }
18
34
  /**
19
- * @since 1.0.0
35
+ * Types used by the `OpenAiConfig` context service.
36
+ *
37
+ * @since 4.0.0
20
38
  */
21
39
  export declare namespace OpenAiConfig {
22
40
  /**
23
- * @since 1.0.
41
+ * Configuration values read by OpenAI provider operations when executing
42
+ * requests.
43
+ *
24
44
  * @category models
45
+ * @since 4.0.0
25
46
  */
26
47
  interface Service {
27
48
  readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined;
28
49
  }
29
50
  }
30
51
  /**
31
- * @since 1.0.0
52
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
53
+ * operations.
54
+ *
55
+ * **When to use**
56
+ *
57
+ * Use when you need temporary OpenAI HTTP client customization for a single
58
+ * effect or workflow without rebuilding the client layer.
59
+ *
60
+ * **Details**
61
+ *
62
+ * Supports both data-first and data-last forms. The transform is stored in the
63
+ * scoped `OpenAiConfig` service and read by OpenAI provider operations while
64
+ * running the supplied effect.
65
+ *
66
+ * **Gotchas**
67
+ *
68
+ * If a transform is already present in the scoped config, this helper replaces
69
+ * it. Compose transforms manually when both should apply.
70
+ *
32
71
  * @category configuration
72
+ * @since 4.0.0
33
73
  */
34
74
  export declare const withClientTransform: {
35
75
  /**
36
- * @since 1.0.0
76
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
77
+ * operations.
78
+ *
79
+ * **When to use**
80
+ *
81
+ * Use when you need temporary OpenAI HTTP client customization for a single
82
+ * effect or workflow without rebuilding the client layer.
83
+ *
84
+ * **Details**
85
+ *
86
+ * Supports both data-first and data-last forms. The transform is stored in the
87
+ * scoped `OpenAiConfig` service and read by OpenAI provider operations while
88
+ * running the supplied effect.
89
+ *
90
+ * **Gotchas**
91
+ *
92
+ * If a transform is already present in the scoped config, this helper replaces
93
+ * it. Compose transforms manually when both should apply.
94
+ *
37
95
  * @category configuration
96
+ * @since 4.0.0
38
97
  */
39
98
  (transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
40
99
  /**
41
- * @since 1.0.0
100
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
101
+ * operations.
102
+ *
103
+ * **When to use**
104
+ *
105
+ * Use when you need temporary OpenAI HTTP client customization for a single
106
+ * effect or workflow without rebuilding the client layer.
107
+ *
108
+ * **Details**
109
+ *
110
+ * Supports both data-first and data-last forms. The transform is stored in the
111
+ * scoped `OpenAiConfig` service and read by OpenAI provider operations while
112
+ * running the supplied effect.
113
+ *
114
+ * **Gotchas**
115
+ *
116
+ * If a transform is already present in the scoped config, this helper replaces
117
+ * it. Compose transforms manually when both should apply.
118
+ *
42
119
  * @category configuration
120
+ * @since 4.0.0
43
121
  */
44
122
  <A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>;
45
123
  };
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAiConfig.d.ts","sourceRoot":"","sources":["../src/OpenAiConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;;AAEjE;;;GAGG;AACH,qBAAa,YAAa,SAAQ,iBAGG;IACnC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC,CAGrF;CACF;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC;;;OAGG;IACH,UAAiB,OAAO;QACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,CAAC,GAAG,SAAS,CAAA;KAC5E;CACF;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE;IAChC;;;OAGG;IACH,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,GAAG,CAAC,CAAC,EAAE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AM,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;;;;;;;;;;;;;;;;;;;;;;OAsBG;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"}
@@ -1,22 +1,57 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `OpenAiConfig` module lets a workflow temporarily customize the HTTP
3
+ * client used by `@effect/ai-openai` request helpers. OpenAI client, language
4
+ * model, and embedding code read this scoped transform when they execute
5
+ * provider calls.
6
+ *
7
+ * @since 4.0.0
3
8
  */
9
+ import * as Context from "effect/Context";
4
10
  import * as Effect from "effect/Effect";
5
11
  import { dual } from "effect/Function";
6
- import * as ServiceMap from "effect/ServiceMap";
7
12
  /**
8
- * @since 1.0.0
13
+ * Context service for scoped OpenAI configuration used by provider operations.
14
+ *
15
+ * **When to use**
16
+ *
17
+ * Use to provide scoped OpenAI client configuration, such as an HTTP client
18
+ * transform, to OpenAI provider operations without passing it through each call.
19
+ *
20
+ * @see {@link withClientTransform} for scoping an HTTP client transformation
21
+ *
9
22
  * @category services
23
+ * @since 4.0.0
10
24
  */
11
- export class OpenAiConfig extends /*#__PURE__*/ServiceMap.Service()("@effect/ai-openai/OpenAiConfig") {
25
+ export class OpenAiConfig extends /*#__PURE__*/Context.Service()("@effect/ai-openai/OpenAiConfig") {
12
26
  /**
13
- * @since 1.0.0
27
+ * Gets the configured OpenAI service from the current context when present.
28
+ *
29
+ * @since 4.0.0
14
30
  */
15
- static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.services(), context => context.mapUnsafe.get(OpenAiConfig.key));
31
+ static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), context => context.mapUnsafe.get(OpenAiConfig.key));
16
32
  }
17
33
  /**
18
- * @since 1.0.0
34
+ * Provides a scoped transform for the OpenAI HTTP client used by provider
35
+ * operations.
36
+ *
37
+ * **When to use**
38
+ *
39
+ * Use when you need temporary OpenAI HTTP client customization for a single
40
+ * effect or workflow without rebuilding the client layer.
41
+ *
42
+ * **Details**
43
+ *
44
+ * Supports both data-first and data-last forms. The transform is stored in the
45
+ * scoped `OpenAiConfig` service and read by OpenAI provider operations while
46
+ * running the supplied effect.
47
+ *
48
+ * **Gotchas**
49
+ *
50
+ * If a transform is already present in the scoped config, this helper replaces
51
+ * it. Compose transforms manually when both should apply.
52
+ *
19
53
  * @category configuration
54
+ * @since 4.0.0
20
55
  */
21
56
  export const withClientTransform = /*#__PURE__*/dual(2, (self, transformClient) => Effect.flatMap(OpenAiConfig.getOrUndefined, config => Effect.provideService(self, OpenAiConfig, {
22
57
  ...config,
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAiConfig.js","names":["Effect","dual","ServiceMap","OpenAiConfig","Service","getOrUndefined","map","services","context","mapUnsafe","get","key","withClientTransform","self","transformClient","flatMap","config","provideService"],"sources":["../src/OpenAiConfig.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAG/C;;;;AAIA,OAAM,MAAOC,YAAa,sBAAQD,UAAU,CAACE,OAAO,EAGjD,CAAC,gCAAgC,CAAC;EACnC;;;EAGA,OAAgBC,cAAc,gBAA2DL,MAAM,CAACM,GAAG,cACjGN,MAAM,CAACO,QAAQ,EAAS,EACvBC,OAAO,IAAKA,OAAO,CAACC,SAAS,CAACC,GAAG,CAACP,YAAY,CAACQ,GAAG,CAAC,CACrD;;AAgBH;;;;AAIA,OAAO,MAAMC,mBAAmB,gBAc5BX,IAAI,CAAC,CAAC,EAAE,CACVY,IAA4B,EAC5BC,eAAmD,KAEnDd,MAAM,CAACe,OAAO,CACZZ,YAAY,CAACE,cAAc,EAC1BW,MAAM,IAAKhB,MAAM,CAACiB,cAAc,CAACJ,IAAI,EAAEV,YAAY,EAAE;EAAE,GAAGa,MAAM;EAAEF;AAAe,CAAE,CAAC,CACtF,CAAC","ignoreList":[]}
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;;;;;;;;AAQA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,IAAI,QAAQ,iBAAiB;AAGtC;;;;;;;;;;;;;AAaA,OAAM,MAAOC,YAAa,sBAAQH,OAAO,CAACI,OAAO,EAG9C,CAAC,gCAAgC,CAAC;EACnC;;;;;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;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,MAAMC,mBAAmB,gBAoD5BT,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,188 @@
1
+ /**
2
+ * The `OpenAiEmbeddingModel` module provides the OpenAI implementation of
3
+ * Effect AI's `EmbeddingModel` service. It sends embedding requests through
4
+ * `OpenAiClient`, exposes constructors for layers and `AiModel` values,
5
+ * supports scoped request configuration overrides, and checks that OpenAI
6
+ * returns one numeric vector for each requested input.
7
+ *
8
+ * @since 4.0.0
9
+ */
10
+ import * as Context from "effect/Context";
11
+ import * as Effect from "effect/Effect";
12
+ import * as Layer from "effect/Layer";
13
+ import * as EmbeddingModel from "effect/unstable/ai/EmbeddingModel";
14
+ import * as AiModel from "effect/unstable/ai/Model";
15
+ import { OpenAiClient } from "./OpenAiClient.ts";
16
+ /**
17
+ * Model identifiers supported by OpenAI's embeddings API.
18
+ *
19
+ * @category models
20
+ * @since 4.0.0
21
+ */
22
+ export type Model = "text-embedding-ada-002" | "text-embedding-3-small" | "text-embedding-3-large";
23
+ declare const Config_base: Context.ServiceClass<Config, "@effect/ai-openai/OpenAiEmbeddingModel/Config", {
24
+ readonly [x: string]: unknown;
25
+ readonly encoding_format?: "float" | "base64";
26
+ readonly dimensions?: number;
27
+ readonly user?: string;
28
+ readonly model?: string;
29
+ }>;
30
+ /**
31
+ * Context service for OpenAI embedding model configuration.
32
+ *
33
+ * **When to use**
34
+ *
35
+ * Use when you need scoped OpenAI request defaults or overrides for embedding
36
+ * requests from Effect context.
37
+ *
38
+ * **Details**
39
+ *
40
+ * The service stores the OpenAI create-embedding request payload without
41
+ * `input`, carrying options such as `model`, `dimensions`, `encoding_format`,
42
+ * and `user`.
43
+ *
44
+ * @see {@link withConfigOverride} for scoping embedding request overrides
45
+ *
46
+ * @category services
47
+ * @since 4.0.0
48
+ */
49
+ export declare class Config extends Config_base {
50
+ }
51
+ /**
52
+ * Creates an `AiModel` for an OpenAI embedding model with its configured vector dimensions.
53
+ *
54
+ * **When to use**
55
+ *
56
+ * Use to provide an OpenAI `EmbeddingModel` and its `Dimensions` service to an
57
+ * Effect program.
58
+ *
59
+ * @see {@link layer} for providing only the embedding model service
60
+ * @see {@link withConfigOverride} for scoped request configuration overrides
61
+ *
62
+ * @category constructors
63
+ * @since 4.0.0
64
+ */
65
+ export declare const model: (model: (string & {}) | Model, options: {
66
+ readonly dimensions: number;
67
+ readonly config?: Omit<typeof Config.Service, "model" | "dimensions">;
68
+ }) => AiModel.Model<"openai", EmbeddingModel.EmbeddingModel | EmbeddingModel.Dimensions, OpenAiClient>;
69
+ /**
70
+ * Creates an OpenAI embedding model service.
71
+ *
72
+ * **When to use**
73
+ *
74
+ * Use to construct the `EmbeddingModel.Service` effectfully when
75
+ * `OpenAiClient` is already available in the environment.
76
+ *
77
+ * **Details**
78
+ *
79
+ * The `model` option is sent with each embedding request. Constructor `config`
80
+ * supplies create-embedding request fields other than `model` and `input`, and
81
+ * scoped overrides from `withConfigOverride` are merged last for each request.
82
+ *
83
+ * **Gotchas**
84
+ *
85
+ * The service expects numeric embedding vectors. It fails with
86
+ * `InvalidOutputError` when the provider returns base64 embeddings,
87
+ * out-of-range indexes, duplicate indexes, or an unexpected number of
88
+ * embeddings.
89
+ *
90
+ * @see {@link layer} for providing the embedding model service as a layer
91
+ * @see {@link model} for creating an `AiModel` that also provides dimensions
92
+ * @see {@link withConfigOverride} for scoped request configuration overrides
93
+ *
94
+ * @category constructors
95
+ * @since 4.0.0
96
+ */
97
+ export declare const make: (args_0: {
98
+ readonly model: (string & {}) | Model;
99
+ readonly config?: Omit<typeof Config.Service, "model"> | undefined;
100
+ }) => Effect.Effect<EmbeddingModel.Service, never, OpenAiClient>;
101
+ /**
102
+ * Creates a layer for the OpenAI embedding model.
103
+ *
104
+ * **When to use**
105
+ *
106
+ * Use when composing application layers and you want OpenAI to satisfy
107
+ * `EmbeddingModel.EmbeddingModel` while supplying `OpenAiClient` from another
108
+ * layer.
109
+ *
110
+ * **Gotchas**
111
+ *
112
+ * Use the default floating-point embedding format. The service expects numeric
113
+ * vectors and fails with `InvalidOutputError` if OpenAI returns base64
114
+ * embeddings.
115
+ *
116
+ * @see {@link make} for constructing the embedding model service effectfully
117
+ * @see {@link model} for creating an `AiModel` that also provides embedding dimensions
118
+ *
119
+ * @category layers
120
+ * @since 4.0.0
121
+ */
122
+ export declare const layer: (options: {
123
+ readonly model: (string & {}) | Model;
124
+ readonly config?: Omit<typeof Config.Service, "model"> | undefined;
125
+ }) => Layer.Layer<EmbeddingModel.EmbeddingModel, never, OpenAiClient>;
126
+ /**
127
+ * Provides config overrides for OpenAI embedding model operations.
128
+ *
129
+ * **When to use**
130
+ *
131
+ * Use when you need scoped OpenAI embedding request defaults for a single
132
+ * effect or workflow without rebuilding the embedding model service.
133
+ *
134
+ * **Details**
135
+ *
136
+ * Supports both data-first and data-last forms. Existing scoped config is read
137
+ * first, then the provided overrides are applied so override fields take
138
+ * precedence.
139
+ *
140
+ * @see {@link Config} for the scoped embedding request configuration service
141
+ *
142
+ * @category configuration
143
+ * @since 4.0.0
144
+ */
145
+ export declare const withConfigOverride: {
146
+ /**
147
+ * Provides config overrides for OpenAI embedding model operations.
148
+ *
149
+ * **When to use**
150
+ *
151
+ * Use when you need scoped OpenAI embedding request defaults for a single
152
+ * effect or workflow without rebuilding the embedding model service.
153
+ *
154
+ * **Details**
155
+ *
156
+ * Supports both data-first and data-last forms. Existing scoped config is read
157
+ * first, then the provided overrides are applied so override fields take
158
+ * precedence.
159
+ *
160
+ * @see {@link Config} for the scoped embedding request configuration service
161
+ *
162
+ * @category configuration
163
+ * @since 4.0.0
164
+ */
165
+ (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>;
166
+ /**
167
+ * Provides config overrides for OpenAI embedding model operations.
168
+ *
169
+ * **When to use**
170
+ *
171
+ * Use when you need scoped OpenAI embedding request defaults for a single
172
+ * effect or workflow without rebuilding the embedding model service.
173
+ *
174
+ * **Details**
175
+ *
176
+ * Supports both data-first and data-last forms. Existing scoped config is read
177
+ * first, then the provided overrides are applied so override fields take
178
+ * precedence.
179
+ *
180
+ * @see {@link Config} for the scoped embedding request configuration service
181
+ *
182
+ * @category configuration
183
+ * @since 4.0.0
184
+ */
185
+ <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>;
186
+ };
187
+ export {};
188
+ //# sourceMappingURL=OpenAiEmbeddingModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAiEmbeddingModel.d.ts","sourceRoot":"","sources":["../src/OpenAiEmbeddingModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;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;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG,wBAAwB,GAAG,wBAAwB,GAAG,wBAAwB,CAAA;;;;;;;;AAElG;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,MAAO,SAAQ,WAawB;CAAG;AAEvD;;;;;;;;;;;;;GAaG;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,Y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