Repository navigation
feat(importer): review ai points job calls models through the dos.ai gateway - #1607
Conversation
…gateway JOY decided on 2026-11-04 that the job uses dos.ai, not the Anthropic API (D2 of the AI review points design). The job now sends its batch through the gateway's OpenAI-compatible Files and Batch API with DOS_AI_API_KEY (DOS_AI_BASE_URL overrides the URL). That Batch API serves dos, qwen3.8 and deepseek models only, so the default model is dos (Qwen3.8 27B on DOS GPUs) and qwen3.8-max is the fallback, with the same monthly caps. Caps, kill switch, process-once, evidence checks and quality stops are unchanged. A cut-off or filtered answer (finish_reason length or content_filter) and an errored line are stored as failed. Cached tokens count at the full input price, an upper bound. @anthropic-ai/sdk is removed. The proposal notes the D2 change. Refs #1531 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review findings on the dos.ai client (#1531): - POST /batches is retried only on 429; a lost answer throws and says a batch may exist, instead of creating and billing a second one. - A batch failed as a whole, one with no output, or one whose output file is gone (404) closes its row and stores nothing, so its reviews are due again without spending an attempt; a line not run for want of credits is unbilled, not failed. - Each call's timeout covers reading the body. - Tests: create-once on a network error and a 502, retry on 429, failed and purged batches, 402 lines, the request body; batch ids renamed. - The proposal notes the dos.ai batch path in sections 4 and 5. Refs #1531 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 19 minutes. View limit details
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. |
There was a problem hiding this comment.
⏱️ Code Review completed (6 eligible files · 50,477 chars · 3 model call(s) · 2 PR unit(s))
Whole diff with bounded context at base 37ea3c8 / head bfe87d6.
Excluded by noise policy: pnpm-lock.yaml.
✅ No verified defects
1 possible issue(s) could not be grounded in or verified against the snapshot source, so they are not published.
Context investigation was bounded to the explicitly requested snapshot paths.
🔒 Dependency check
✅ Passed. Every new package version comes from the public registry or a source this lockfile already used for it, its checksum is pinned where the format records one, and OSV lists no new malicious package or high or critical vulnerability for the versions it was asked about.
Refs #1531
On 2026-11-04 JOY changed D2 of
Docs/Proposals/2026-11-03-ai-review-points.html: "Tại sao khóa Anthropic? Tao có nguyên 1 cái dos.ai cơ mà?". The review AI points job (#1599) therefore calls models through JOY's dos.ai gateway instead of the Anthropic API.What the gateway offers
Read from the DOS/DOS.AI source,
services/api-gateway:POST /v1/files(multipart,purpose=batch);POST /v1/batches(endpoint/v1/chat/completions,completion_window24h);GET /v1/batches/:id,POST /v1/batches/:id/cancel;GET /v1/files/:id/content(JSONL output).dos(Qwen3.8 27B on DOS GPUs),qwen3.8-*anddeepseek-*. Claude is not served there.dos_sk_keys sent asAuthorization: Bearer, as the importer's other AI clients already do (DOS_AI_API_KEY,DOS_AI_BASE_URL).The change
dosAiReviewAiClientreplaces the Anthropic SDK client, and@anthropic-ai/sdkis removed.response_format: json_schema(strict),temperature: 0,max_tokens: 6000, the instructions as the system message and the reviews as the user message.finish_reasonlengthis treated as cut off, andcontent_filteras refused. Both, and any errored line, are stored as failed, never as empty.Models (D1's shape):
dosby default andqwen3.8-maxas the fallback ifdosmisses the gold set.Unchanged: the 2000-reviews-a-run limit, the kill switch, process-once, the persisted batch id, the evidence checks, the quality stops and
--purge.Review fixes: a fresh-context Claude review found 1 P1 and 3 P2. All are fixed:
POST /batchesis never retried on a lost answer, because a retry could create and bill a second batch. Only a 429 is retried.The proposal: sections 3, 4, 5, D2 and the Rate-Services line now record the change.
Tests (fake gateway, no network):
Typecheck and lint pass.
Runbook for Rate-Services (replaces the earlier one)
DOS_AI_API_KEY, ados_sk_key from dev.dos.me for the DOS.AI product. It replacesANTHROPIC_API_KEY. The key's organization must not have Zero Data Retention on, because the Batch API refuses those batches.DOS_AI_BASE_URL. The default ishttps://api.dos.me/v1; usehttps://beta-api.dos.ai/v1for Beta.REVIEW_AI_POINTS_ENABLED=true(kill switch) andREVIEW_AI_MODEL(dosby default, orqwen3.8-max).qwen3.8-maxbatches may wait for Alibaba's off-peak window (16:00 to 02:00 UTC). A batch still running is collected on the next run.--apply --max 20on Beta. It checks thatdosreturns schema JSON withinmax_tokens(Qwen3 may spend tokens on thinking) before the gold set runs.No model was called during development.
🤖 Generated with Claude Code
📌 TL;DR
This PR migrates the AI review extraction job from the Anthropic SDK to the
dos.aigateway's OpenAI-compatible Batch API, replacing Claude models withdosandqwen3.8-max. It updates the client implementation, request formatting, cost calculations, and environment configuration to align with the new provider's constraints and pricing.🎯 Type of Change
🔍 Changes Walkthrough
Docs/Proposals/2026-11-03-ai-review-points.htmldos.aiinstead of Anthropic. Documented new model options (dos,qwen3.8-max), pricing adjustments, and API key changes.apps/importer/.env.exampleDOS_AI_BASE_URL,REVIEW_AI_POINTS_ENABLED, andREVIEW_AI_MODELvariables. Updated comments to clarify thatDOS_AI_API_KEYis now the required credential for this job.apps/importer/package.json@anthropic-ai/sdkdependency as it is no longer used.apps/importer/src/shopee/__tests__/review-ai-points.test.tsdos.aiclient behavior, including batch creation via file upload, result parsing, error handling (402, 404), and cost calculations for the new models.apps/importer/src/shopee/jobs/review-ai-points.tsdosAiReviewAiClientthat implements the OpenAI Batch API (file upload, batch creation, polling, result retrieval). UpdatedBatchRequeststructure to OpenAI format. Added handling forBatchGoneErrorand "unbilled" (402) states.apps/importer/src/shopee/review-ai-prompt.tsREVIEW_AI_MODELSto definedosandqwen3.8-maxwith their specific pricing and monthly caps. Adjusted cache cost factors to 1.0 (upper bound) sincedos.aidoes not publish specific cache rates.📊 Architectural Flow
sequenceDiagram participant Job as review-ai-points.ts participant Client as dosAiReviewAiClient participant Gateway as dos.ai Gateway participant DB as Supabase Job->>Client: createBatch(requests) Client->>Gateway: POST /files (JSONL) Gateway-->>Client: file_id Client->>Gateway: POST /batches (file_id) Gateway-->>Client: batch_id loop Polling Job->>Client: batchStatus(batch_id) Client->>Gateway: GET /batches/{id} Gateway-->>Client: status end Job->>Client: results(batch_id) Client->>Gateway: GET /batches/{id} Gateway-->>Client: output_file_id Client->>Gateway: GET /files/{output_file_id}/content Gateway-->>Client: JSONL Results Client-->>Job: BatchResult[] Job->>DB: Store results & update batch status