Skip to content

Commit 46a6fac

Browse files
authored
feat(#70): support gemini 2.5 stable models (#71)
closes #70
1 parent 0d43ad6 commit 46a6fac

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/lgtm_ai/ai/schemas.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939
"gemini-2.0-flash-lite-preview-02-05",
4040
"gemini-2.0-pro-exp-02-05",
4141
"gemini-2.5-flash-preview-04-17",
42+
"gemini-2.5-pro",
4243
"gemini-2.5-pro-exp-03-25",
4344
"gemini-2.5-pro-preview-03-25",
4445
"gemini-2.5-pro-preview-05-06",
46+
"gemini-2.5-flash",
4547
"gemini-2.5-flash-preview-05-20",
4648
"gemini-2.5-pro-preview-06-05",
4749
]

src/lgtm_ai/ai/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ def select_latest_gemini_model(matches: list[SupportedGeminiModel]) -> Supported
2626
if len(matches) == 1:
2727
return matches[0]
2828

29+
# If one of them is not a `preview` or `exp` model, select it
30+
# This is because out of several possible models given a wildcard, we assume preference for stable models.
31+
# If the user wanted a preview or experimental model, they could have specified it in the wildcard itself:
32+
# e.g.: `gemini-2.5-flash*` will select the latest stable, while `gemini-2.5-flash-p*` will select the latest preview.
33+
non_preview_matches = [model for model in matches if all(word not in model for word in ("preview", "exp"))]
34+
if non_preview_matches:
35+
if len(non_preview_matches) > 1:
36+
raise InvalidGeminiWildcard(matches)
37+
return non_preview_matches[0]
38+
2939
model_to_date = {model: model.split("-")[-2:] for model in matches}
3040

3141
def _looks_like_date(date: list[str]) -> bool:

tests/ai/test_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def test_get_ai_model(model: str, model_url: str | None, ai_api_key: str, expect
5151
("gemini-2.5-flash-*-*", None, pytest.raises(InvalidModelWildCard)),
5252
# Wildcards in the middle of the model name are not allowed
5353
("gemini-*-pro-preview-06-05", None, pytest.raises(InvalidModelWildCard)),
54+
# Wildcards that match preview, experimental and stable models must select the stable one
55+
("gemini-2.5-pro*", "gemini-2.5-pro", does_not_raise()),
5456
],
5557
)
5658
def test_get_ai_model_with_wildcard(model: str, expected_model_name: str, expectation: Any) -> None:

0 commit comments

Comments
 (0)