Uh oh!
There was an error while loading. Please reload this page.
added cookbook for batch api - #5
Conversation
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdded a comprehensive cookbook page documenting overnight review tagging using the ZeroGPU Batch API: setup, data schemas, JSONL formatting, complete Python implementation, error recovery patterns, and example workflows. Updated cookbook index and navigation to surface the new tutorial. ChangesBatch API Review Tagging Cookbook
Sequence Diagram(s) sequenceDiagram
participant tag_reviews.py as tag_reviews.py
participant ZeroGPU_API as /v1/chat/completions
participant BatchService as BatchService
participant Storage as Storage
tag_reviews.py->>ZeroGPU_API: upload JSONL (purpose=batch)
tag_reviews.py->>ZeroGPU_API: create batch (completion_window=24h)
tag_reviews.py->>ZeroGPU_API: poll status
BatchService->>BatchService: process rows with LFM2.5-1.2B-Instruct
BatchService->>Storage: write output file (per-line JSON)
BatchService->>Storage: write error file (per-line)
tag_reviews.py->>Storage: download output and error files
tag_reviews.py->>tag_reviews.py: parse and merge results, write tagged.csv/failed.csv
🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers:
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cookbook/batch-review-tagging.mdx`:
- Line 609: Update the example sentence in cookbook/batch-review-tagging.mdx
(the line starting "Cap batch size by your real SLO, not the 100 MB file
limit.") to remove the impossible "a million-line batch" example and replace it
with a realistic batch size within the Batch API limits (e.g., "a 50,000-line
batch" or "a batch near the 50k-line limit") so the guidance matches the
documented 50,000-line per-batch constraint and clarifies the recommendation to
pick chunk sizes that fit the completion_window.
- Line 609: Replace the incorrect "100 MB file limit" text with the correct
Batch API limit: "200 MB (209,715,200 bytes) file limit" in the sentence that
currently reads "**Cap batch size by your real SLO, not the 100 MB file
limit.**" (update the phrase so it reads "**Cap batch size by your real SLO, not
the 200 MB (209,715,200 bytes) file limit.**") to accurately reflect the API
limit in cookbook/batch-review-tagging.mdx.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 284e6a43-2e54-4515-a801-913396281c92
⛔ Files ignored due to path filters (1)
cookbook/batch-review-tagging/reviews.csvis excluded by!**/*.csv
📒 Files selected for processing (2)
cookbook/batch-review-tagging.mdxcookbook/batch-review-tagging/input.jsonl
Uh oh!
There was an error while loading. Please reload this page.
…20labs/docs into batch-api-cookbook
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
cookbook/batch-review-tagging.mdx (2)
282-310:⚠️ Potential issue | 🟠 Major | ⚡ Quick winValidate
review_idbefore emittingcustom_idto prevent whole-batch rejection.
build_jsonlcurrently writesrow["review_id"]directly ascustom_id(Line 296) without checking non-empty/unique values. A blank or duplicate ID will failPOST /v1/batchesvalidation and reject the entire batch.🛠️ Suggested fix
def build_jsonl(csv_path: str, jsonl_path: str) -> int: """Skip rows with an empty review; return the number of lines written.""" written = 0 + seen_ids: set[str] = set() with open(csv_path, encoding="utf-8") as src, \ open(jsonl_path, "w", encoding="utf-8") as dst: reader = csv.DictReader(src) for row in reader: + review_id = (row.get("review_id") or "").strip()+ if not review_id:+ print("skip row: empty review_id")+ continue+ if review_id in seen_ids:+ print(f"skip {review_id}: duplicate review_id")+ continue+ seen_ids.add(review_id) review = (row.get("review") or "").strip() if not review: # Row r-007 in the sample CSV has no review text. Don't waste a # request on it; record it as a local skip instead. print(f"skip {row.get('review_id')}: empty review text") continue line = { - "custom_id": row["review_id"],+ "custom_id": review_id, "method": "POST", "url": "/v1/chat/completions",🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cookbook/batch-review-tagging.mdx` around lines 282 - 310, The build_jsonl function writes row["review_id"] directly as custom_id which can be empty or duplicated and will cause /v1/batches to reject the entire batch; before emitting the line in build_jsonl validate that review_id is non-empty and unique within this run (use row.get("review_id") or fallback), if empty generate a stable fallback ID (e.g., a UUID or "row-N" sequence) and if a duplicate is encountered log/print a skip or append a suffix to make it unique, then use that validated/unique value as custom_id when writing the JSONL entry.
537-544:⚠️ Potential issue | 🟠 MajorCheck HTTP status in
errored_idsbefore parsing response body.
errored_idsreadsrequests.get(...).textwithoutraise_for_status(), so 401/404/5xx responses can later fail as JSON parse errors instead of surfacing the real HTTP failure.🛠️ Suggested fix
def errored_ids(error_file_id: str) -> set[str]: - text = requests.get(- f"{BASE}/v1/files/{error_file_id}/content", headers=HEADERS- ).text+ resp = requests.get(+ f"{BASE}/v1/files/{error_file_id}/content", headers=HEADERS+ )+ resp.raise_for_status()+ text = resp.text return { json.loads(line)["custom_id"] for line in text.splitlines() if line.strip() }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cookbook/batch-review-tagging.mdx` around lines 537 - 544, The function errored_ids should check the HTTP response status before reading and parsing the body; update errored_ids to capture the Response from requests.get, call response.raise_for_status() (or check response.ok and raise a descriptive error) before using response.text, and only then parse each non-empty line as JSON and extract "custom_id" so 4xx/5xx/401 failures surface as HTTP errors instead of JSON parsing errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@cookbook/batch-review-tagging.mdx`:
- Around line 282-310: The build_jsonl function writes row["review_id"] directly
as custom_id which can be empty or duplicated and will cause /v1/batches to
reject the entire batch; before emitting the line in build_jsonl validate that
review_id is non-empty and unique within this run (use row.get("review_id") or
fallback), if empty generate a stable fallback ID (e.g., a UUID or "row-N"
sequence) and if a duplicate is encountered log/print a skip or append a suffix
to make it unique, then use that validated/unique value as custom_id when
writing the JSONL entry.
- Around line 537-544: The function errored_ids should check the HTTP response
status before reading and parsing the body; update errored_ids to capture the
Response from requests.get, call response.raise_for_status() (or check
response.ok and raise a descriptive error) before using response.text, and only
then parse each non-empty line as JSON and extract "custom_id" so 4xx/5xx/401
failures surface as HTTP errors instead of JSON parsing errors.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 69518606-6e17-4ba0-97c0-1cd409968e2b
📒 Files selected for processing (3)
cookbook/batch-review-tagging.mdxcookbook/index.mdxdocs.json
💤 Files with no reviewable changes (1)
- cookbook/index.mdx
✅ Files skipped from review due to trivial changes (1)
- docs.json
amaan-ai20
left a comment
There was a problem hiding this comment.
Looks good! @Baldur-Hua-ai20labs
Waiting for the video.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
amaan-ai20
left a comment
There was a problem hiding this comment.
Awesome Work! @Baldur-Hua-ai20labs
Adds a complete Batch API cookbook demonstrating how to tag a CSV of customer reviews overnight.
Includes:
Jira
Summary by CodeRabbit