Skip to content

OpenAiLanguageModel.ts

The OpenAiLanguageModel module adapts OpenAI-compatible chat completions providers to Effect AI’s LanguageModel service. It builds a model service from a model id, translates prompts, files, tools, structured output schemas, and provider-specific options into OpenAiClient requests, and maps normal or streaming chat completion results back into Effect AI response content and metadata.

Since v4.0.0



Provides scoped config overrides for OpenAI-compatible language model operations.

When to use

Use to override request configuration for a single language model effect without changing the defaults supplied to model, make, or layer.

Details

Existing Config values from the Effect context are merged with overrides, and the override values take precedence.

See

  • Config for the configuration shape

Signature

declare const withConfigOverride: {
(overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
<A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
}

Source

Since v4.0.0

Creates an OpenAI-compatible LanguageModel service from a model identifier and optional request defaults.

When to use

Use to construct an OpenAI-compatible chat-completions language model service backed by OpenAiClient.

Details

The returned effect requires OpenAiClient. Request defaults from the config option are merged with any Config service in the context, with context values taking precedence. The service supports both generateText and streamText.

See

  • layer for providing the service as a Layer
  • model for creating a model descriptor for AiModel.provide

Signature

declare const make: (args_0: {
readonly model: string
readonly config?: Omit<typeof Config.Service, "model"> | undefined
}) => Effect.Effect<LanguageModel.Service, never, OpenAiClient>

Source

Since v4.0.0

Creates an OpenAI-compatible model descriptor that can be provided with Effect.provide.

When to use

Use when you want an OpenAI-compatible language model value that carries provider and model metadata and can be supplied directly to an Effect program.

See

  • layer for creating a LanguageModel.LanguageModel layer directly
  • make for constructing the language model service effectfully

Signature

declare const model: (
model: string,
config?: Omit<typeof Config.Service, "model">
) => AiModel.Model<"openai", LanguageModel.LanguageModel, OpenAiClient>

Source

Since v4.0.0

Context service for OpenAI language model configuration.

When to use

Use as the context service for OpenAI-compatible language model request configuration, especially when a scoped operation should override the defaults supplied to model, make, or layer.

See

  • withConfigOverride for scoping language model request overrides

Signature

declare class Config

Source

Since v4.0.0

Creates a layer for the OpenAI-compatible language model.

When to use

Use when composing application layers and you want OpenAI-compatible APIs to satisfy LanguageModel.LanguageModel while supplying OpenAiClient from another layer.

See

  • make for constructing the language model service effectfully
  • model for creating an AI model descriptor

Signature

declare const layer: (options: {
readonly model: string
readonly config?: Omit<typeof Config.Service, "model"> | undefined
}) => Layer.Layer<LanguageModel.LanguageModel, never, OpenAiClient>

Source

Since v4.0.0