import type * as bedrock from "@distilled.cloud/aws/bedrock-runtime"; import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Stream from "effect/Stream"; import { LanguageModel as AiLanguageModel } from "effect/unstable/ai"; import * as Binding from "../../Binding.ts"; import type { ConverseRequest } from "./Converse.ts"; import type { ConverseStreamRequest } from "./ConverseStream.ts"; /** * Inference parameters applied to every request made through the * {@link LanguageModel}. They translate to the Converse API's * `inferenceConfig` (plus `additionalModelRequestFields` for * model-specific extensions like `top_k` or reasoning budgets). */ export interface LanguageModelParameters { /** * Maximum number of tokens the model may generate in the response. */ maxTokens?: number; /** * Sampling temperature. Lower values make the output more deterministic. */ temperature?: number; /** * Nucleus-sampling probability mass. */ topP?: number; /** * Sequences that stop generation when the model emits them. */ stopSequences?: string[]; /** * Model-specific request fields passed through verbatim as the Converse * API's `additionalModelRequestFields` — e.g. `{ top_k: 50 }` for * Anthropic models or `{ inferenceConfig: { topK: 5 } }` for Amazon Nova. */ additionalModelRequestFields?: unknown; } /** * Options for constructing a Bedrock-backed Effect AI `LanguageModel`. */ export interface LanguageModelOptions { /** * Default inference parameters. Every field can be overridden per call * with {@link withModelParameters}. */ parameters?: LanguageModelParameters; } /** * Per-call overrides applied with {@link withModelParameters}: any * {@link LanguageModelParameters} field plus the model to run the call on. */ export interface LanguageModelCallParameters extends LanguageModelParameters { /** * The model to run inference on for this call. Must be one of the model * ids the {@link LanguageModel} binding was created with (IAM is scoped to * exactly those). * @default the first bound model id */ modelId?: string; } /** * Fiber-scoped {@link LanguageModelCallParameters} consulted on every * generateText / streamText call made through a Bedrock-backed * `LanguageModel`. Set it for a region of your program with * {@link withModelParameters}. */ export declare const CurrentModelParameters: Context.Reference; /** * Scope per-call inference parameters (and optionally the target model) * onto an Effect or Stream that talks to a Bedrock-backed `LanguageModel`. * Defined fields override the binding's construction-time `parameters`; * everything else falls through to those defaults. * * ```typescript * const response = yield* LanguageModel.generateText({ prompt }).pipe( * Bedrock.withModelParameters({ temperature: 0, maxTokens: 64 }), * ); * ``` */ export declare const withModelParameters: (parameters: LanguageModelCallParameters) => | Stream.Stream>(self: S) => S; /** * Runtime binding that turns an Amazon Bedrock model into an * `effect/unstable/ai` {@link AiLanguageModel.LanguageModel} `Layer`, so any * Effect AI program (`LanguageModel.generateText`, `streamText`, `Chat`, * toolkits, ...) runs against Bedrock without code changes. * * Calls are translated to the Bedrock Converse API — Bedrock's unified * messages API that works across all conversational foundation models * (Amazon Nova, Anthropic Claude, Meta Llama, Mistral, ...) — so one binding * covers every model. Bind one model or a list of models: the function is * granted `bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream` * scoped to exactly those models, the first is the default, and runtime code * picks between them (and tunes inference parameters) per call with * {@link withModelParameters}. A model reference may be a foundation-model * id, a cross-region inference profile id (e.g. `us.amazon.nova-micro-v1:0`), * or a full Bedrock ARN. * * Model access is an account entitlement — enable the model in the Bedrock * console (Model access) before invoking, otherwise calls fail with * `AccessDeniedException`. Many newer models are only invocable through a * cross-region inference profile id, not their bare foundation-model id. * * ### Effect AI on Bedrock * **Example:** Generate Text * ```typescript * import { LanguageModel } from "effect/unstable/ai"; * * // init: bind the model and get a LanguageModel Layer * const model = yield* Bedrock.LanguageModel("us.amazon.nova-micro-v1:0", { * parameters: { maxTokens: 1024, temperature: 0.7 }, * }); * * // runtime: any Effect AI program works against Bedrock * const response = yield* LanguageModel.generateText({ * prompt: "Say hello.", * }).pipe(Effect.provide(model)); * ``` * * **Example:** Stream Text * ```typescript * const parts = LanguageModel.streamText({ prompt }).pipe( * Stream.provide(model), * ); * // parts is a Stream of text-start / text-delta / ... / finish parts * ``` * * ### Runtime Configuration * **Example:** Override Parameters Per Call * The binding's `parameters` are only defaults — scope overrides onto any * call with `withModelParameters`. * ```typescript * const response = yield* LanguageModel.generateText({ prompt }).pipe( * Bedrock.withModelParameters({ temperature: 0, maxTokens: 64 }), * ); * ``` * * **Example:** Bind Multiple Models and Pick Per Call * IAM access is fixed at deploy time (scoped to the bound list); which of * those models serves a given request is a runtime decision. * ```typescript * // init: one Layer, IAM for both models, Nova Micro is the default * const model = yield* Bedrock.LanguageModel([ * "us.amazon.nova-micro-v1:0", * "us.anthropic.claude-sonnet-4-20250514-v1:0", * ]); * * // runtime: route this call to Claude * const response = yield* LanguageModel.generateText({ prompt }).pipe( * Bedrock.withModelParameters({ * modelId: "us.anthropic.claude-sonnet-4-20250514-v1:0", * }), * ); * ``` * * ### Tool Calling * **Example:** Call Tools with a Toolkit * ```typescript * import { Tool, Toolkit } from "effect/unstable/ai"; * import * as Schema from "effect/Schema"; * * const GetWeather = Tool.make("get_weather", { * description: "Get the current weather for a city.", * parameters: Schema.Struct({ city: Schema.String }), * success: Schema.Struct({ temperatureF: Schema.Number }), * }); * const WeatherToolkit = Toolkit.make(GetWeather); * * const response = yield* LanguageModel.generateText({ * prompt: "What's the weather in Seattle?", * toolkit: WeatherToolkit, * }).pipe( * Effect.provide(WeatherToolkit.toLayer({ * get_weather: ({ city }) => Effect.succeed({ temperatureF: 72 }), * })), * Effect.provide(model), * ); * ``` * * @binding */ export interface LanguageModel extends Binding.Service Effect.Effect>> { } export declare const LanguageModel: LanguageModel; /** * The already-bound Converse callables the adapter drives. Produced by * `yield* Bedrock.Converse(model)` / `yield* Bedrock.ConverseStream(model)` * (or any function of the same shape). */ export interface MakeLanguageModelOptions { /** Non-streaming Converse callable (modelId already bound). */ readonly converse: (request: ConverseRequest) => Effect.Effect; /** Streaming Converse callable (modelId already bound). */ readonly converseStream: (request: ConverseStreamRequest) => Effect.Effect; /** Default inference parameters for every call. */ readonly parameters?: LanguageModelParameters; } /** * Provide an {@link AiLanguageModel.LanguageModel} layer backed by the * supplied Bedrock Converse callables. */ export declare const makeLanguageModelLayer: (options: MakeLanguageModelOptions) => Layer.Layer; /** * Build an {@link AiLanguageModel.Service} that proxies generateText / * streamText through the Bedrock Converse API. */ export declare const makeLanguageModel: ({ converse, converseStream, parameters, }: MakeLanguageModelOptions) => Effect.Effect; //# sourceMappingURL=LanguageModel.d.ts.map