DevoxxGenieIDEAPlugin
DevoxxGenieIDEAPlugin copied to clipboard
[REFACTOR] LLMModelRegistryService is becoming too big
The file /Users/stephan/projects/DevoxxGenieIDEAPlugin/src/main/java/com/devoxx/genie/service/LLMModelRegistryService.java is pretty large.
- 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...
}
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.
See also #715