Skip to content

Commit

Permalink
rename to askenv
Browse files Browse the repository at this point in the history
  • Loading branch information
RexWzh committed Mar 10, 2024
1 parent 03a1318 commit f3b6646
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 33 deletions.
22 changes: 11 additions & 11 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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 <name> [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL]
askenv new <name> [-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 <name>
askenv use <name>
```

3. Delete a specified environment configuration file.

```bash
chatenv delete <name>
chatenv delete --default
askenv delete <name>
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 <name>
askenv save <name>
```

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]
```
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 参数。

Expand All @@ -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 <name> [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL]
askenv new <name> [-a API_KEY] [-b BASE_URL] [--api-base API_BASE] [-m MODEL]
```

2. 激活某个环境,将其设置为当前使用的配置。

```bash
chatenv use <name>
askenv use <name>
```

3. 删除指定的环境配置文件。

```bash
chatenv delete <name>
chatenv delete --default
askenv delete <name>
askenv delete --default
```

4. 列出当前所有可用环境。

```bash
chatenv list
askenv list
```

5. 显示指定环境的配置信息,如果没有指定环境名称,则显示默认环境的配置。

```bash
chatenv show [name]
askenv show [name]
```

6. 将当前激活的环境配置保存为指定名称的配置文件。

```bash
chatenv save <name>
askenv save <name>
```

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]
```
2 changes: 1 addition & 1 deletion askchat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """Rex Wang"""
__email__ = '[email protected]'
__version__ = '1.0.0'
__version__ = '1.0.1'

import asyncio

Expand Down
4 changes: 2 additions & 2 deletions askchat/chatenv.py → askchat/askenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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')
Expand Down
9 changes: 4 additions & 5 deletions askchat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()

Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import setup, find_packages

VERSION = '1.0.0'
VERSION = '1.0.1'

with open('README.md') as readme_file:
readme = readme_file.read()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_chatenv.py → tests/test_askenv.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit f3b6646

Please sign in to comment.