Skip to content

Add DeepSeek integration for solving images and store API key#3

Open
brawliscool wants to merge 9 commits into
mainfrom
codex/set-api-to-use-gpt-5-nano-model-w4yu0z
Open

Add DeepSeek integration for solving images and store API key#3
brawliscool wants to merge 9 commits into
mainfrom
codex/set-api-to-use-gpt-5-nano-model-w4yu0z

Conversation

@brawliscool
Copy link
Copy Markdown
Owner

Motivation

  • Replace the local mock solution flow with an actual model-based solver to return real step-by-step math solutions from uploaded images.
  • Persist a user-provided DeepSeek API key so solves can be authenticated without exposing keys in code.

Description

  • Added constants for DeepSeek configuration including DEEPSEEK_API_KEY_STORAGE_KEY, DEEPSEEK_MODEL, and DEEPSEEK_MAX_OUTPUT_TOKENS and updated billing/plan logic usage.
  • Implemented getDeepSeekApiKey() to prompt for and persist the API key in localStorage under DEEPSEEK_API_KEY_STORAGE_KEY and validate presence before solving.
  • Implemented parseSolutionPayload() to normalize and parse JSON responses from the model and validate the expected { problem, steps } shape.
  • Implemented generateSolutionWithDeepSeek() which posts to https://api.deepseek.com/chat/completions with the configured model and returns a parsed solution.
  • Replaced the previous mock setTimeout solver with an async call to generateSolutionWithDeepSeek() on solve, added error handling to restore credits on failure, and updated UI state and toasts accordingly.

Testing

  • No automated tests were added or executed as part of this change.

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: b73f027563

ℹ️ 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 Outdated
Comment on lines +414 to +415
const solution = await generateSolutionWithDeepSeek(state.currentImageDataUrl, apiKey);
setSolutionResult(solution);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Prevent stale solve responses from replacing newer results

The async solve callback unconditionally applies setSolutionResult(solution) after awaiting the API call, but it never verifies that this is still the most recent solve request. If the user triggers another solve while an earlier request is still in flight, an older response can arrive later and overwrite the newer result, so the UI can display the wrong solution for the current image.

Useful? React with 👍 / 👎.

Comment thread script.js Outdated
Comment on lines +307 to +308
"Solve the homework from this uploaded image data URL. Respond with strict JSON only: {\"problem\": string, \"steps\": string[]}. Keep steps concise.\n\nImage data URL:\n" +
imageDataUrl,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid embedding full image data URLs in chat prompt

This sends the entire base64 Data URL as plain prompt text, which is extremely large for typical uploaded photos and can exceed model context/request limits or cause frequent request failures and excessive token usage. The solve flow now depends on this path for every request, so reliability drops sharply unless the image is sent via a proper image input mechanism (or aggressively reduced first).

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