mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[GH-ISSUE #9900] Code interpreter doesn't work if the upstream model streams <code_interpreter>...</code_interpreter> into a single chunk #15690
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @xmcp on GitHub (Feb 13, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/9900
Bug Report
Installation Method
docker
Environment
Open WebUI Version: v0.5.11
Ollama (if applicable): N/A
Operating System: Ubuntu 24.04
Browser (if applicable): N/A
Confirmation:
Expected Behavior:
The code interpreter repeatedly fails, causing a dead loop for the model.
Actual Behavior:
The code interpreter should work.
Description
Bug Summary:
I have an OpenAI endpoint that uses fake streaming, i.e., it will put the whole output into a single
text/event-streamchunk when stream=True. In this setup, when using the code interpreter feature, Open WebUI cannot end the<code_interpreter>block successfully, leading to errors when executing the code.Reproduction Details
Steps to Reproduce:
text/event-streamchunkprint the current python version.</code_interpreter>and contents after that are considered part of the code block, leading to aSyntaxError.Logs and Screenshots
Browser Console Logs:

Docker Container Logs:
The above log seems to be printed at middleware.py:1794.
Screenshots/Screen Recordings (if applicable):
Additional Information
I think I know the root cause of this issue, and can contribute a PR for it. I will elaborate in a separate comment below.
@xmcp commented on GitHub (Feb 13, 2025):
The root cause seems to be the
tag_content_handlerfunction inmiddleware.py, which looks like:This function will be called once for each streamed chunk. If
<code_interpreter>...</code_interpreter>is returned within a single chunk, only the code path for the start tag is executed, skipping the code path for the end tag.Therefore, the whole chunk including the content after
</code_interpreter>is incorrectly considered the content in the code block.@xmcp commented on GitHub (Feb 13, 2025):
FYI, the below patch solves this issue in my setup
@tjbck commented on GitHub (Feb 13, 2025):
PR Welcome!
@tjbck commented on GitHub (Feb 14, 2025):
I highly suspect the issue is caused from the model-end. Suggested PR does not resolve the issue entirely.