Skip to content

[REFACTOR] LLMModelRegistryService is becoming too big #697

@stephanj

Description

@stephanj

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...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions