getToolCallable method

Function getToolCallable(
  1. GroqToolCall toolCall
)

Validates and returns the registered tool function with the given arguments. toolCall the tool call usually returned from the GroqMessage object. returns the callable function, if the tool is registered. Throws an exception if the tool is not found.

Implementation

Function getToolCallable(GroqToolCall toolCall) {
  GroqToolItem? tool;
  try {
    tool = _registeredTools.firstWhere((element) {
      print('element.functionName: ${element.functionName}');
      print('toolCall.functionName: ${toolCall.functionName}');
      return element.functionName == toolCall.functionName;
    });
  } catch (e) {
    throw Exception('Tool not found');
  }
  final response = tool.validateAndGetCallable(toolCall.arguments);
  return response;
}