@effect/ai-openai 0.11.4 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,7 @@ import * as Option from "effect/Option"
20
20
  import * as Redacted from "effect/Redacted"
21
21
  import * as Stream from "effect/Stream"
22
22
  import * as Generated from "./Generated.js"
23
+ import { OpenAiConfig } from "./OpenAiConfig.js"
23
24
 
24
25
  /**
25
26
  * @since 1.0.0
@@ -79,7 +80,12 @@ export const make = (options: {
79
80
  options.transformClient ? options.transformClient : identity
80
81
  )
81
82
  const httpClientOk = HttpClient.filterStatusOk(httpClient)
82
- const client = Generated.make(httpClient)
83
+ const client = Generated.make(httpClient, {
84
+ transformClient: (client) =>
85
+ OpenAiConfig.getOrUndefined.pipe(
86
+ Effect.map((config) => config?.transformClient ? config.transformClient(client) : client)
87
+ )
88
+ })
83
89
  const streamRequest = <A = unknown>(request: HttpClientRequest.HttpClientRequest) =>
84
90
  httpClientOk.execute(request).pipe(
85
91
  Effect.map((r) => r.stream),
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
+ import type { HttpClient } from "@effect/platform/HttpClient"
4
5
  import * as Context from "effect/Context"
5
6
  import * as Effect from "effect/Effect"
7
+ import { dual } from "effect/Function"
6
8
  import type { Simplify } from "effect/Types"
7
9
  import type * as Generated from "./Generated.js"
8
10
 
@@ -12,14 +14,7 @@ import type * as Generated from "./Generated.js"
12
14
  */
13
15
  export class OpenAiConfig extends Context.Tag("@effect/ai-openai/OpenAiConfig")<
14
16
  OpenAiConfig,
15
- Simplify<
16
- Partial<
17
- Omit<
18
- typeof Generated.CreateChatCompletionRequest.Encoded,
19
- "messages" | "tools" | "tool_choice" | "stream" | "stream_options" | "functions"
20
- >
21
- >
22
- >
17
+ OpenAiConfig.Service
23
18
  >() {
24
19
  /**
25
20
  * @since 1.0.0
@@ -29,3 +24,53 @@ export class OpenAiConfig extends Context.Tag("@effect/ai-openai/OpenAiConfig")<
29
24
  (context) => context.unsafeMap.get(OpenAiConfig.key)
30
25
  )
31
26
  }
27
+
28
+ /**
29
+ * @since 1.0.0
30
+ * @category models
31
+ */
32
+ export declare namespace OpenAiConfig {
33
+ /**
34
+ * @since 1.0.0
35
+ * @category models
36
+ */
37
+ export interface Service extends
38
+ Simplify<
39
+ Partial<
40
+ Omit<
41
+ typeof Generated.CreateChatCompletionRequest.Encoded,
42
+ "messages" | "tools" | "tool_choice" | "stream" | "stream_options" | "functions"
43
+ >
44
+ >
45
+ >
46
+ {
47
+ readonly transformClient?: (client: HttpClient) => HttpClient
48
+ }
49
+ }
50
+
51
+ /**
52
+ * @since 1.0.0
53
+ * @category configuration
54
+ */
55
+ export const withClientTransform = dual<
56
+ /**
57
+ * @since 1.0.0
58
+ * @category configuration
59
+ */
60
+ (transform: (client: HttpClient) => HttpClient) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
61
+ /**
62
+ * @since 1.0.0
63
+ * @category configuration
64
+ */
65
+ <A, E, R>(
66
+ self: Effect.Effect<A, E, R>,
67
+ transform: (client: HttpClient) => HttpClient
68
+ ) => Effect.Effect<A, E, R>
69
+ >(
70
+ 2,
71
+ (self, transformClient) =>
72
+ Effect.flatMap(
73
+ OpenAiConfig.getOrUndefined,
74
+ (config) => Effect.provideService(self, OpenAiConfig, { ...config, transformClient })
75
+ )
76
+ )