Skip to content

fix: strip <think>/<precontext> from live stream deltas (#4) - #11

Merged
Khurdhula-Harshavardhan merged 1 commit into
mainfrom
fix/stream-tag-filter
Jul 20, 2026
Merged

fix: strip <think>/<precontext> from live stream deltas (#4)#11
Khurdhula-Harshavardhan merged 1 commit into
mainfrom
fix/stream-tag-filter

Conversation

@Abhinavexist

Copy link
Copy Markdown
Collaborator

Fixes#4

Problem

Interfaze streams side-channels inline in content as <precontext>…</precontext> and <think>…</think>. The SDK stripped them only from the aggregated accessors (text, get_final_completion()). Anyone rendering tokens live — iterating the stream directly or using the plain create(stream=True) drop-in path — saw the raw tags in delta.content.

Fix

Add InterfazeStream.text_deltas() (sync and async): a delta-level filtered iterator that yields visible text only.

  • Strips both <think> and <precontext> blocks incrementally.
  • Buffers a trailing partial that could be a split tag (<prec | ontext>) instead of leaking it.
  • Never withholds text that cannot be a tag (a literal < is emitted; it does not block waiting for a close tag that may never arrive — side-channels are conditional on the header / absent under a schema).
  • reasoning and precontext remain available on get_final_completion().

README's streaming example now uses text_deltas() and documents that raw deltas are unfiltered (implements the issue's "provide a filtered helper + document" resolution).

Tests

5 new: precontext stripped, think stripped, tag split across chunks, literal < preserved, and async text_deltas. Suite: 29 passing; ruff + mypy --strict clean.

Interfaze streams side-channels inline in content as <think>…</think> and
<precontext>…</precontext>. The SDK stripped them only from the aggregated
accessors, so live token consumers (raw deltas / create(stream=True)) saw
the raw tags in delta.content.
Add InterfazeStream.text_deltas() (sync + async): a delta-level filtered
iterator that strips both tag types, buffering across chunk boundaries for
split tags and never withholding text that cannot be a tag. reasoning and
precontext remain available on get_final_completion(). README now steers
live rendering to text_deltas().

@Khurdhula-HarshavardhanKhurdhula-Harshavardhan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@Khurdhula-Harshavardhan
Khurdhula-Harshavardhan deleted the fix/stream-tag-filter branch July 20, 2026 23:28
Abhinavexist added a commit that referenced this pull request Jul 21, 2026
…est-id, escape hatches
- #1 .stream() now yields OpenAI ChatCompletionStreamEvents (content.delta/done,
tool-call events) via ChatCompletionStreamState; <think>/<precontext> stripped from
content events; text_deltas() for plain tokens; create(stream=True) unchanged.
- #2 streamed usage + system_fingerprint captured on get_final_completion().
- #3 _request_id carried onto the returned completion.
- #6 parse()/with_raw_response/with_streaming_response exposed on the wrapper
(no more AttributeError; parse delegates to the OpenAI client, model default + guard).
Rebased onto main (post #7#11).
Abhinavexist added a commit that referenced this pull request Jul 22, 2026
…est-id, escape hatches
- #1 .stream() now yields OpenAI ChatCompletionStreamEvents (content.delta/done,
tool-call events) via ChatCompletionStreamState; <think>/<precontext> stripped from
content events; text_deltas() for plain tokens; create(stream=True) unchanged.
- #2 streamed usage + system_fingerprint captured on get_final_completion().
- #3 _request_id carried onto the returned completion.
- #6 parse()/with_raw_response/with_streaming_response exposed on the wrapper
(no more AttributeError; parse delegates to the OpenAI client, model default + guard).
Rebased onto main (post #7#11).
Abhinavexist added a commit that referenced this pull request Jul 22, 2026
…est-id, escape hatches (#20)
- #1 .stream() now yields OpenAI ChatCompletionStreamEvents (content.delta/done,
tool-call events) via ChatCompletionStreamState; <think>/<precontext> stripped from
content events; text_deltas() for plain tokens; create(stream=True) unchanged.
- #2 streamed usage + system_fingerprint captured on get_final_completion().
- #3 _request_id carried onto the returned completion.
- #6 parse()/with_raw_response/with_streaming_response exposed on the wrapper
(no more AttributeError; parse delegates to the OpenAI client, model default + guard).
Rebased onto main (post #7#11).
Sign up for freeto 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.

Streamed <precontext>/<think> tags leak to live consumers

2 participants

@Abhinavexist@Khurdhula-Harshavardhan