TypedModel class

A typed facade over Model.

Wraps the raw Map<String, dynamic>-based API with typed classes: GenerateTextOptions in, GenerateTextResult out, StreamParts out of streamText. Construct with a Model (e.g. Model.openai(...)); call close to release the native handle.

Example:

final model = Model.openai(apiKey, 'gpt-4o', baseUrl: baseUrl);
final typed = TypedModel(model);
try {
  final result = typed.generateText('Hello', GenerateTextOptions(temperature: 0.7));
  print(result.text);
} finally {
  typed.close();
}

Constructors

TypedModel(Model _raw)

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → void
Release the native handle. Delegates to the wrapped Model; safe to call multiple times.
consumeStreamText(String prompt, [GenerateTextOptions? options]) StreamTextResultAggregated
Consume a stream to completion from a string prompt and return the aggregated result (M11). Synchronous (blocks until the stream finishes).
consumeStreamTextMessages(List<ModelMessage> messages, [GenerateTextOptions? options]) StreamTextResultAggregated
Consume a stream to completion from a list of typed ModelMessages and return the aggregated result (M11).
generateObject(String prompt, [GenerateTextOptions? options]) GenerateObjectResult
Generate a structured JSON object from a string prompt (M12).
generateObjectMessages(List<ModelMessage> messages, [GenerateTextOptions? options]) GenerateObjectResult
Generate a structured JSON object from a list of typed ModelMessages (M12).
generateText(String prompt, [GenerateTextOptions? options]) GenerateTextResult
Generate text from a string prompt.
generateTextAsOpenAI(String prompt, [GenerateTextOptions? options]) ChatCompletion
Generate text (non-streaming) with OpenAI Chat Completions output.
generateTextAsOpenAIMessages(List<ModelMessage> messages, [GenerateTextOptions? options]) ChatCompletion
Generate text from a list of typed ModelMessages with OpenAI Chat Completions output.
generateTextMessages(List<ModelMessage> messages, [GenerateTextOptions? options]) GenerateTextResult
Generate text from a list of typed ModelMessages (multi-turn).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
streamText(Object prompt, [GenerateTextOptions? options]) Stream<StreamPart>
Stream text, yielding typed StreamParts.
streamTextAsOpenAI(Object prompt, [GenerateTextOptions? options]) Stream<ChatCompletionChunk>
Stream text with OpenAI Chat Completions output, yielding typed ChatCompletionChunks (RFC-0026).
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited