[GH-ISSUE #11166] Entire website freeze when pipeline wait API to response #135859

Closed
opened 2026-05-25 03:03:15 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @KenKout on GitHub (Mar 4, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/11166

Bug Report

Installation Method

Docker Compose

Environment

  • Open WebUI Version: v0.5.18

Description

Bug Summary:
I use sonar-deep-research by using this pipeline to show citations and got this issue

Reproduction Details

Steps to Reproduce:

  1. Using this pipelines:
from pydantic import BaseModel, Field
from typing import Optional, Union, Generator, Iterator
from open_webui.utils.misc import get_last_user_message
from open_webui.utils.misc import pop_system_message

import os
import json
import time
import requests


class Pipe:
    class Valves(BaseModel):
        NAME_PREFIX: str = Field(
            default="Perplexity/",
            description="The prefix applied before the model names.",
        )
        PERPLEXITY_API_BASE_URL: str = Field(
            default="https://api.perplexity.ai",
            description="The base URL for Perplexity API endpoints.",
        )
        PERPLEXITY_API_KEY: str = Field(
            default="",
            description="Required API key to access Perplexity services.",
        )

    def __init__(self):
        self.type = "manifold"
        self.valves = self.Valves()

    def pipes(self):
        return [
            {
                "id": "sonar-reasoning-pro",
                "name": f"Sonar Reasoning Pro 128k 8k output",
            },
            {
                "id": "sonar-reasoning",
                "name": f"Sonar Reasoning 128k 8k output",
            },
            {
                "id": "sonar-pro",
                "name": f"Sonar Pro 200k",
            },
            {
                "id": "sonar",
                "name": f"Sonar 128k",
            },
            {
                "id": "r1-1776",
                "name": f"Deepseek-R1 128k",
            },
            {
                "id": "sonar-deep-research",
                "name": f"Sonar Deep Research 60k",
            },
        ]

    def pipe(self, body: dict, __user__: dict) -> Union[str, Generator, Iterator]:
        print(f"pipe:{__name__}")

        if not self.valves.PERPLEXITY_API_KEY:
            raise Exception("PERPLEXITY_API_KEY not provided in the valves.")

        headers = {
            "Authorization": f"Bearer {self.valves.PERPLEXITY_API_KEY}",
            "Content-Type": "application/json",
            "accept": "application/json",
        }

        system_message, messages = pop_system_message(body.get("messages", []))
        system_prompt = "You are a helpful assistant."
        if system_message is not None:
            system_prompt = system_message["content"]

        model_id = body["model"]
        if model_id.startswith(self.valves.NAME_PREFIX):
            model_id = model_id[len(self.valves.NAME_PREFIX) :]
        if model_id.startswith("perplexity."):
            model_id = model_id[len("perplexity.") :]

        payload = {
            "model": model_id,
            "messages": [{"role": "system", "content": system_prompt}, *messages],
            "stream": body.get("stream", True),
            "return_citations": True,
            "return_images": True,
        }

        url = f"{self.valves.PERPLEXITY_API_BASE_URL}/chat/completions"

        try:
            if body.get("stream", False):
                return self.stream_response(url, headers, payload)
            else:
                return self.non_stream_response(url, headers, payload)
        except requests.exceptions.RequestException as e:
            print(f"Request failed: {e}")
            return f"Error: Request failed: {e}"
        except Exception as e:
            print(f"Error in pipe method: {e}")
            return f"Error: {e}"

    def stream_response(self, url, headers, payload):
        try:
            with requests.post(
                url, headers=headers, json=payload, stream=True, timeout=(3.05, 300)
            ) as response:
                if response.status_code != 200:
                    raise Exception(
                        f"HTTP Error {response.status_code}: {response.text}"
                    )

                data = None

                for line in response.iter_lines():
                    if line:
                        line = line.decode("utf-8")
                        if line.startswith("data: "):
                            try:
                                data = json.loads(line[6:])
                                yield data["choices"][0]["delta"]["content"]

                                time.sleep(
                                    0.01
                                )  # Delay to avoid overwhelming the client

                            except json.JSONDecodeError:
                                print(f"Failed to parse JSON: {line}")
                            except KeyError as e:
                                print(f"Unexpected data structure: {e}")
                                print(f"Full data: {data}")
                citations = data.get("citations", [])
                citations_string = "\n".join(
                    [f"[{i+1}] {url}" for i, url in enumerate(citations)]
                )
                yield "\n\n" + citations_string
        except requests.exceptions.RequestException as e:
            print(f"Request failed: {e}")
            yield f"Error: Request failed: {e}"
        except Exception as e:
            print(f"General error in stream_response method: {e}")
            yield f"Error: {e}"

    def non_stream_response(self, url, headers, payload):
        try:
            response = requests.post(
                url, headers=headers, json=payload, timeout=(3.05, 300)
            )
            if response.status_code != 200:
                raise Exception(f"HTTP Error {response.status_code}: {response.text}")

            res = response.json()
            citations = res.get("citations", [])
            citations_string = "\n".join(
                [f"[{i+1}] {url}" for i, url in enumerate(citations)]
            )
            return res["choices"][0]["message"]["content"] + "\n\n" + citations_string
        except requests.exceptions.RequestException as e:
            print(f"Failed non-stream request: {e}")
            return f"Error: {e}"
  1. Choose Sonar Deep Research
  2. Enter the prompt that take times to response
  3. Come to incognito mode and try to connect to website

Logs and Screenshots

Screenshots/Screen Recordings (if applicable):

https://github.com/user-attachments/assets/94079e1e-0e6d-4c3a-a2f4-c3779e28727d

Potential issue

https://stackoverflow.com/questions/71516140/fastapi-runs-api-calls-in-serial-instead-of-parallel-fashion

Originally created by @KenKout on GitHub (Mar 4, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/11166 # Bug Report ## Installation Method Docker Compose ## Environment - **Open WebUI Version:** v0.5.18 ## Description **Bug Summary:** I use sonar-deep-research by using this pipeline to show citations and got this issue ## Reproduction Details **Steps to Reproduce:** 1. Using this pipelines: ```python from pydantic import BaseModel, Field from typing import Optional, Union, Generator, Iterator from open_webui.utils.misc import get_last_user_message from open_webui.utils.misc import pop_system_message import os import json import time import requests class Pipe: class Valves(BaseModel): NAME_PREFIX: str = Field( default="Perplexity/", description="The prefix applied before the model names.", ) PERPLEXITY_API_BASE_URL: str = Field( default="https://api.perplexity.ai", description="The base URL for Perplexity API endpoints.", ) PERPLEXITY_API_KEY: str = Field( default="", description="Required API key to access Perplexity services.", ) def __init__(self): self.type = "manifold" self.valves = self.Valves() def pipes(self): return [ { "id": "sonar-reasoning-pro", "name": f"Sonar Reasoning Pro 128k 8k output", }, { "id": "sonar-reasoning", "name": f"Sonar Reasoning 128k 8k output", }, { "id": "sonar-pro", "name": f"Sonar Pro 200k", }, { "id": "sonar", "name": f"Sonar 128k", }, { "id": "r1-1776", "name": f"Deepseek-R1 128k", }, { "id": "sonar-deep-research", "name": f"Sonar Deep Research 60k", }, ] def pipe(self, body: dict, __user__: dict) -> Union[str, Generator, Iterator]: print(f"pipe:{__name__}") if not self.valves.PERPLEXITY_API_KEY: raise Exception("PERPLEXITY_API_KEY not provided in the valves.") headers = { "Authorization": f"Bearer {self.valves.PERPLEXITY_API_KEY}", "Content-Type": "application/json", "accept": "application/json", } system_message, messages = pop_system_message(body.get("messages", [])) system_prompt = "You are a helpful assistant." if system_message is not None: system_prompt = system_message["content"] model_id = body["model"] if model_id.startswith(self.valves.NAME_PREFIX): model_id = model_id[len(self.valves.NAME_PREFIX) :] if model_id.startswith("perplexity."): model_id = model_id[len("perplexity.") :] payload = { "model": model_id, "messages": [{"role": "system", "content": system_prompt}, *messages], "stream": body.get("stream", True), "return_citations": True, "return_images": True, } url = f"{self.valves.PERPLEXITY_API_BASE_URL}/chat/completions" try: if body.get("stream", False): return self.stream_response(url, headers, payload) else: return self.non_stream_response(url, headers, payload) except requests.exceptions.RequestException as e: print(f"Request failed: {e}") return f"Error: Request failed: {e}" except Exception as e: print(f"Error in pipe method: {e}") return f"Error: {e}" def stream_response(self, url, headers, payload): try: with requests.post( url, headers=headers, json=payload, stream=True, timeout=(3.05, 300) ) as response: if response.status_code != 200: raise Exception( f"HTTP Error {response.status_code}: {response.text}" ) data = None for line in response.iter_lines(): if line: line = line.decode("utf-8") if line.startswith("data: "): try: data = json.loads(line[6:]) yield data["choices"][0]["delta"]["content"] time.sleep( 0.01 ) # Delay to avoid overwhelming the client except json.JSONDecodeError: print(f"Failed to parse JSON: {line}") except KeyError as e: print(f"Unexpected data structure: {e}") print(f"Full data: {data}") citations = data.get("citations", []) citations_string = "\n".join( [f"[{i+1}] {url}" for i, url in enumerate(citations)] ) yield "\n\n" + citations_string except requests.exceptions.RequestException as e: print(f"Request failed: {e}") yield f"Error: Request failed: {e}" except Exception as e: print(f"General error in stream_response method: {e}") yield f"Error: {e}" def non_stream_response(self, url, headers, payload): try: response = requests.post( url, headers=headers, json=payload, timeout=(3.05, 300) ) if response.status_code != 200: raise Exception(f"HTTP Error {response.status_code}: {response.text}") res = response.json() citations = res.get("citations", []) citations_string = "\n".join( [f"[{i+1}] {url}" for i, url in enumerate(citations)] ) return res["choices"][0]["message"]["content"] + "\n\n" + citations_string except requests.exceptions.RequestException as e: print(f"Failed non-stream request: {e}") return f"Error: {e}" ``` 2. Choose Sonar Deep Research 3. Enter the prompt that take times to response 4. Come to incognito mode and try to connect to website ## Logs and Screenshots **Screenshots/Screen Recordings (if applicable):** https://github.com/user-attachments/assets/94079e1e-0e6d-4c3a-a2f4-c3779e28727d ## Potential issue https://stackoverflow.com/questions/71516140/fastapi-runs-api-calls-in-serial-instead-of-parallel-fashion
Author
Owner

@tjbck commented on GitHub (Mar 4, 2025):

async should be used.

<!-- gh-comment-id:2698874314 --> @tjbck commented on GitHub (Mar 4, 2025): `async` should be used.
Author
Owner

@KenKout commented on GitHub (Mar 5, 2025):

May I ask you if you have any script that uses async ? I have tried many times but none of it worked

<!-- gh-comment-id:2699784222 --> @KenKout commented on GitHub (Mar 5, 2025): May I ask you if you have any script that uses async ? I have tried many times but none of it worked
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#135859