Cache LLM model instances in registry#14
Conversation
Optimizes `get_model` by caching LLM client instances to avoid redundant instantiation. Verified with reproduction script and existing tests.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Added
@lru_cache(maxsize=16)to theget_modelfunction insrc/models/registry.py.🎯 Why:
The
get_modelfunction was creating a new LLM client instance on every call. Instantiating these clients can be expensive (setting up connections, validating keys). By caching the result, we reuse the same client instance for the same configuration (provider, model_name, temperature).📊 Impact:
Reduces unnecessary object creation and potential connection overhead. While strict benchmarking wasn't possible due to environment constraints, this is a standard optimization for service clients.
🔬 Measurement:
Verified using a reproduction script that
get_modelnow returns the same instance for identical arguments. Existing unit tests passed.PR created automatically by Jules for task 2149973887280083142 started by @ishaanxgupta