Timeout for label detection
This commit is contained in:
1 parent
6a6ed178ef
commit
55f9a29677
2 files changed
+96
-21
No files matched your search
@@ -19,11 +19,7 @@ from copienator import (
|
||||
)
|
||||
|
||||
|
||||
def run(workspace: EvaluationWorkspace, *, client=None) -> ExitCode:
|
||||
if client is None:
|
||||
if not config.API_KEY:
|
||||
raise CliError("GEMINI_API_KEY is not configured")
|
||||
client = genai.Client(api_key=config.API_KEY)
|
||||
def run(workspace: EvaluationWorkspace, *, client=None, overwrite: bool = False) -> ExitCode:
|
||||
batches = (
|
||||
(
|
||||
"flash",
|
||||
@@ -45,16 +41,32 @@ def run(workspace: EvaluationWorkspace, *, client=None) -> ExitCode:
|
||||
}
|
||||
if workspace.batch_jobs_file.is_file():
|
||||
previous = read_json(workspace.batch_jobs_file)
|
||||
if isinstance(previous, dict) and isinstance(previous.get("jobs"), dict):
|
||||
manifest["jobs"] = previous["jobs"]
|
||||
if not isinstance(previous, dict) or not isinstance(previous.get("jobs"), dict):
|
||||
raise CliError(f"Invalid batch manifest: {workspace.batch_jobs_file}")
|
||||
manifest["jobs"] = previous["jobs"]
|
||||
started = 0
|
||||
skipped = 0
|
||||
for tier, file_path, model_id, display_name in batches:
|
||||
existing = manifest["jobs"].get(tier)
|
||||
if tier in manifest["jobs"]:
|
||||
if (not isinstance(existing, dict)
|
||||
or not isinstance(existing.get("name"), str)
|
||||
or not existing["name"].strip()):
|
||||
raise CliError(f"Invalid batch job in {workspace.batch_jobs_file}: {tier}")
|
||||
if not overwrite:
|
||||
print(f"Skipping {tier}: already submitted as {existing['name']}.")
|
||||
skipped += 1
|
||||
continue
|
||||
if not file_path.is_file():
|
||||
print(f"Skipping {model_id}: {file_path.name} does not exist.")
|
||||
continue
|
||||
if file_path.stat().st_size == 0:
|
||||
print(f"Skipping {model_id}: {file_path.name} is empty.")
|
||||
continue
|
||||
if client is None:
|
||||
if not config.API_KEY:
|
||||
raise CliError("GEMINI_API_KEY is not configured")
|
||||
client = genai.Client(api_key=config.API_KEY)
|
||||
print(f"Uploading {file_path.name} for model {model_id}...")
|
||||
uploaded = client.files.upload(
|
||||
file=str(file_path),
|
||||
@@ -77,19 +89,26 @@ def run(workspace: EvaluationWorkspace, *, client=None) -> ExitCode:
|
||||
}
|
||||
atomic_write_json(workspace.batch_jobs_file, manifest)
|
||||
print(f"Started batch job: {job.name}")
|
||||
if not started:
|
||||
if not started and not skipped:
|
||||
print("No non-empty batch request files were found.")
|
||||
return ExitCode.PARTIAL
|
||||
return ExitCode.SUCCESS
|
||||
|
||||
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
return evaluation_parser("Upload correction JSONL files and start Gemini batches")
|
||||
parser = evaluation_parser("Upload correction JSONL files and start Gemini batches")
|
||||
parser.add_argument(
|
||||
"--overwrite", action="store_true",
|
||||
help="Submit new jobs even for recorded tiers, replacing their saved job IDs",
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
def main(argv: Sequence[str] | None = None) -> int:
|
||||
parser = build_parser()
|
||||
return execute(parser, argv, lambda args: run(workspace_from_args(args)))
|
||||
return execute(parser, argv, lambda args: run(
|
||||
workspace_from_args(args), overwrite=args.overwrite,
|
||||
))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user