ToolChoice.fromJson constructor

ToolChoice.fromJson(
  1. dynamic raw
)

Implementation

factory ToolChoice.fromJson(dynamic raw) {
  if (raw is String) {
    switch (raw) {
      case 'auto':
        return const ToolChoiceAuto();
      case 'none':
        return const ToolChoiceNone();
      case 'required':
        return const ToolChoiceRequired();
    }
  }
  final map = raw as Map<String, dynamic>;
  switch (map['type']) {
    case 'file_search':
      return const ToolChoiceFileSearch();
    case 'web_search_preview':
      return const ToolChoiceWebSearchPreview();
    case 'computer_use_preview':
      return const ToolChoiceComputerUsePreview();
    case 'code_interpreter':
      return const ToolChoiceCodeInterpreter();
    case 'mcp':
      return const ToolChoiceMcp();
    case 'image_generation':
      return const ToolChoiceImageGeneration();
    case 'function_tool':
      return ToolChoiceFunction(name: map['name'] as String);
    default:
      return ToolChoiceOther(raw);
  }
}