Skip to content

Integrate DeepSeek image-to-solution API and replace stubbed solver#5

Open
brawliscool wants to merge 2 commits into
mainfrom
codex/set-api-to-use-gpt-5-nano-model-82bkbo
Open

Integrate DeepSeek image-to-solution API and replace stubbed solver#5
brawliscool wants to merge 2 commits into
mainfrom
codex/set-api-to-use-gpt-5-nano-model-82bkbo

Conversation

@brawliscool
Copy link
Copy Markdown
Owner

Motivation

  • Replace the local stubbed solver with a real model-backed solution generator to process uploaded homework images.
  • Allow using a configurable DeepSeek endpoint and model with persisted API key and configuration to support vision-capable servers.
  • Improve robustness by trying multiple endpoint/model candidates and handling generic fallback responses and server errors.

Description

  • Added DeepSeek-related constants and storage keys such as DEEPSEEK_API_KEY_STORAGE_KEY, DEEPSEEK_BASE_URL_STORAGE_KEY, DEEPSEEK_MODEL_STORAGE_KEY, and DEEPSEEK_MAX_OUTPUT_TOKENS.
  • Implemented helper functions getDeepSeekApiKey, getDeepSeekBaseUrl, and getDeepSeekModelCandidates to obtain saved/configured values and persist them to localStorage.
  • Implemented request/response handling for DeepSeek in 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).
  • Replaced the previous timeout-based stubbed solution in the solve flow with an asynchronous call to generateSolutionWithDeepSeek, added error handling that refunds credits on failure, updates UI status, and surfaces errors via showToast.

Testing

  • No automated tests were added or run for this change.
  • Existing UI behavior for uploads and navigation was preserved and not modified by automated test code.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread script.js
showToast("Solution generated.");
solveTimeoutId = setTimeout(async () => {
try {
const solution = await generateSolutionWithDeepSeek(state.currentImageDataUrl, apiKey);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread script.js
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");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant