Use different seeds for retries
This commit is contained in:
1 parent
c58bbc3672
commit
b6c2a634ca
7 files changed
+91
-10
No files matched your search
@@ -15,12 +15,13 @@ from collections.abc import Sequence
|
||||
from pathlib import Path
|
||||
|
||||
from google import genai
|
||||
from google.genai import types
|
||||
|
||||
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.gemini_config import fresh_seed, thinking_config
|
||||
from copienator import configuration as settings
|
||||
from copienator.feedback_boxes import valid_feedback_box
|
||||
from copienator.latex_json import repair_latex_json
|
||||
@@ -274,10 +275,19 @@ def call_gemini_with_retries(model_id, contents, config,
|
||||
"""Handles requests to Gemini with a 1min and 5min retry mechanism, and quota fallback."""
|
||||
global pro_quota_exhausted
|
||||
delays = [60, 300]
|
||||
request_seed = None
|
||||
# Own the retries here so the SDK cannot silently resend a fixed seed.
|
||||
http_options = config.http_options or types.HttpOptions()
|
||||
config = config.model_copy(update={"http_options": http_options.model_copy(
|
||||
update={"retry_options": types.HttpRetryOptions(attempts=1)}
|
||||
)})
|
||||
|
||||
for attempt in range(3):
|
||||
if stop_requested.is_set():
|
||||
raise CorrectionStopRequested
|
||||
request_seed = fresh_seed(request_seed)
|
||||
config = config.model_copy(update={"seed": request_seed})
|
||||
tprint(f"\tGemini attempt {attempt + 1}/3: seed={request_seed}")
|
||||
# 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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user