-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Args: Add subcommands to run actions
Migrate OpenAPI and sample config export to subcommands "export-openapi" and "export-config". Also add a "download" subcommand that passes args to the TabbyAPI downloader. This allows models to be downloaded via the API and CLI args. Signed-off-by: kingbri <[email protected]>
- Loading branch information
Showing
6 changed files
with
112 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,51 @@ | ||
import argparse | ||
import asyncio | ||
import json | ||
from loguru import logger | ||
|
||
from common.tabby_config import config, generate_config_file | ||
from common.downloader import hf_repo_download | ||
from common.tabby_config import generate_config_file | ||
from common.utils import unwrap | ||
from endpoints.server import export_openapi | ||
|
||
|
||
def branch_to_actions() -> bool: | ||
"""Checks if a optional action needs to be run.""" | ||
def download_action(args: argparse.Namespace): | ||
asyncio.run( | ||
hf_repo_download( | ||
repo_id=args.repo_id, | ||
folder_name=args.folder_name, | ||
revision=args.revision, | ||
token=args.token, | ||
include=args.include, | ||
exclude=args.exclude, | ||
) | ||
) | ||
|
||
if config.actions.export_openapi: | ||
openapi_json = export_openapi() | ||
|
||
with open(config.actions.openapi_export_path, "w") as f: | ||
f.write(json.dumps(openapi_json)) | ||
logger.info( | ||
"Successfully wrote OpenAPI spec to " | ||
+ f"{config.actions.openapi_export_path}" | ||
) | ||
elif config.actions.export_config: | ||
generate_config_file(filename=config.actions.config_export_path) | ||
else: | ||
# did not branch | ||
return False | ||
def config_export_action(args: argparse.Namespace): | ||
export_path = unwrap(args.export_path, "config_sample.yml") | ||
generate_config_file(filename=export_path) | ||
|
||
# branched and ran an action | ||
return True | ||
|
||
def openapi_export_action(args: argparse.Namespace): | ||
export_path = unwrap(args.export_path, "openapi.json") | ||
openapi_json = export_openapi() | ||
|
||
with open(export_path, "w") as f: | ||
f.write(json.dumps(openapi_json)) | ||
logger.info("Successfully wrote OpenAPI spec to " + f"{export_path}") | ||
|
||
|
||
def run_subcommand(args: argparse.Namespace) -> bool: | ||
match args.actions: | ||
case "download": | ||
download_action(args) | ||
return True | ||
case "export-config": | ||
config_export_action(args) | ||
return True | ||
case "export-openapi": | ||
openapi_export_action(args) | ||
return True | ||
case _: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters