AI SDK CorewrapLanguageModel

wrapLanguageModel()

Language model middleware is an experimental feature.

The experimental_wrapLanguageModel function provides a way to enhance the behavior of language models by wrapping them with middleware. See Language Model Middleware for more information on middleware.

import { experimental_wrapLanguageModel as wrapLanguageModel } from 'ai';
const wrappedLanguageModel = wrapLanguageModel({
model: yourModel,
middleware: yourLanguageModelMiddleware,
});

Import

import { experimental_wrapLanguageModel as wrapLanguageModel } from "ai"

API Signature

Parameters

model:

LanguageModelV1
The original LanguageModelV1 instance to be wrapped.

middleware:

Experimental_LanguageModelV1Middleware
The middleware to be applied to the language model.

modelId:

string
Optional custom model ID to override the original model's ID.

providerId:

string
Optional custom provider ID to override the original model's provider.

Returns

A new LanguageModelV1 instance with middleware applied.