Skip to content

docs: note that a match can be split across chunks in the filter stre… - #1798

Open
ninadphalak wants to merge 1 commit into
open-webui:mainfrom
ninadphalak:docs/stream-hook-split-match
Open

ninadphalak wants to merge 1 commit into
open-webui:mainfrom
ninadphalak:docs/stream-hook-split-match

Conversation

@ninadphalak

Copy link
Copy Markdown

Summary

The Filter page lists "real-time content filtering" and "live word replacement" as uses for the stream hook, and its example removes a marker with delta["content"].replace(...). stream() is called once per event, so when the model emits the marker across two chunks, neither call sees it and the text reaches the reader unchanged. This adds a short note under that example that says so, and points to the two options the page already describes: keep per-reply state and hold back a possible match start, or use outlet(), which sees the whole message but runs after the chunks were delivered.

It saves filter authors from finding this out in production, where it shows up as a rule that works most of the time.

Related issue or discussion

None.

Checklist

  • I have reviewed the relevant documentation and matched the existing style.
  • This PR meets Open WebUI's contribution standards: it is accurate, relevant to users, narrowly scoped, maintainable, and not promotional content, advertising, lead generation, SEO placement, or a request to list a product, service, provider, integration, gateway, tool, or company primarily for visibility.
  • I understand that PRs that do not meet these standards may be closed without review and will not be merged. Repeated, low-quality, off-topic, promotional, or intentionally misleading submissions may result in the contributor being blocked from future participation in Open WebUI repositories.

Notes for reviewers

Checked against open-webui at 926f826 (0.13.5):

  • backend/open_webui/utils/middleware.py lines 5014-5026: each SSE data: line is parsed and passed to process_filter_functions(filter_type='stream', form_data=data) on its own. Lines 6709-6716 and 6739-6748 do the same on the direct API path.
  • backend/open_webui/utils/filter.py line 136: the handler receives that single event as event.

Running the page's own example over the text Hi [redacted] there cut in two at every position leaves the marker in the output for 10 of the 18 cuts (every cut that falls inside the marker). A version that holds back a possible match start in per-reply state gives the same result as a whole-text replace for all 18 cuts and for one character per chunk.

npm run build passes with the change (the note links to the existing "Correlating one stream" heading), as do npm run prettier:check, npm run lint and npm run test:docs-search.

This branch has not been deployed

No deployments
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.

1 participant