Skip to content

utils

Client for the Utils endpoints.

Classes

UtilsClient

UtilsClient(client: OWUIClientBase)

Bases: ResourceBase

Client for utility operations such as Gravatar, code formatting/execution, markdown conversion, and database downloads.

Source code in src/owui_client/client_base.py
def __init__(self, client: OWUIClientBase):
    self._client = client

Functions

get_gravatar
get_gravatar(email: str) -> str

Get the Gravatar URL for a given email address.

Parameters:

Name Type Description Default
email str

The email address to retrieve the Gravatar URL for.

required

Returns:

Type Description
str

The URL of the Gravatar image.

Source code in src/owui_client/routers/utils.py
async def get_gravatar(self, email: str) -> str:
    """
    Get the Gravatar URL for a given email address.

    Args:
        email: The email address to retrieve the Gravatar URL for.

    Returns:
        The URL of the Gravatar image.
    """
    return await self._request("GET", "/v1/utils/gravatar", params={"email": email})
format_code
format_code(form_data: CodeForm) -> Dict[str, str]

Format the provided code using Black (Python formatter).

Parameters:

Name Type Description Default
form_data CodeForm

The CodeForm containing the code to format.

required

Returns:

Type Description
Dict[str, str]

A dictionary containing the formatted code under the "code" key.

Source code in src/owui_client/routers/utils.py
async def format_code(self, form_data: CodeForm) -> Dict[str, str]:
    """
    Format the provided code using Black (Python formatter).

    Args:
        form_data: The `CodeForm` containing the code to format.

    Returns:
        A dictionary containing the formatted code under the "code" key.
    """
    return await self._request("POST", "/v1/utils/code/format", json=form_data.model_dump())
execute_code
execute_code(form_data: CodeForm) -> Dict

Execute the provided code using a Jupyter kernel.

Note: Code execution must be enabled and configured (e.g., Jupyter URL) on the server.

Parameters:

Name Type Description Default
form_data CodeForm

The CodeForm containing the code to execute.

required

Returns:

Type Description
Dict

The output of the code execution from Jupyter.

Raises:

Type Description
HTTPException

If the code execution engine is not supported or configured.

Source code in src/owui_client/routers/utils.py
async def execute_code(self, form_data: CodeForm) -> Dict:
    """
    Execute the provided code using a Jupyter kernel.

    Note: Code execution must be enabled and configured (e.g., Jupyter URL) on the server.

    Args:
        form_data: The `CodeForm` containing the code to execute.

    Returns:
        The output of the code execution from Jupyter.

    Raises:
        HTTPException: If the code execution engine is not supported or configured.
    """
    return await self._request("POST", "/v1/utils/code/execute", json=form_data.model_dump())
get_html_from_markdown
get_html_from_markdown(
    form_data: MarkdownForm,
) -> Dict[str, str]

Convert Markdown content to HTML.

Parameters:

Name Type Description Default
form_data MarkdownForm

The MarkdownForm containing the markdown content.

required

Returns:

Type Description
Dict[str, str]

A dictionary containing the generated HTML under the "html" key.

Source code in src/owui_client/routers/utils.py
async def get_html_from_markdown(self, form_data: MarkdownForm) -> Dict[str, str]:
    """
    Convert Markdown content to HTML.

    Args:
        form_data: The `MarkdownForm` containing the markdown content.

    Returns:
        A dictionary containing the generated HTML under the "html" key.
    """
    return await self._request("POST", "/v1/utils/markdown", json=form_data.model_dump())
download_chat_as_pdf
download_chat_as_pdf(
    form_data: ChatTitleMessagesForm,
) -> bytes

Generate and download a PDF version of a chat.

Parameters:

Name Type Description Default
form_data ChatTitleMessagesForm

The ChatTitleMessagesForm containing chat title and messages.

required

Returns:

Type Description
bytes

The PDF file content as bytes.

Source code in src/owui_client/routers/utils.py
async def download_chat_as_pdf(self, form_data: ChatTitleMessagesForm) -> bytes:
    """
    Generate and download a PDF version of a chat.

    Args:
        form_data: The `ChatTitleMessagesForm` containing chat title and messages.

    Returns:
        The PDF file content as bytes.
    """
    return await self._request("POST", "/v1/utils/pdf", model=bytes, json=form_data.model_dump())
download_db
download_db() -> bytes

Download the database file.

Note: Requires admin privileges and ENABLE_ADMIN_EXPORT must be True. Only supported for SQLite databases.

Returns:

Type Description
bytes

The database file content as bytes.

Raises:

Type Description
HTTPException

If access is prohibited or the database is not SQLite.

Source code in src/owui_client/routers/utils.py
async def download_db(self) -> bytes:
    """
    Download the database file.

    Note: Requires admin privileges and `ENABLE_ADMIN_EXPORT` must be True.
    Only supported for SQLite databases.

    Returns:
        The database file content as bytes.

    Raises:
        HTTPException: If access is prohibited or the database is not SQLite.
    """
    return await self._request("GET", "/v1/utils/db/download", model=bytes)