# Open Web UI Stream Chunk Filter for Zed IDE This adapter script resolves the following error in Zed IDE: ``` data did not match any variant of untagged enum ResponseStreamResult ``` which occurs when using a custom Open Web UI model (pipe functions). Open Web UI sends invalid chunks in the stream, causing parsing exceptions. --- ## What the adapter does - Proxies requests to Open Web UI - Filters out and removes invalid chunks from the stream, allowing Zed IDE to properly receive responses - Supports streaming - Allows overriding system messages in requests (optional) - **Simulates OpenAI-style function calling (`tool_calls`) using special stream markers** controlled by the environment variable `EMULATE_TOOLS_CALLING` (default: enabled) --- ## Tool Calling Emulation If your model outputs function definitions inside the following block: ``` { ... json ... } ``` The adapter will: - Detect the block - Extract and parse the JSON - Convert it into OpenAI-compatible `tool_calls` chunks - Send those chunks to the client as if native function calling were supported ### Expected JSON Structure The JSON inside `...` must have the following structure: ```json { "model": "", "functions": [ { "index": , "function_call": { "name": "", "arguments": "" }, } ] } ``` Notes: - The `arguments` field must be a valid **stringified JSON object** - The outer structure must contain a `functions` list - Each entry represents one tool call --- ## Usage 1. Clone or download the script 2. Set environment variables: - `OPENWEBUI_URL` — URL of your Open Web UI server - `OPENWEBUI_API_KEY` — API key for access - (optional) `ZED_SYSTEM_PROMPT_FILE` — path to a file with a system prompt - (optional) `ZED_SYSTEM_PROMPT_MODE` — mode for handling system messages, one of: - `default` (leave system messages unchanged) - `replace` (replace all system messages with the one from the file) - `disable` (remove all system messages) - (optional) `EMULATE_TOOLS_CALLING` — `true` or `false` to enable/disable tool calling emulation (default: `true`) 3. Install dependencies: ```bash pip install fastapi httpx uvicorn python-dotenv ``` 4. Run the server: ```bash python OpenWEBUI_tool_calling_proxy.py ``` 5. Configure Zed IDE to use this proxy instead of a direct connection to Open Web UI --- ## Important notes - The invalid chunk issue only occurs with Open Web UI custom models (pipe functions) - Models served via OpenRouter are not affected - The tool calling emulation requires output in the `...` format - This is a temporary and pragmatic workaround to enable compatibility with OpenAI-like clients --- If you have any questions, feel free to reach out. --- Author: Savkin Vladimir Date: 2025