2020import json
2121import logging
2222import os
23+ import re
2324import sys
2425from typing import Any
2526from typing import AsyncGenerator
@@ -424,6 +425,8 @@ def _remove_display_name_if_present(
424425class Gemma (Gemini ):
425426 """Integration for Gemma models exposed via the Gemini API.
426427
428+ Only Gemma 3 models are supported at this time.
429+
427430 For full documentation, see: https://ai.google.dev/gemma/docs/core/
428431
429432 NOTE: Gemma does **NOT** support system instructions. Any system instructions
@@ -442,9 +445,7 @@ class Gemma(Gemini):
442445 usage via the Gemini API.
443446 """
444447
445- model : str = (
446- 'gemma-3-27b-it' # Others: [gemma-3-1b-it, gemma-3-4b-it, gemma-3-12b-it]
447- )
448+ model : str = 'gemma-3-27b-it' # Others: [gemma-3-1b-it, gemma-3-4b-it, gemma-3-12b-it]
448449
449450 @classmethod
450451 @override
@@ -456,7 +457,7 @@ def supported_models(cls) -> list[str]:
456457 """
457458
458459 return [
459- r'gemma-.*' ,
460+ r'gemma-3 .*' ,
460461 ]
461462
462463 @cached_property
@@ -473,7 +474,7 @@ async def _preprocess_request(self, llm_request: LlmRequest) -> None:
473474
474475 # NOTE: if history is preserved, we must include the system instructions ONLY once at the beginning
475476 # of any chain of contents.
476- if len ( contents ) >= 1 :
477+ if contents :
477478 if contents [0 ] != instruction_content :
478479 # only prepend if it hasn't already been done
479480 llm_request .contents = [instruction_content ] + contents
@@ -642,8 +643,6 @@ def gemma_functions_after_model_callback(
642643 return
643644
644645 try :
645- import re
646-
647646 json_candidate = None
648647
649648 markdown_code_block_pattern = re .compile (
@@ -699,7 +698,6 @@ def _get_last_valid_json_substring(text: str) -> tuple[bool, str | None]:
699698 decoder = json .JSONDecoder ()
700699 last_json_str = None
701700 start_pos = 0
702- first_brace_index = 0
703701 while start_pos < len (text ):
704702 try :
705703 first_brace_index = text .index ('{' , start_pos )
0 commit comments