FunctionTool.fromJson constructor

FunctionTool.fromJson(
  1. Map<String, dynamic> json
)

Reads a declaration in OpenAI's tools shape.

Accepts both {"type":"function","function":{...}} and a bare function object, because both are in circulation.

Implementation

factory FunctionTool.fromJson(Map<String, dynamic> json) {
  final fn = json['type'] == 'function' && json['function'] is Map
      ? Map<String, dynamic>.from(json['function'] as Map)
      : json;
  return FunctionTool(
    name: '${fn['name'] ?? ''}',
    description: '${fn['description'] ?? ''}',
    parameters: fn['parameters'] is Map
        ? Map<String, dynamic>.from(fn['parameters'] as Map)
        : const {'type': 'object', 'properties': <String, dynamic>{}},
  );
}