Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: preserve newlines in non-streaming LLM response formatting #49

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

EvanNotFound
Copy link

This PR fixes #48

Problem

Currently, all non-JSON responses from LLMs are collapsed into a single line by joining all whitespace:

compact_response = " ".join(content.strip().split())

This makes structured content (lists, paragraphs, code blocks) unreadable and loses important formatting.

Solution

Replace the whitespace collapsing with proper line handling:

lines = content.strip().splitlines()
compact_response = "\n".join(line.strip() for line in lines)

This preserves intentional line breaks while still cleaning up extra whitespace within lines.

- Replace whitespace collapsing with proper line handling
- Use splitlines() to maintain intentional line breaks
- Clean whitespace within lines while keeping structure
- Preserve markdown formatting and readability

Previously, all non-JSON responses were collapsed to a single line,
making structured content like lists and code blocks unreadable.
This change maintains the original line structure while still
cleaning up extra whitespace.
@EvanNotFound EvanNotFound changed the title Preserve newlines in LLM response formatting Preserve newlines in non-streaming LLM response formatting Feb 24, 2025
@EvanNotFound EvanNotFound changed the title Preserve newlines in non-streaming LLM response formatting Fix: preserve newlines in non-streaming LLM response formatting Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Newline characters are stripped from non-streaming LLM responses
1 participant