Use different seeds for retries

This commit is contained in:
sebastien committed 2026-10-12 11:24:13 +02:00
1 parent c58bbc3672
commit b6c2a634ca
7 files changed
+91 -10

No files matched your search

+7 -5
View File
@@ -15,7 +15,7 @@ from google.genai import types
from pydantic import BaseModel, Field
from copienator import configuration as config
from copienator.gemini_config import thinking_config
from copienator.gemini_config import fresh_seed, thinking_config
from copienator.copy_errors import marked_copy_paths
from copienator import (
CliError,
@@ -213,7 +213,7 @@ def generate_request(
wrong_labels,
wrong_label_text_context="",
wrong_label_text_file: Path | None = None,
seed: int = 0,
seed: int | None = None,
*,
retry: bool = False,
):
@@ -283,7 +283,7 @@ def generate_request(
),
automatic_function_calling=types.AutomaticFunctionCallingConfig(disable=True),
thinking_config=thinking_config("low" if retry else config.THINKING_LEVEL_FOR_LABEL),
seed=seed,
seed=fresh_seed() if seed is None else seed,
max_output_tokens=65535,
response_mime_type= "application/json",
response_json_schema= AnnotationData.model_json_schema(),
@@ -432,6 +432,7 @@ def process_copy_group(
attempt = 0
label_retry_count = 0
wrong_labels: list[str] = []
request_seed = None
while attempt < MAX_ATTEMPTS:
if progress:
progress(group_key, f"{image_file.name}, attempt {attempt + 1}/{MAX_ATTEMPTS}", started)
@@ -439,9 +440,11 @@ def process_copy_group(
print(f"[{group_key}] Retrying {image_file.name} in {10 * attempt}s...")
sleep(10 * attempt)
level = "low" if attempt > 0 else config.THINKING_LEVEL_FOR_LABEL
request_seed = fresh_seed(request_seed)
print(
f"[{group_key}] {image_file.name}: attempt {attempt + 1}/{MAX_ATTEMPTS} "
f"({REQUEST_TIMEOUT_SECONDS}s timeout, thinking={level or 'default'})."
f"({REQUEST_TIMEOUT_SECONDS}s timeout, thinking={level or 'default'}, "
f"seed={request_seed})."
)
try:
text_context_file, text_context = closest_text_context(
@@ -452,7 +455,6 @@ def process_copy_group(
f"[{group_key}] Retry context for {image_file.name}: "
f"{text_context_file.relative_to(workspace.root)}"
)
request_seed = max(0, label_retry_count - 1)
contents, request_config = generate_request(
image_file,
labels_text,