Integrate DeepSeek image-to-solution API and replace stubbed solver#5
Integrate DeepSeek image-to-solution API and replace stubbed solver#5brawliscool wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6301e7f953
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| showToast("Solution generated."); | ||
| solveTimeoutId = setTimeout(async () => { | ||
| try { | ||
| const solution = await generateSolutionWithDeepSeek(state.currentImageDataUrl, apiKey); |
There was a problem hiding this comment.
Capture image snapshot before scheduling solve request
The delayed callback sends state.currentImageDataUrl at execution time, not at click time, so if the user uploads/crops/resets a different image during the plan delay, the request will solve the newer image while charging the credit for the original action. This creates incorrect result-credit pairing in normal UI flows where users keep interacting while the skeleton is visible.
Useful? React with 👍 / 👎.
| const isLikelyGenericFallbackSolution = (solution) => { | ||
| const normalizedProblem = String(solution?.problem || "").trim().toLowerCase(); | ||
| const joinedSteps = Array.isArray(solution?.steps) ? solution.steps.join(" ").toLowerCase() : ""; | ||
| return normalizedProblem.includes("solve for x: 3x + 7 = 28") && joinedSteps.includes("3x = 21") && joinedSteps.includes("x = 7"); |
There was a problem hiding this comment.
Avoid rejecting valid solutions via hard-coded fallback pattern
The generic-fallback detector hard-codes one algebra problem/solution pair (3x + 7 = 28) as invalid, which means a legitimate user upload of that exact exercise will always be treated as an error even when the model answer is correct. This causes deterministic false failures for real inputs that match the heuristic.
Useful? React with 👍 / 👎.
Motivation
Description
DEEPSEEK_API_KEY_STORAGE_KEY,DEEPSEEK_BASE_URL_STORAGE_KEY,DEEPSEEK_MODEL_STORAGE_KEY, andDEEPSEEK_MAX_OUTPUT_TOKENS.getDeepSeekApiKey,getDeepSeekBaseUrl, andgetDeepSeekModelCandidatesto obtain saved/configured values and persist them tolocalStorage.generateSolutionWithDeepSeek, including multiple endpoint and model candidates, variants of user messages, JSON-only response parsing (parseSolutionPayload), assistant content extraction, and detection of generic fallback answers (isLikelyGenericFallbackSolution).generateSolutionWithDeepSeek, added error handling that refunds credits on failure, updates UI status, and surfaces errors viashowToast.Testing
Codex Task