From db24a0546f4f347ede12de8901e855347d26d71c Mon Sep 17 00:00:00 2001 From: rex <1073853456@qq.com> Date: Sun, 10 Mar 2024 21:47:59 +0800 Subject: [PATCH] rename to askenv --- README-en.md | 22 +++++++++++----------- README.md | 22 +++++++++++----------- askchat/{chatenv.py => askenv.py} | 4 ++-- askchat/cli.py | 9 ++++----- setup.cfg | 2 +- tests/{test_chatenv.py => test_askenv.py} | 2 +- 6 files changed, 30 insertions(+), 31 deletions(-) rename askchat/{chatenv.py => askenv.py} (97%) rename tests/{test_chatenv.py => test_askenv.py} (98%) diff --git a/README-en.md b/README-en.md index d9363cf..75e6067 100644 --- a/README-en.md +++ b/README-en.md @@ -108,7 +108,7 @@ Default parameters for `askchat`, used for direct interaction with ChatGPT or co | `--base-url` | `-b https://api.example.com` | Set the Base URL (excluding `/v1`) | | `--api-base` | `--api-base https://api.example.com/v1` | Set the Base URL | | `--api-key` | `-a sk-xxxxxxx` | Provide the OpenAI API key | -| `--use-env` | `-u prod` | Load environment variables from the specified config file, see [ChatEnv](#chatenv) | +| `--use-env` | `-u prod` | Load environment variables from the specified config file, see [AskEnv](#askenv) | Note: Some model APIs, like ChatGPT, use `/v4` as the base path of the API, so the `--api-base` parameter would be needed. @@ -126,49 +126,49 @@ Auxiliary features such as generating configuration files, printing debug logs, Note: `--all-valid-models` prints all available models, including Embedding, dalle-3, tts, etc., use `--valid-models` to filter these out. -## ChatEnv +## AskEnv -`chatenv` is used to manage different environment configurations, supporting operations such as create, activate, delete, etc. It facilitates switching between different environments, managing API keys, model names, and API base URLs. +`askenv` is used to manage different environment configurations, supporting operations such as create, activate, delete, etc. It facilitates switching between different environments, managing API keys, model names, and API base URLs. 1. Create a new environment configuration using the `new` command. ```bash - chatenv new [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL] + askenv new [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL] ``` 2. Activate an environment, setting it as the current configuration. ```bash - chatenv use + askenv use ``` 3. Delete a specified environment configuration file. ```bash - chatenv delete - chatenv delete --default + askenv delete + askenv delete --default ``` 4. List all available environments. ```bash - chatenv list + askenv list ``` 5. Display the configuration information for a specified environment, or the default environment if no name is provided. ```bash - chatenv show [name] + askenv show [name] ``` 6. Save the currently active environment configuration to a specified name. ```bash - chatenv save + askenv save ``` 7. Update one or more settings for a specified or default environment configuration. ```bash - chatenv config [name] [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL] + askenv config [name] [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL] ``` \ No newline at end of file diff --git a/README.md b/README.md index 64d024d..b730f23 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ Options: | `--base-url` | `-b https://api.example.com` | 设置 Base URL (不包含 `/v1`) | | `--api-base` | `--api-base https://api.example.com/v1` | 设置 Base URL | | `--api-key` | `-a sk-xxxxxxx` | 提供 OpenAI API 密钥 | -| `--use-env` | `-u prod` | 使用指定配置文件加载环境变量,详见 [ChatEnv](#chatenv) | +| `--use-env` | `-u prod` | 使用指定配置文件加载环境变量,详见 [AskEnv](#askenv) | 注:一些模型 API,比如智谱,使用 `/v4` 作为 API 的基础路径,这时得用 `--api-base` 参数。 @@ -124,49 +124,49 @@ Options: 注:`--all-valid-models` 会打印所有可用模型,包括 Embedding, dalle-3, tts 等,使用 `--valid-models` 可以过滤掉这些。 -## ChatEnv +## AskEnv -`chatenv` 用于管理不同的环境配置,支持创建、激活、删除等操作,便于在不同的环境之间切换,管理 API 密钥、模型名称和 API 的基础 URL 等配置信息。 +`askenv` 用于管理不同的环境配置,支持创建、激活、删除等操作,便于在不同的环境之间切换,管理 API 密钥、模型名称和 API 的基础 URL 等配置信息。 1. 创建一个新的环境配置,使用 `new` 命令。 ```bash - chatenv new [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL] + askenv new [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL] ``` 2. 激活某个环境,将其设置为当前使用的配置。 ```bash - chatenv use + askenv use ``` 3. 删除指定的环境配置文件。 ```bash - chatenv delete - chatenv delete --default + askenv delete + askenv delete --default ``` 4. 列出当前所有可用环境。 ```bash - chatenv list + askenv list ``` 5. 显示指定环境的配置信息,如果没有指定环境名称,则显示默认环境的配置。 ```bash - chatenv show [name] + askenv show [name] ``` 6. 将当前激活的环境配置保存为指定名称的配置文件。 ```bash - chatenv save + askenv save ``` 7. 更新指定或默认环境配置的一项或多项设置。 ```bash - chatenv config [name] [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL] + askenv config [name] [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL] ``` \ No newline at end of file diff --git a/askchat/chatenv.py b/askchat/askenv.py similarity index 97% rename from askchat/chatenv.py rename to askchat/askenv.py index a6dae5f..dc45ab7 100644 --- a/askchat/chatenv.py +++ b/askchat/askenv.py @@ -10,7 +10,7 @@ @click.group() def cli(): - """chatenv CLI for managing askchat environments.""" + """askenv CLI for managing askchat environments.""" if not ENV_PATH.exists(): ENV_PATH.mkdir(parents=True) @@ -77,7 +77,7 @@ def show(name): if name: click.echo(f"Environment '{name}' not found.") else: - click.echo("No active environment. You can use `chatenv new` to new one.") + click.echo("No active environment. You can use `askenv new` to new one.") @cli.command() @click.argument('name') diff --git a/askchat/cli.py b/askchat/cli.py index 3de773f..fc09bba 100644 --- a/askchat/cli.py +++ b/askchat/cli.py @@ -23,10 +23,9 @@ def setup(): with open(CONFIG_FILE, 'w') as cf: cf.write("# Initial configuration\n") load_dotenv(CONFIG_FILE, override=True) - print("setup loaded") - # if not os.path.exists(LAST_CHAT_FILE): - # with open(LAST_CHAT_FILE, 'w') as lcf: - # lcf.write('{"index": 0, "chat_log": []}') + +# load environment variables from the configuration file +setup() # callback functions def generate_config_callback(ctx, param, value): @@ -45,6 +44,7 @@ def generate_config_callback(ctx, param, value): def debug_log_callback(ctx, param, value): if not value: return + debug_log() ctx.exit() @@ -128,7 +128,6 @@ def cli(): def main( message, model, base_url, api_base, api_key, use_env , c, regenerate, load, print): """Interact with ChatGPT in terminal via chattool""" - setup() # read environment variables from the ENV_PATH if use_env: env_file = ENV_PATH / f"{use_env}.env" diff --git a/setup.cfg b/setup.cfg index 175ca8b..8566fdb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,5 +10,5 @@ addopts = --ignore=setup.py console_scripts = ask = askchat.ask:main askchat = askchat.cli:main - chatenv = askchat.chatenv:cli + askenv = askchat.askenv:cli diff --git a/tests/test_chatenv.py b/tests/test_askenv.py similarity index 98% rename from tests/test_chatenv.py rename to tests/test_askenv.py index f7fab48..0c65aa2 100644 --- a/tests/test_chatenv.py +++ b/tests/test_askenv.py @@ -1,6 +1,6 @@ import pytest from click.testing import CliRunner -from askchat.chatenv import cli +from askchat.askenv import cli from pathlib import Path ENV_PATH = Path.home() / '.askchat' / 'envs'