chatWithTools method

  1. @override
Future<ChatResponse> chatWithTools(
  1. List<ChatMessage> messages,
  2. List<Tool>? tools
)
override

Sends a chat request to the provider with a sequence of messages and tools.

messages - The conversation history as a list of chat messages tools - Optional list of tools to use in the chat

Returns the provider's response or throws an LLMError

Implementation

@override
Future<ChatResponse> chatWithTools(
  List<ChatMessage> messages,
  List<Tool>? tools,
) async {
  try {
    // Note: Phind doesn't support tools yet
    final requestBody = _buildRequestBody(messages, tools, false);

    if (client.logger.isLoggable(Level.FINE)) {
      client.logger.fine('Phind request payload: ${jsonEncode(requestBody)}');
    }

    final responseData = await client.postJson(chatEndpoint, requestBody);
    return _parseResponse(responseData);
  } catch (e) {
    if (e is LLMError) {
      rethrow;
    } else {
      throw GenericError('Unexpected error: $e');
    }
  }
}