registerModel static method

ModelInfo registerModel({
  1. String? id,
  2. required String name,
  3. required Uri url,
  4. required InferenceFramework framework,
  5. ModelCategory modality = ModelCategory.language,
  6. ModelArtifactType? artifactType,
  7. int? memoryRequirement,
  8. bool supportsThinking = false,
})

Register a model with the SDK.

Matches Swift RunAnywhere.registerModel(id:name:url:framework:modality:artifactType:memoryRequirement:).

This saves the model to the C++ registry so it can be discovered and loaded.

RunAnywhere.registerModel(
  id: 'smollm2-360m-q8_0',
  name: 'SmolLM2 360M Q8_0',
  url: Uri.parse('https://huggingface.co/.../model.gguf'),
  framework: InferenceFramework.llamaCpp,
  memoryRequirement: 500000000,
);

Implementation

static ModelInfo registerModel({
  String? id,
  required String name,
  required Uri url,
  required InferenceFramework framework,
  ModelCategory modality = ModelCategory.language,
  ModelArtifactType? artifactType,
  int? memoryRequirement,
  bool supportsThinking = false,
}) {
  final modelId =
      id ?? name.toLowerCase().replaceAll(RegExp(r'[^a-z0-9]'), '-');

  final format = _inferFormat(url.path);

  final model = ModelInfo(
    id: modelId,
    name: name,
    category: modality,
    format: format,
    framework: framework,
    downloadURL: url,
    artifactType: artifactType ?? ModelArtifactType.infer(url, format),
    downloadSize: memoryRequirement,
    supportsThinking: supportsThinking,
    source: ModelSource.local,
  );

  _registeredModels.add(model);

  // Save to C++ registry (fire-and-forget, matches Swift pattern)
  // This is critical for model discovery and loading to work correctly
  _saveToCppRegistry(model);

  return model;
}