Source code for nv_ingest_api.util.string_processing

# SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES.
# All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import logging
import re

logger = logging.getLogger(__name__)

DEPLOT_MAX_TOKENS = 128
DEPLOT_TEMPERATURE = 1.0
DEPLOT_TOP_P = 1.0


[docs] def remove_url_endpoints(url) -> str: """Some configurations provide the full endpoint in the URL. Ex: http://deplot:8000/v1/chat/completions. For hitting the health endpoint we need to get just the hostname:port combo that we can append the health/ready endpoint to so we attempt to parse that information here. Args: url str: Incoming URL Returns: str: URL with just the hostname:port portion remaining """ if "/v1" in url: url = url.split("/v1")[0] return url
[docs] def generate_url(url) -> str: """Examines the user defined URL for http*://. If that pattern is detected the URL is used as provided by the user. If that pattern does not exist then the assumption is made that the endpoint is simply `http://` and that is prepended to the user supplied endpoint. Args: url str: Endpoint where the Rest service is running Returns: str: Fully validated URL """ if not re.match(r"^https?://", url): # Add the default `http://` if it's not already present in the URL url = f"http://{url}" return url