liveBook · Manning

MockLanguageModelV1

As explained in Build AI-Enhanced Web Apps

A Vercel AI SDK mock provider class that simulates language-model behavior with developer-defined responses during tests.

MockLanguageModelV1 is a Vercel AI SDK mock provider for testing generateText and generateObject without calling a live provider API. Define controlled model behavior by overriding doGenerate with predictable text, usage, and finish metadata. section 8.4.3

Test a predefined response

Instantiate MockLanguageModelV1 with doGenerate, pass it to generateText, and assert that result.text equals the expected response. The same pattern supports generateObject with a schema and object assertions. section 8.4.3

How Build AI-Enhanced Web Apps covers it

How deep it goes
Explains instantiation and doGenerate overrides, but defers provider internals and broader integration details.
Examples
Uses predefined text, structured objects, token usage metadata, and simulated streaming chunks as test fixtures.
What it assumes
Assumes familiarity with Vercel AI SDK generation functions and unit-test assertions.
What you can do after
Apply it via Vercel AI SDK tests to verify generated text, structured objects, and application model-return handling.
How it connects
Connects generateText and generateObject with simulateReadableStream for testing generated and streamed responses.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.