[GH-ISSUE #6282] Calling openwebui endpoints from within an openwebui function fails. #14303

Closed
opened 2026-04-19 20:42:51 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @XReyRobert on GitHub (Oct 19, 2024).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/6282

Installation Method

  • Deploy openwebui docker ghcr.io/open-webui/open-webui:main
  • Deploy debug function bellow
  • Enable function + Global
  • start a chat
  • Review Log

My debugging function source code

import requests
import json
import time
import uuid

from pydantic import BaseModel, Field


class Filter:

    def __init__(self):
        # Initialize 'valves' with specific configurations
        print("Initializing Filter class with default valves.")
        self.valves = self.Valves()
        self.continuation = False

    class Valves(BaseModel):
        priority: int = Field(
            default=0, description="Priority level for the filter operations."
        )
        max_turns: int = Field(
            default=100, description="Maximum allowable conversation turns for a user."
        )
        enable_status_indicator: bool = Field(
            default=True, description="Enable or disable status indicators."
        )
        api_key: str = Field(
            default="YOUR_API_KEY",
            description="API key for external message transmission.",
        )

    async def emit_status(self, level: str, message: str, done: bool):
        """
        A simple function to print status for debugging purposes.
        """
        print(f"Status: Level={level}, Message='{message}', Done={done}")

    async def outlet(self, body: dict):
        """
        Simplified outlet function to make a single API call with a basic prompt like 'Hello'
        and append the result to the last assistant message.
        """
        print(f"Processing outlet with body: {json.dumps(body, indent=2)}")

        messages = body.get("messages", [])

        # Basic prompt to test the API
        prompt = "Who are you?"

        # API endpoint
        url = "http://localhost/api/chat/completions"

        # Headers for API call
        headers = {
            "Authorization": f"Bearer {self.valves.api_key}",
            "Content-Type": "application/json",
        }

        # Data to send to the API
        data = {
            "model": "qwen2.5:32b",  # Use a test model
            "messages": [{"role": "user", "content": prompt}],
            "stream": False,
        }

        try:
            # Emit a status update before making the request
            await self.emit_status("info", "Sending API request", done=False)

            # Send the POST request to the API
            print(f"Sending API request to {url} with data: {data}")
            response = requests.post(url, headers=headers, json=data, timeout=20)

            # Check if the request was successful
            if response.status_code == 200:
                response_json = response.json()
                print(f"Full response JSON: {response_json}")

                # Extract the message content from the API response
                api_response = response_json.get("message", {}).get("content", "")

                print(f"API response: {api_response}")

                # Find the last assistant message and append the API response
                if messages:
                    for message in reversed(messages):
                        if message.get("role") == "assistant":
                            message[
                                "content"
                            ] += f"\nAPI Response:\n```\n{api_response}\n```"
                            break

                # Emit a success status after processing the response
                await self.emit_status("info", "API call successful", done=True)

            else:
                # Handle the case where the API returns an error
                error_message = (
                    f"Error from API: {response.status_code} - {response.text}"
                )
                print(error_message)
                await self.emit_status("error", error_message, done=True)

        except requests.Timeout:
            error_message = "API request timed out."
            print(error_message)
            await self.emit_status("error", error_message, done=True)

        except Exception as e:
            error_message = f"An error occurred during the API request: {str(e)}"
            print(error_message)
            await self.emit_status("error", error_message, done=True)

        return body

[Describe the method you used to install the project, e.g., git clone, Docker, pip, etc.]

Environment

  • Open WebUI Version: v0.3.32

  • Ollama (if applicable): N/A

  • Operating System: openwebui docker image ghcr.io/open-webui/open-webui:main

  • Browser (if applicable): N/A
    Confirmation:

  • I have read and followed all the instructions provided in the README.md.

  • I am on the latest version of both Open WebUI and Ollama.

  • I have included the browser console logs.

  • I have included the Docker container logs.

  • I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below.

Expected Behavior:

I would expect to be able to connect to the openwebui API Endpoints invoked from the function that should be running within the container

Actual Behavior:

*Endpoint call does timeout

Description

Bug Summary:
[Provide a brief but clear summary of the bug]

Reproduction Details

Steps to Reproduce:
[Outline the steps to reproduce the bug. Be as detailed as possible.]

Logs and Screenshots

Browser Console Logs:
[Include relevant browser console logs, if applicable]

Docker Container Logs:

Processing outlet with body: {
  "model": "qwen2.5:32b",
  "messages": [
    {
      "id": "c1870030-8aab-48f6-b4af-06a9bc76c2f9",
      "role": "user",
      "content": "hello\n"
    },
    {
      "id": "38e06c08-d83e-4e4e-aba3-1c8ceb00658a",
      "role": "assistant",
      "content": "Hello! How can I assist you today? Feel free to ask any detailed questions or discuss specific topics, and I'll do my best to provide in-depth insights. Whether it's science, technology, mathematics, philosophy, or anything else, I'm here to enhance your understanding and stimulate your thinking.",
      "info": {
        "total_duration": 2161149758,
        "load_duration": 33872583,
        "prompt_eval_count": 89,
        "prompt_eval_duration": 128282000,
        "eval_count": 61,
        "eval_duration": 1864779000
      },
      "timestamp": 1729354458
    }
  ],
  "chat_id": "ed236ecc-cd6b-40e7-bd4d-62c58be651ab",
  "session_id": "ahaJY2a6lg-je4v_AAAL",
  "id": "38e06c08-d83e-4e4e-aba3-1c8ceb00658a"
}
Status: Level=info, Message='Sending API request', Done=False
Sending API request to http://localhost:8080/api/chat/completions with data: {'model': 'qwen2.5:32b', 'messages': [{'role': 'user', 'content': 'Who are you?'}], 'stream': False}
API request timed out.
Status: Level=error, Message='API request timed out.', Done=True

Additional Information

  • The equivalent curl command from WITHIN the container shell does succeed.
  • Replacing openwebui url to a ollama endpoint will succeed too....

Note

It might be related to how to docker image is configured, I'm just out of options to try to debug further...

Originally created by @XReyRobert on GitHub (Oct 19, 2024). Original GitHub issue: https://github.com/open-webui/open-webui/issues/6282 ## Installation Method * Deploy openwebui docker ghcr.io/open-webui/open-webui:main * Deploy debug function bellow * Enable function + Global * start a chat * Review Log My debugging function source code ``` import requests import json import time import uuid from pydantic import BaseModel, Field class Filter: def __init__(self): # Initialize 'valves' with specific configurations print("Initializing Filter class with default valves.") self.valves = self.Valves() self.continuation = False class Valves(BaseModel): priority: int = Field( default=0, description="Priority level for the filter operations." ) max_turns: int = Field( default=100, description="Maximum allowable conversation turns for a user." ) enable_status_indicator: bool = Field( default=True, description="Enable or disable status indicators." ) api_key: str = Field( default="YOUR_API_KEY", description="API key for external message transmission.", ) async def emit_status(self, level: str, message: str, done: bool): """ A simple function to print status for debugging purposes. """ print(f"Status: Level={level}, Message='{message}', Done={done}") async def outlet(self, body: dict): """ Simplified outlet function to make a single API call with a basic prompt like 'Hello' and append the result to the last assistant message. """ print(f"Processing outlet with body: {json.dumps(body, indent=2)}") messages = body.get("messages", []) # Basic prompt to test the API prompt = "Who are you?" # API endpoint url = "http://localhost/api/chat/completions" # Headers for API call headers = { "Authorization": f"Bearer {self.valves.api_key}", "Content-Type": "application/json", } # Data to send to the API data = { "model": "qwen2.5:32b", # Use a test model "messages": [{"role": "user", "content": prompt}], "stream": False, } try: # Emit a status update before making the request await self.emit_status("info", "Sending API request", done=False) # Send the POST request to the API print(f"Sending API request to {url} with data: {data}") response = requests.post(url, headers=headers, json=data, timeout=20) # Check if the request was successful if response.status_code == 200: response_json = response.json() print(f"Full response JSON: {response_json}") # Extract the message content from the API response api_response = response_json.get("message", {}).get("content", "") print(f"API response: {api_response}") # Find the last assistant message and append the API response if messages: for message in reversed(messages): if message.get("role") == "assistant": message[ "content" ] += f"\nAPI Response:\n```\n{api_response}\n```" break # Emit a success status after processing the response await self.emit_status("info", "API call successful", done=True) else: # Handle the case where the API returns an error error_message = ( f"Error from API: {response.status_code} - {response.text}" ) print(error_message) await self.emit_status("error", error_message, done=True) except requests.Timeout: error_message = "API request timed out." print(error_message) await self.emit_status("error", error_message, done=True) except Exception as e: error_message = f"An error occurred during the API request: {str(e)}" print(error_message) await self.emit_status("error", error_message, done=True) return body ``` [Describe the method you used to install the project, e.g., git clone, Docker, pip, etc.] ## Environment - **Open WebUI Version:** v0.3.32 - **Ollama (if applicable):** N/A - **Operating System:** openwebui docker image ghcr.io/open-webui/open-webui:main - **Browser (if applicable):** N/A **Confirmation:** - [X] I have read and followed all the instructions provided in the README.md. - [X] I am on the latest version of both Open WebUI and Ollama. - [ ] I have included the browser console logs. - [X] I have included the Docker container logs. - [X] I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below. ## Expected Behavior: I would expect to be able to connect to the openwebui API Endpoints invoked from the function that should be running within the container ## Actual Behavior: *Endpoint call does timeout ## Description **Bug Summary:** [Provide a brief but clear summary of the bug] ## Reproduction Details **Steps to Reproduce:** [Outline the steps to reproduce the bug. Be as detailed as possible.] ## Logs and Screenshots **Browser Console Logs:** [Include relevant browser console logs, if applicable] **Docker Container Logs:** ``` Processing outlet with body: { "model": "qwen2.5:32b", "messages": [ { "id": "c1870030-8aab-48f6-b4af-06a9bc76c2f9", "role": "user", "content": "hello\n" }, { "id": "38e06c08-d83e-4e4e-aba3-1c8ceb00658a", "role": "assistant", "content": "Hello! How can I assist you today? Feel free to ask any detailed questions or discuss specific topics, and I'll do my best to provide in-depth insights. Whether it's science, technology, mathematics, philosophy, or anything else, I'm here to enhance your understanding and stimulate your thinking.", "info": { "total_duration": 2161149758, "load_duration": 33872583, "prompt_eval_count": 89, "prompt_eval_duration": 128282000, "eval_count": 61, "eval_duration": 1864779000 }, "timestamp": 1729354458 } ], "chat_id": "ed236ecc-cd6b-40e7-bd4d-62c58be651ab", "session_id": "ahaJY2a6lg-je4v_AAAL", "id": "38e06c08-d83e-4e4e-aba3-1c8ceb00658a" } Status: Level=info, Message='Sending API request', Done=False Sending API request to http://localhost:8080/api/chat/completions with data: {'model': 'qwen2.5:32b', 'messages': [{'role': 'user', 'content': 'Who are you?'}], 'stream': False} API request timed out. Status: Level=error, Message='API request timed out.', Done=True ``` ## Additional Information * The equivalent curl command from WITHIN the container shell does succeed. * Replacing openwebui url to a ollama endpoint will succeed too.... ## Note It might be related to how to docker image is configured, I'm just out of options to try to debug further...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#14303