Skip to content

Commit

Permalink
Support per-request HttpClient transformations in the OpenAI AI int…
Browse files Browse the repository at this point in the history
…egration package (#4418)
  • Loading branch information
IMax153 authored Feb 7, 2025
1 parent b8ff1e6 commit cdc82e4
Show file tree
Hide file tree
Showing 6 changed files with 1,304 additions and 986 deletions.
39 changes: 39 additions & 0 deletions .changeset/cuddly-jobs-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
"@effect/ai-openai": patch
---

Support per-request HTTP client transformations in the OpenAi AI integration package.

For example:

```ts
import { Completions } from "@effect/ai"
import { OpenAiClient, OpenAiCompletions, OpenAiConfig } from "@effect/ai-openai"
import { HttpClient, HttpClientRequest } from "@effect/platform"
import { NodeHttpClient } from "@effect/platform-node"
import { Config, Effect, Layer } from "effect"

const OpenAi = OpenAiClient.layerConfig({
apiKey: Config.redacted("OPENAI_API_KEY")
}).pipe(Layer.provide(NodeHttpClient.layerUndici))

const Gpt4oCompletions = OpenAiCompletions.layer({
model: "gpt-4o"
}).pipe(Layer.provide(OpenAi))

const program = Effect.gen(function*() {
const completions = yield* Completions.Completions

yield* completions.create("Tell me a dad joke").pipe(
// Per-request HTTP client transforms which are only applied if
// the OpenAi provider is in use
OpenAiConfig.withClientTransform(
HttpClient.mapRequest(
HttpClientRequest.setHeader("x-dad-jokes", "are-awesome")
)
)
)
})

program.pipe(Effect.provide(Gpt4oCompletions), Effect.runPromise)
```
2 changes: 1 addition & 1 deletion packages/ai/openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@effect/experimental": "workspace:^",
"@effect/platform": "workspace:^",
"@effect/platform-node": "workspace:^",
"@tim-smart/openapi-gen": "^0.3.2",
"@tim-smart/openapi-gen": "^0.3.3",
"effect": "workspace:^"
},
"dependencies": {
Expand Down
Loading

0 comments on commit cdc82e4

Please sign in to comment.