Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

Summary

  • What: Fix streaming response parsing in orchestrate_content.py to correctly parse Ollama's newline-delimited JSON format.
  • Why: Previous implementation concatenated raw JSON bytes instead of extracting response text from JSON objects, resulting in malformed content.

Changes

  • Parse streaming chunks as newline-delimited JSON objects, extracting the "response" field from each line
  • Buffer incomplete lines across chunk boundaries for proper JSON parsing
  • Extract helper function process_json_line to eliminate code duplication

Before:

chunks = []
async for chunk in resp.content.iter_chunked(1024):
    chunks.append(chunk)
text = b"".join(chunks).decode("utf-8", errors="ignore")

After:

buffer = ""
response_parts = []
async for chunk in resp.content.iter_chunked(1024):
    buffer += chunk.decode("utf-8", errors="ignore")
    while "\n" in buffer:
        line, buffer = buffer.split("\n", 1)
        json_obj = json.loads(line.strip())
        response_parts.append(json_obj["response"])
text = "".join(response_parts)

Testing

  • All existing unit tests pass (test_orchestrate_content.py)
  • Streaming mode test validates TTFT capture and response text extraction

Checklist

  • Streaming parser correctly handles newline-delimited JSON
  • Response text properly extracted from "response" field
  • Code duplication eliminated
  • All tests pass

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 17, 2026 18:51
Co-authored-by: 73junito <86015877+73junito@users.noreply.github.com>
Co-authored-by: 73junito <86015877+73junito@users.noreply.github.com>
Copilot AI changed the title [WIP] Addressing feedback from PR #158 review comments Fix Ollama streaming response parser to handle newline-delimited JSON Jan 17, 2026
Copilot AI requested a review from 73junito January 17, 2026 18:54
Copy link
Owner

@73junito 73junito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewed

@73junito 73junito marked this pull request as ready for review January 17, 2026 19:06
Copilot AI review requested due to automatic review settings January 17, 2026 19:06
@73junito 73junito merged commit f0fd0a8 into merge/pr-158-local Jan 17, 2026
4 of 7 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the Ollama streaming response parser to correctly handle newline-delimited JSON format. The previous implementation incorrectly concatenated raw JSON bytes, while the updated code properly parses each JSON line and extracts the response text field.

Changes:

  • Parse streaming chunks as newline-delimited JSON objects, extracting the "response" field from each line
  • Buffer incomplete lines across chunk boundaries for proper JSON parsing
  • Extract helper function process_json_line to handle JSON line processing with error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants