extract<T> method

Future<T> extract<T>({
  1. required List<Message> messages,
  2. required ObjectSchema schema,
  3. required T fromJson(
    1. Map<String, Object?> json
    ),
  4. String toolName = 'extract',
  5. String? toolDescription,
  6. int maxRetries = 2,
  7. void onRetry(
    1. ExtractionAttempt attempt
    )?,
})

Extracts a T from the model.

fromJson runs only after the response has passed schema validation, so it can assume every required field is present and correctly typed.

Implementation

Future<T> extract<T>({
  required List<Message> messages,
  required ObjectSchema schema,
  required T Function(Map<String, Object?> json) fromJson,
  String toolName = 'extract',
  String? toolDescription,
  int maxRetries = 2,
  void Function(ExtractionAttempt attempt)? onRetry,
}) async {
  final raw = await extractRaw(
    messages: messages,
    schema: schema,
    toolName: toolName,
    toolDescription: toolDescription,
    maxRetries: maxRetries,
    onRetry: onRetry,
  );
  return fromJson(raw);
}