Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/grading/grading.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,14 +641,21 @@ export async function gradeDetailedLLM(frontUrl, backUrl, config, extraImages =
const apiKey = process.env.ANTHROPIC_API_KEY;
let detectTokens = { input: 0, output: 0 };

const togetherKey = process.env.TOGETHER_API_KEY;
const rawTogetherKey = process.env.TOGETHER_API_KEY;
const togetherKey = rawTogetherKey && rawTogetherKey.length > 20 ? rawTogetherKey : null;
const detectOpts = togetherKey
? { provider: "together", togetherKey }
: {};
const detectModel = togetherKey ? null : "claude-sonnet-4-6";
const detectJobs = [detectAndCropCard(frontUrl, apiKey, detectModel, detectOpts)];
if (hasBack) detectJobs.push(detectAndCropCard(backUrl, apiKey, detectModel, detectOpts));
const [frontDetect, backDetect] = await Promise.all(detectJobs);
let frontDetect = { imageUrl: frontUrl, cropped: false };
let backDetect = hasBack ? { imageUrl: backUrl, cropped: false } : null;
try {
const detectJobs = [detectAndCropCard(frontUrl, apiKey, detectModel, detectOpts)];
if (hasBack) detectJobs.push(detectAndCropCard(backUrl, apiKey, detectModel, detectOpts));
[frontDetect, backDetect] = await Promise.all(detectJobs);
} catch (e) {
console.warn(`[grade] card detection failed, using original images: ${e.message || e}`);
}

const frontBlock = frontDetect.cropped
? imageBlockFromBase64(frontDetect.base64, frontDetect.mediaType)
Expand Down Expand Up @@ -801,8 +808,8 @@ export async function gradeImage(imageUrl, config, extraImages = [], centeringHi
if (config.aiGrading.mode === "llm") {
const backImg = extraImages[0]?.imageUrl || extraImages[0] || null;
const remainingExtras = extraImages.slice(1);
if (backImg && config.aiGrading.llm.provider === "claude") {
result = await gradeDetailedLLM(imageUrl, backImg, config, remainingExtras, centeringHint);
if (config.aiGrading.llm.provider === "claude") {
result = await gradeDetailedLLM(imageUrl, backImg || null, config, remainingExtras, centeringHint);
}
if (!result) {
result = await gradeViaLLM(imageUrl, config, extraImages);
Expand Down
Loading