update Gemini API : use thinking levels

This commit is contained in:
sebastien committed 2026-10-10 08:47:39 +02:00
1 parent 7bc588e9a1
commit ec6ac9580b
9 files changed
+161 -21

No files matched your search

+17 -8
View File
@@ -20,6 +20,8 @@ from copienator import configuration as config
from copienator.commands import grouping
from copienator.answer_origins import save_origins
from copienator import prompting
from copienator.gemini_config import thinking_config
from copienator import configuration as settings
from copienator.feedback_boxes import valid_feedback_box
from copienator.latex_json import repair_latex_json
from copienator import (
@@ -279,6 +281,9 @@ def call_gemini_with_retries(model_id, contents, config,
# Switch to fallback immediately if quota was exhausted by another thread
if model_id == MODEL_ID_pro and pro_quota_exhausted and fallback_model_id:
model_id = fallback_model_id
config = config.model_copy(update={"thinking_config": thinking_config(
settings.THINKING_LEVEL_FLASH
)})
try:
full_response_text = ""
@@ -312,6 +317,9 @@ def call_gemini_with_retries(model_id, contents, config,
if is_quota_error and model_id == MODEL_ID_pro and fallback_model_id:
tprint(f"\tGemini Pro quota hit ({e}). \n\n\tFalling back to Flash permanently...")
model_id = fallback_model_id
config = config.model_copy(update={"thinking_config": thinking_config(
settings.THINKING_LEVEL_FLASH
)})
pro_quota_exhausted = True
continue # Retry immediately with Flash
@@ -506,7 +514,11 @@ def process_single_task(task_tuple, precomputed_response=None):
flash_count += 1
try:
contents, config = prompting.generate_request(INPUT_DIR, file_path, label)
contents, config = prompting.generate_request(
INPUT_DIR, file_path, label,
thinking_level=(settings.THINKING_LEVEL_FLASH if use_flash
else settings.THINKING_LEVEL_PRO),
)
model_to_use = MODEL_ID_flash if use_flash else MODEL_ID_pro
if precomputed_response:
@@ -891,13 +903,10 @@ def run_configured(args: argparse.Namespace) -> ExitCode:
],
}
],
"generation_config": {
"temperature": 1.0,
"topP": 0.95,
"maxOutputTokens": 65535,
"responseMimeType": "application/json",
"responseSchema": prompting.UNROLLED_SCHEMA,
},
"generation_config": prompting.batch_generation_config(
settings.THINKING_LEVEL_FLASH if use_flash
else settings.THINKING_LEVEL_PRO
),
},
}
line = json.dumps(request)