getChatResponse method

  1. @override
Future<ChatResponse> getChatResponse({
  1. required Iterable<ChatMessage> messages,
  2. ChatOptions? options,
  3. CancellationToken? cancellationToken,
})
override

Sends a chat request and returns the complete response.

Implementation

@override
Future<ChatResponse> getChatResponse({
  required Iterable<ChatMessage> messages,
  ChatOptions? options,
  CancellationToken? cancellationToken,
}) async {
  final key = getCacheKey(messages, options);
  final cached = await getCachedResponse(key);
  if (cached != null) return cached;

  final response = await super.getChatResponse(
    messages: messages,
    options: options,
    cancellationToken: cancellationToken,
  );

  await setCachedResponse(key, response);
  return response;
}