Repository navigation
fix(generation): stop creative-space generations failing on Anki metadata validation - #63
Merged
Merged
Conversation
The Anki schema required metadata.cardTypes, but the Anki prompt never asks
the model to emit it, so every Anki generation died at final validation with
AI_NoObjectGeneratedError ("No object generated: response did not match
schema"). The mind map, quiz and Anki schemas also required chunkIds even
though aggregateNotebookContent never exposes chunk IDs to the model and the
prompts only ask for them "whenever possible" (尽可能); a single omitted field
discarded the entire generation. Anki card text additionally carried max()
caps the prompt never states, so a long answer failed the same way.
- Anki: metadata is optional and totalCards/cardTypes are derived from the
generated cards; chunkIds defaults to [] and the undeclared text caps are
removed.
- Mind map / quiz: chunkIds defaults to [].
Verified by running the real generation path against the configured
DeepSeek connection: Anki went from a schema validation failure to a
successful 4-card result; mind map and quiz already succeeded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes the Anki, mind map and quiz generators stop discarding an entire result when the model omits a field the prompts never required. Concretely, Anki card generation now succeeds instead of always ending in a failed item, and chunk IDs are treated as the best-effort field the prompts describe.
Why?
In the creative space, creating Anki cards always failed after the model finished streaming, and chart/quiz creation was exposed to the same class of failure. The root cause is that the Zod schemas used for
streamObjectare stricter than the prompts:createAnkiSchemarequiredmetadata.cardTypes: string[], but the Anki prompt's output format only mentionsmetadata.totalCards. The model follows the prompt, omitscardTypes, and final validation throwsAI_NoObjectGeneratedError: No object generated: response did not match schemawithpath: ["metadata","cardTypes"], expected "array", received undefined.aggregateNotebookContentnever passes chunk IDs to the model — only the chunk text — while the prompts ask for chunk IDs only "whenever possible" (尽可能). YetchunkIdswas required, so one omitted node/card/question field failed the whole generation.front max(300),back max(500), etc., which the Anki prompt never states, so a long answer could fail the same way.Related issue
None.
What changed?
AnkiCardService:metadatais now optional andtotalCards/cardTypesare derived from the generatedcards;chunkIdsdefaults to[]; the undeclaredmax()caps on card text are removed.MindMapService/QuizService:chunkIdsdefaults to[]. The existingvalidateAndClean*code already filters invalid IDs and rebuilds the chunk mapping, so this only affects the "model omitted them" case.Verification
npm run typecheck— passnpm test— 49/49 passnpm run build— passelectron-vite dev): ran the real generation path against the configuredopenai-completions/api.deepseek.comconnection.No object generated: response did not match schema(missingmetadata.cardTypes).cardTypes=basic; mind map and quiz already succeeded and still do.No new tests were added: the generation services are not unit-testable without a model connection, and the schemas are module-private. The prompt/schema mismatch is covered by the manual verification above.