fix(agents): normalize single newlines to markdown paragraphs in quiz content#441
Merged
Merged
Conversation
… content LLMs often emit single \\n characters between logical paragraphs in question / answer / explanation fields. In markdown this renders as a soft-break, causing the front-end to collapse everything into one dense block. Add _normalize_markdown_paragraphs() to Generator so that isolated single newlines are turned into \\n\\n paragraph breaks before the payload is returned. Structural markers (lists, code fences, tables, headings) are preserved to avoid breaking intentional formatting. Fixes quiz questions appearing without paragraph spacing in the web UI.
a079af0 to
6ca722c
Compare
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.
Description
Fix quiz question content not rendering with proper paragraph spacing in the web UI.
LLMs often emit single
\ncharacters between logical paragraphs inquestion,correct_answer, andexplanationfields (e.g.(1)…(2)…). In Markdown, a single newline is treated as a soft-break and rendered as a space, causingreact-markdownto collapse everything into one dense<p>block.This PR adds
_normalize_markdown_paragraphs()to theGeneratorclass so that isolated single newlines are converted to\n\nparagraph breaks before the payload is returned. Structural markers (lists, code fences, tables, headings) are preserved to avoid breaking intentional formatting.Related Issues
Module(s) Affected
agentsapiconfigcoreknowledgeloggingservicestoolsutilsweb(Frontend) — indirectly fixes renderingdocs(Documentation)scriptstests...Checklist
pre-commit run --all-filesand fixed any issues.Additional Notes
File changed:
deeptutor/agents/question/agents/generator.pySummary of changes:
_normalize_markdown_paragraphs()static methodquestion,correct_answer, andexplanationfields in_normalize_payload_shape()Before fix (raw LLM output):
已知平面向量 $\boldsymbol{a}=(n,2)$... (1)若 $\boldsymbol{a} \perp \boldsymbol{b}$,求... (2)若 $\boldsymbol{a}$ 与 $\boldsymbol{b}$ 的夹角为锐角...→ Renders as one dense block with no paragraph breaks.
After fix (normalized):
已知平面向量 $\boldsymbol{a}=(n,2)$... (1)若 $\boldsymbol{a} \perp \boldsymbol{b}$,求... (2)若 $\boldsymbol{a}$ 与 $\boldsymbol{b}$ 的夹角为锐角...→ Each sub-question renders as a separate
<p>element, significantly improving readability.Rebased onto: v1.3.7 (latest upstream
main)