github Effect-TS/effect @effect/ai@0.8.2

latest releases: @effect/vitest@0.17.5, @effect/sql@0.28.3, @effect/sql-sqlite-wasm@0.29.3...
13 hours ago

Patch Changes

  • #4378 f5e3b1b Thanks @IMax153! - 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:

    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"
    
    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
    
      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)
  • #4388 fcf3b7c Thanks @IMax153! - Rename correlationId to toolCallId

  • #4389 f089470 Thanks @IMax153! - Add support for GenAI telemetry annotations.

  • #4368 a0c85e6 Thanks @IMax153! - Support creation of embeddings from the AI integration packages.

    For example, the following program will create an OpenAI Embeddings service
    that will aggregate all embedding requests received within a 500 millisecond
    window into a single batch.

    import { Embeddings } from "@effect/ai"
    import { OpenAiClient, OpenAiEmbeddings } from "@effect/ai-openai"
    import { NodeHttpClient } from "@effect/platform-node"
    import { Config, Effect, Layer } 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 TextEmbeddingsLarge = OpenAiEmbeddings.layerDataLoader({
      model: "text-embedding-3-large",
      window: "500 millis",
      maxBatchSize: 2048
    }).pipe(Layer.provide(OpenAi))
    
    // Use the generic `Embeddings` service interface in your program
    const program = Effect.gen(function* () {
      const embeddings = yield* Embeddings.Embeddings
      const result = yield* embeddings.embed("The input to embed")
    })
    
    // Provide the specific implementation to use
    program.pipe(Effect.provide(TextEmbeddingsLarge), Effect.runPromise)
  • Updated dependencies [59b3cfb, 766113c, bb05fb8, 712277f, f269122, 8f6006a, c45b559, 430c846, 7b03057, a9c94c8, 107e6f0, c9175ae, 65c11b9, e386d2f, 9172efb]:

    • @effect/platform@0.75.2
    • effect@3.12.8
    • @effect/experimental@0.39.2

Don't miss a new effect release

NewReleases is sending notifications on new releases.