Add DeepSeek integration for solving images and store API key#3
Add DeepSeek integration for solving images and store API key#3brawliscool wants to merge 9 commits into
Conversation
…o-model Integrate OpenAI Responses API for image-based solving with gpt-5-nano
There was a problem hiding this comment.
💡 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".
| const solution = await generateSolutionWithDeepSeek(state.currentImageDataUrl, apiKey); | ||
| setSolutionResult(solution); |
There was a problem hiding this comment.
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 👍 / 👎.
| "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, |
There was a problem hiding this comment.
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 👍 / 👎.
Motivation
Description
DEEPSEEK_API_KEY_STORAGE_KEY,DEEPSEEK_MODEL, andDEEPSEEK_MAX_OUTPUT_TOKENSand updated billing/plan logic usage.getDeepSeekApiKey()to prompt for and persist the API key inlocalStorageunderDEEPSEEK_API_KEY_STORAGE_KEYand validate presence before solving.parseSolutionPayload()to normalize and parse JSON responses from the model and validate the expected{ problem, steps }shape.generateSolutionWithDeepSeek()which posts tohttps://api.deepseek.com/chat/completionswith the configured model and returns a parsed solution.setTimeoutsolver with an async call togenerateSolutionWithDeepSeek()on solve, added error handling to restore credits on failure, and updated UI state and toasts accordingly.Testing
Codex Task