DevoxxGenieIDEAPlugin icon indicating copy to clipboard operation
DevoxxGenieIDEAPlugin copied to clipboard

[REFACTOR] LLMModelRegistryService is becoming too big

Open stephanj opened this issue 7 months ago • 2 comments

The file /Users/stephan/projects/DevoxxGenieIDEAPlugin/src/main/java/com/devoxx/genie/service/LLMModelRegistryService.java is pretty large.

  1. Use the Provider Pattern for Model Registration The most immediate refactoring would be to separate the model registration by provider. Here's how you could approach it:
public interface ModelRegistrar {
    void registerModels(Map<String, LanguageModel> modelMap);
}

public class AnthropicModelRegistrar implements ModelRegistrar {
    @Override
    public void registerModels(Map<String, LanguageModel> modelMap) {
        // Move all Anthropic model registration code here
    }
}

public class OpenAIModelRegistrar implements ModelRegistrar {
    @Override
    public void registerModels(Map<String, LanguageModel> modelMap) {
        // Move all OpenAI model registration code here
    }
}

// Similar classes for each provider: GrokModelRegistrar, GroqModelRegistrar, etc. Then your LLMModelRegistryService would be simplified to:

@Service
public final class LLMModelRegistryService {
    private final Map<String, LanguageModel> models = new HashMap<>();
    private final List<ModelRegistrar> registrars;

    public LLMModelRegistryService() {
        registrars = Arrays.asList(
            new AnthropicModelRegistrar(),
            new OpenAIModelRegistrar(),
            new GrokModelRegistrar(),
            // Add other registrars
        );
        
        registerAllModels();
    }
    
    private void registerAllModels() {
        for (ModelRegistrar registrar : registrars) {
            registrar.registerModels(models);
        }
    }
    
    // Rest of the class...
}

stephanj avatar May 19 '25 19:05 stephanj

Actually it would be great if we can externalise the LLM model names, so we can just download/update a remote JSON file instead? Of course when you're not online there should be a fallback procedure.

stephanj avatar May 26 '25 12:05 stephanj

See also #715

stephanj avatar May 27 '25 11:05 stephanj