The registry

public class ModelRegistry {
  private static final Map FACTORIES = new ConcurrentHashMap<>();
  public static void register(String name, ModelFactory factory) {
    FACTORIES.put(name, factory);
  }
  public static BaseLLM create(String name, Config cfg) {
    return FACTORIES.get(name).create(cfg);
  }
}
Advertisement

Register a provider

ModelRegistry.register("ollama", cfg -> new OllamaLLM(cfg.endpoint(), cfg.model()));
ModelRegistry.register("anthropic", cfg -> new AnthropicLLM(cfg.apiKey()));
Advertisement

Look up by name

BaseLLM model = ModelRegistry.create("ollama",
    Config.of("endpoint", "http://localhost:11434", "model", "llama3.2"));