generate method

  1. @override
Future<ModelMessage> generate(
  1. List<LLMMessage> messages, {
  2. List<Tool>? tools,
  3. ToolChoice? toolChoice,
  4. required ModelConfig modelConfig,
  5. bool? jsonOutput,
  6. CancelToken? cancelToken,
})
override

Implementation

@override
Future<ModelMessage> generate(
  List<LLMMessage> messages, {
  List<Tool>? tools,
  ToolChoice? toolChoice,
  required ModelConfig modelConfig,
  bool? jsonOutput,
  CancelToken? cancelToken,
}) async {
  final hash = hasher.compute(
    messages: messages,
    tools: tools,
    modelConfig: modelConfig,
    jsonOutput: jsonOutput,
    trialSalt: trialSalt,
  );
  final cached = await store.get(hash);
  if (cached != null) return cached;

  _logger.fine('replay cache miss: $hash');
  if (fallback != null && !strictReplay) {
    await rateLimitGate.acquire(estimatedTokens: modelConfig.maxTokens ?? 0);
    return fallback!.generate(
      messages,
      tools: tools,
      toolChoice: toolChoice,
      modelConfig: modelConfig,
      jsonOutput: jsonOutput,
      cancelToken: cancelToken,
    );
  }
  throw RecordingNotFoundException(hash);
}