Fixing timeouts in label detection, maybe.
This commit is contained in:
1 parent
9925362352
commit
c58bbc3672
2 files changed
+34
-5
No files matched your search
@@ -31,6 +31,7 @@ from copienator.utils import natural_key, read_all_labels
|
||||
|
||||
MODEL_ID = config.MODEL_FOR_LABEL_ID
|
||||
api_key = config.API_KEY
|
||||
REQUEST_TIMEOUT_SECONDS = 80
|
||||
|
||||
my_prompt = """I'm giving you an image of the left columns of a written exam.
|
||||
Students answer several exercises, which can have several questions.
|
||||
@@ -213,6 +214,8 @@ def generate_request(
|
||||
wrong_label_text_context="",
|
||||
wrong_label_text_file: Path | None = None,
|
||||
seed: int = 0,
|
||||
*,
|
||||
retry: bool = False,
|
||||
):
|
||||
"""Generates request for Gemini with context."""
|
||||
|
||||
@@ -275,11 +278,11 @@ def generate_request(
|
||||
|
||||
generate_content_config = types.GenerateContentConfig(
|
||||
http_options=types.HttpOptions(
|
||||
timeout=120_000,
|
||||
timeout=REQUEST_TIMEOUT_SECONDS * 1000,
|
||||
retry_options=types.HttpRetryOptions(attempts=1),
|
||||
),
|
||||
automatic_function_calling=types.AutomaticFunctionCallingConfig(disable=True),
|
||||
thinking_config=thinking_config(config.THINKING_LEVEL_FOR_LABEL),
|
||||
thinking_config=thinking_config("low" if retry else config.THINKING_LEVEL_FOR_LABEL),
|
||||
seed=seed,
|
||||
max_output_tokens=65535,
|
||||
response_mime_type= "application/json",
|
||||
@@ -435,7 +438,11 @@ def process_copy_group(
|
||||
if attempt > 0:
|
||||
print(f"[{group_key}] Retrying {image_file.name} in {10 * attempt}s...")
|
||||
sleep(10 * attempt)
|
||||
print(f"[{group_key}] {image_file.name}: attempt {attempt + 1}/{MAX_ATTEMPTS} (120s timeout).")
|
||||
level = "low" if attempt > 0 else config.THINKING_LEVEL_FOR_LABEL
|
||||
print(
|
||||
f"[{group_key}] {image_file.name}: attempt {attempt + 1}/{MAX_ATTEMPTS} "
|
||||
f"({REQUEST_TIMEOUT_SECONDS}s timeout, thinking={level or 'default'})."
|
||||
)
|
||||
try:
|
||||
text_context_file, text_context = closest_text_context(
|
||||
workspace, wrong_labels
|
||||
@@ -455,6 +462,7 @@ def process_copy_group(
|
||||
text_context,
|
||||
text_context_file,
|
||||
seed=request_seed,
|
||||
retry=attempt > 0,
|
||||
)
|
||||
response = client.models.generate_content(
|
||||
model=MODEL_ID,
|
||||
|
||||
Reference in new issue
Block a user