Skip to content

Commit

Permalink
improve changeset description
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 committed Jan 31, 2025
1 parent 78f0a4b commit 204499c
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion .changeset/angry-llamas-move.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,53 @@
"@effect/ai": patch
---

Support non-identified schemas in `Completions.structured`
Support non-identified schemas in `AiChat.structured` and `Completions.structured`.

Instead of requiring a `Schema` with either an `identifier` or `_tag` property
for AI APIs that allow for returning structured outputs, you can now optionally
pass a `correlationId` to `AiChat.structured` and `Completions.structured` when
you want to either use a simple schema or inline the schema.

Example:

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

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

// Create an embeddings service for the `text-embedding-3-large` model
const Gpt4oCompletions = OpenAiCompletions.layer({
model: "gpt-4o"
}).pipe(Layer.provide(OpenAi))

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

const CalendarEvent = Schema.Struct({
name: Schema.String,
date: Schema.DateFromString,
participants: Schema.Array(Schema.String)
})

yield* completions.structured({
correlationId: "CalendarEvent",
schema: CalendarEvent,
input: String.stripMargin(`
|Extract event information from the following prose:
|
|Alice and Bob are going to a science fair on Friday.
`)
})
})

program.pipe(
Effect.provide(Gpt4oCompletions),
Effect.runPromise
)
```

0 comments on commit 204499c

Please sign in to comment.