[AUR-424] Setup CLI interface (#25)
* [AUR-424] Setup CLI interface * [AUR-424] fix test_vectorstore:test_query * [AUR-424] exclude examples when setup CLI * [AUR-424] create kh and kh --export * [AUR-426] revise cli by using click.group * Fix dynamic import * [AUR-426] revert the format of import packages * [AUR-426] set argument default * [AUR-426] set click dependencies in setup.py --------- Co-authored-by: trducng <trungduc1992@gmail.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import os
|
||||
|
||||
import click
|
||||
import yaml
|
||||
|
||||
from kotaemon.contribs.promptui.config import export_pipeline_to_config
|
||||
from kotaemon.contribs.promptui.ui import build_from_dict
|
||||
|
||||
|
||||
# check if the output is not a .yml file -> raise error
|
||||
def check_config_format(config):
|
||||
if os.path.exists(config):
|
||||
if isinstance(config, str):
|
||||
with open(config) as f:
|
||||
yaml.safe_load(f)
|
||||
else:
|
||||
raise ValueError("config must be yaml format.")
|
||||
|
||||
|
||||
@click.group()
|
||||
def main():
|
||||
pass
|
||||
|
||||
|
||||
@click.group()
|
||||
def promptui():
|
||||
pass
|
||||
|
||||
|
||||
main.add_command(promptui)
|
||||
|
||||
|
||||
@promptui.command()
|
||||
@click.argument("export_path", nargs=1)
|
||||
@click.option("--output", default="promptui.yml", required=False)
|
||||
def export(export_path, output):
|
||||
|
||||
import sys
|
||||
|
||||
from theflow.utils.modules import import_dotted_string
|
||||
|
||||
sys.path.append(os.getcwd())
|
||||
cls = import_dotted_string(export_path, safe=False)
|
||||
export_pipeline_to_config(cls, output)
|
||||
check_config_format(output)
|
||||
|
||||
|
||||
@promptui.command()
|
||||
@click.argument("run_path", required=False, default="promptui.yml")
|
||||
def run(run_path):
|
||||
build_from_dict(run_path)
|
||||
check_config_format(run_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Reference in New Issue
Block a user