20
20
import json
21
21
import logging
22
22
import os
23
+ import re
23
24
import sys
24
25
from typing import Any
25
26
from typing import AsyncGenerator
@@ -424,6 +425,8 @@ def _remove_display_name_if_present(
424
425
class Gemma (Gemini ):
425
426
"""Integration for Gemma models exposed via the Gemini API.
426
427
428
+ Only Gemma 3 models are supported at this time.
429
+
427
430
For full documentation, see: https://ai.google.dev/gemma/docs/core/
428
431
429
432
NOTE: Gemma does **NOT** support system instructions. Any system instructions
@@ -442,9 +445,7 @@ class Gemma(Gemini):
442
445
usage via the Gemini API.
443
446
"""
444
447
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]
448
449
449
450
@classmethod
450
451
@override
@@ -456,7 +457,7 @@ def supported_models(cls) -> list[str]:
456
457
"""
457
458
458
459
return [
459
- r'gemma-.*' ,
460
+ r'gemma-3 .*' ,
460
461
]
461
462
462
463
@cached_property
@@ -473,7 +474,7 @@ async def _preprocess_request(self, llm_request: LlmRequest) -> None:
473
474
474
475
# NOTE: if history is preserved, we must include the system instructions ONLY once at the beginning
475
476
# of any chain of contents.
476
- if len ( contents ) >= 1 :
477
+ if contents :
477
478
if contents [0 ] != instruction_content :
478
479
# only prepend if it hasn't already been done
479
480
llm_request .contents = [instruction_content ] + contents
@@ -642,8 +643,6 @@ def gemma_functions_after_model_callback(
642
643
return
643
644
644
645
try :
645
- import re
646
-
647
646
json_candidate = None
648
647
649
648
markdown_code_block_pattern = re .compile (
@@ -699,7 +698,6 @@ def _get_last_valid_json_substring(text: str) -> tuple[bool, str | None]:
699
698
decoder = json .JSONDecoder ()
700
699
last_json_str = None
701
700
start_pos = 0
702
- first_brace_index = 0
703
701
while start_pos < len (text ):
704
702
try :
705
703
first_brace_index = text .index ('{' , start_pos )
0 commit comments