Commit 12d19211 authored by Your Name's avatar Your Name

Fix whitespace filtering in stream response

- Remove debug print for empty filtered chunks
- Fix strip_tool_calls_from_content to preserve whitespace-only chunks ('\n\n', ' ')
- These whitespace characters are essential for proper message composition
parent fe8b5ea4
...@@ -628,7 +628,11 @@ class ToolCallParser: ...@@ -628,7 +628,11 @@ class ToolCallParser:
# Clean up excessive newlines left from removal # Clean up excessive newlines left from removal
text = re.sub(r'\n{3,}', '\n\n', text) text = re.sub(r'\n{3,}', '\n\n', text)
return text.strip() # Only strip if there's actual content (not just whitespace)
if text.strip():
text = text.strip()
return text
def format_tools_for_prompt(tools: List[Tool], messages: List[ChatMessage]) -> List[ChatMessage]: def format_tools_for_prompt(tools: List[Tool], messages: List[ChatMessage]) -> List[ChatMessage]:
"""Format tools into the system message or add a tool description.""" """Format tools into the system message or add a tool description."""
if not tools: if not tools:
...@@ -4478,10 +4482,7 @@ async def stream_chat_response( ...@@ -4478,10 +4482,7 @@ async def stream_chat_response(
# Always filter out tool call format - some may slip through even without tools # Always filter out tool call format - some may slip through even without tools
filtered_chunk = tool_parser.strip_tool_calls_from_content(filtered_chunk) filtered_chunk = tool_parser.strip_tool_calls_from_content(filtered_chunk)
if not filtered_chunk: # Pass through all content including whitespace - it's essential for message composition
print(f"DEBUG: filtered_chunk was empty (original chunk: {repr(chunk[:50])})")
continue
generated_text += filtered_chunk generated_text += filtered_chunk
data = { data = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment