tabbyAPI-ollama/start.py
kingbri bb7a8e4614 Config: Add override argparser
Add an argparser that casts over to dictionaries of subgroups to
integrate with the config.

This argparser doesn't contain everything in the config due to complexity
issues with CLI args, but will eventually progress to parity. In addition,
it's used to override the config.yml rather than replace it.

A config arg is also provided if the user wants to fully override the
config yaml with another file path.

Signed-off-by: kingbri <bdashore3@proton.me>
2024-01-01 14:27:12 -05:00

64 lines
1.9 KiB
Python

"""Utility to automatically upgrade and start the API"""
import argparse
import os
import pathlib
import subprocess
from args import convert_args_to_dict, init_argparser
def get_requirements_file():
"""Fetches the appropriate requirements file depending on the GPU"""
requirements_name = "requirements-nowheel"
ROCM_PATH = os.environ.get("ROCM_PATH")
CUDA_PATH = os.environ.get("CUDA_PATH")
# TODO: Check if the user has an AMD gpu on windows
if ROCM_PATH:
requirements_name = "requirements-amd"
elif CUDA_PATH:
cuda_version = pathlib.Path(CUDA_PATH).name
if "12" in cuda_version:
requirements_name = "requirements"
elif "11" in cuda_version:
requirements_name = "requirements-cu118"
return requirements_name
def add_start_args(parser: argparse.ArgumentParser):
"""Add start script args to the provided parser"""
start_group = parser.add_argument_group("start")
start_group.add_argument(
"-iu",
"--ignore-upgrade",
action="store_true",
help="Ignore requirements upgrade",
)
start_group.add_argument(
"-nw",
"--nowheel",
action="store_true",
help="Don't upgrade wheel dependencies (exllamav2, torch)",
)
if __name__ == "__main__":
subprocess.run(["pip", "-V"])
# Create an argparser and add extra startup script args
parser = init_argparser()
add_start_args(parser)
args = parser.parse_args()
if args.ignore_upgrade:
print("Ignoring pip dependency upgrade due to user request.")
else:
requirements_file = (
"requirements-nowheel" if args.nowheel else get_requirements_file()
)
subprocess.run(["pip", "install", "-U", "-r", f"{requirements_file}.txt"])
# Import entrypoint after installing all requirements
from main import entrypoint
entrypoint(convert_args_to_dict(args, parser))