MockLanguageModelV4 class
A controllable mock language model for testing.
Mirrors MockLanguageModelV1 from the JS AI SDK v6 ai/test sub-path.
final model = MockLanguageModelV4(
response: [MockTextPart('Hello!')],
);
final result = await generateText(model: model, prompt: 'Hi');
expect(result.text, 'Hello!');
Constructors
-
MockLanguageModelV4({List<
LanguageModelV4ContentPart> response = const [], LanguageModelV4FinishReason finishReason = LanguageModelV4FinishReason.stop, String? rawFinishReason = 'stop', LanguageModelV4Usage? usage, List<String> warnings = const [], ProviderMetadata? providerMetadata, Object? doGenerateError, Object? doStreamError, String provider = 'mock', String modelId = 'mock-language-model'})
Properties
- doGenerateError → Object?
-
If set, doGenerate throws this error instead of returning a response.
final
- doStreamError → Object?
-
If set, doStream throws this error instead of returning a stream.
final
- finishReason → LanguageModelV4FinishReason
-
Finish reason to report.
final
-
generateCalls
→ List<
LanguageModelV4CallOptions> -
All call options passed to doGenerate in the order they were called.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- modelId → String
-
Provider-specific model identifier.
final
- provider → String
-
Provider identifier (e.g., 'openai', 'anthropic').
final
- providerMetadata → ProviderMetadata?
-
final
- rawFinishReason → String?
-
final
-
response
→ List<
LanguageModelV4ContentPart> -
Content parts to return from every call.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- specificationVersion → String
-
Specification version this model implements.
no setter
-
streamCalls
→ List<
LanguageModelV4CallOptions> -
All call options passed to doStream in the order they were called.
final
-
supportedUrls
→ FutureOr<
Map< String, List< >RegExp> > -
URL patterns this model can consume without the SDK downloading them.
no setterinherited
- usage → LanguageModelV4Usage?
-
Token usage to report.
final
-
warnings
→ List<
String> -
Warnings to report.
final
Methods
-
doGenerate(
LanguageModelV4CallOptions options) → Future< LanguageModelV4GenerateResult> - Generate a complete, non-streaming response.
-
doStream(
LanguageModelV4CallOptions options) → Future< LanguageModelV4StreamResult> - Generate a streaming response.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited