From 7b8c9d87c452d94459e7ac657242de430bea76ca Mon Sep 17 00:00:00 2001 From: rex <1073853456@qq.com> Date: Sun, 11 Aug 2024 04:13:38 +0800 Subject: [PATCH] add interactive mode --- askchat/__init__.py | 2 +- askchat/askenv.py | 11 ++++++++--- setup.py | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/askchat/__init__.py b/askchat/__init__.py index a39ee35..761ba2f 100644 --- a/askchat/__init__.py +++ b/askchat/__init__.py @@ -2,7 +2,7 @@ __author__ = """Rex Wang""" __email__ = '1073853456@qq.com' -__version__ = '1.2.1' +__version__ = '1.2.2' import asyncio from pathlib import Path diff --git a/askchat/askenv.py b/askchat/askenv.py index 156ba6a..fe0b63f 100644 --- a/askchat/askenv.py +++ b/askchat/askenv.py @@ -33,14 +33,19 @@ def list(): @click.option('-b', '--base-url', default=None, help='Base URL of the API (without suffix `/v1`)') @click.option('--api-base', default=None, help='Base URL of the API (with suffix `/v1`)') @click.option('-m', '--model', default=None, help='Model name') -def new(name, api_key, base_url, api_base, model): +@click.option('--interactive', '-i', is_flag=True, default=False, help='Enable interactive mode for inputting options') +def new(name, api_key, base_url, api_base, model, interactive): """Create a new environment configuration.""" config_path = ENV_PATH / f'{name}.env' if config_path.exists(): click.echo(f"Warning: Overwriting existing environment '{name}'.") click.confirm("Do you want to continue?", abort=True) - else: - click.echo(f"Environment '{name}' created.") + if interactive: + api_key = click.prompt('API key', default=api_key, hide_input=True) + base_url = click.prompt('Base URL of the API (without suffix `/v1`)', default=base_url) + default_api_base = f"{base_url}/v1" if base_url else api_base + api_base = click.prompt('Base URL of the API (with suffix `/v1`)', default=default_api_base) + model = click.prompt('Default model name', default=model) write_config(config_path, api_key, model, base_url, api_base, overwrite=True) @cli.command() diff --git a/setup.py b/setup.py index 70df16e..fddc2a8 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup, find_packages -VERSION = '1.2.1' +VERSION = '1.2.2' with open('README.md') as readme_file: readme = readme_file.read()