Skip to content

fix: guard ModelNameCompleter against None active_model and stale cache - #704

Open
varunsahni18 wants to merge 1 commit into
mpfaffenberger:mainfrom
varunsahni18:fix/419-modelnamecompleter-none-crash-and-stale-cache
Open

fix: guard ModelNameCompleter against None active_model and stale cache#704
varunsahni18 wants to merge 1 commit into
mpfaffenberger:mainfrom
varunsahni18:fix/419-modelnamecompleter-none-crash-and-stale-cache

Conversation

@varunsahni18

Copy link
Copy Markdown

Changes

  • Guard get_active_model() return against None before calling .lower() (fixes AttributeError crash)
  • Remove stale self.model_names cache from __init__
  • Load model_names fresh per completion invocation in get_completions()
  • Add regression test for the no-model-configured scenario

Issue

Closes #419

Testing

from unittest.mock import patch
from code_puppy.command_line.model_picker_completion import ModelNameCompleter
from prompt_toolkit.document import Document

with patch("..._load_models_config", return_value={"gpt-4": {}}), \
     patch("...get_active_model", return_value=None):
    completions = list(ModelNameCompleter().get_completions(Document("/model "), None))
    assert len(completions) > 0  # No crash!

Credit: Issue analysis and code pointers by @mpfaffenberger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ModelNameCompleter crashes with AttributeError when no model is configured (get_active_model() returns None)

1 participant