Skip to content

Commit

Permalink
add response options
Browse files Browse the repository at this point in the history
  • Loading branch information
RexWzh committed Mar 24, 2024
1 parent 883348c commit 5db6b5b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Manage conversation history, including saving, loading, deleting, and listing co
|-----------------|------------------------|-----------------------------------------------|
| `-c` | `askchat -c <message>` | Continue the last conversation |
| `--regenerate` | `askchat -r` | Regenerate the last response of the conversation |
| `--load` | `askchat -l <file> [message]` | Load conversation history from a file and continue |
| `--load` | `askchat -l <file>` | Load conversation history from a file |
| `--print` | `askchat -p [<file>]` | Print the last or a specified conversation history |
| `--save` | `askchat -s <file>` | Save the current conversation history to a file |
| `--delete` | `askchat -d <file>` | Delete a specified conversation history file |
Expand All @@ -108,6 +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 |
| `--option` | `-o top_p 1 temperature 0.5` | Set request parameters |
| `--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 Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Options:
|---------------------|------------------|--------------------------------------------|
| `-c` | `askchat -c <message>` | 继续上一次的对话 |
| `--regenerate` | `askchat -r` | 重新生成上一次对话的最后回复 |
| `--load` | `askchat -l <file> [message]` | 从文件加载对话历史,继续对话 |
| `--load` | `askchat -l <file>` | 加载历史对话 |
| `--print` | `askchat -p [<file>]` | 打印上次或指定的对话历史 |
| `--save` | `askchat -s <file>` | 将当前对话历史保存到文件 |
| `--delete` | `askchat -d <file>` | 删除指定的对话历史文件 |
Expand All @@ -106,6 +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 密钥 |
| `--option` | `-o top_p 1 temperature 0.5` | 设置请求参数 |
| `--use-env` | `-u prod` | 使用指定配置文件加载环境变量,详见 [AskEnv](#askenv) |

注:一些模型 API,比如智谱,使用 `/v4` 作为 API 的基础路径,这时得用 `--api-base` 参数。
Expand Down
6 changes: 4 additions & 2 deletions askchat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ def cli():
@click.option('--valid-models', is_flag=True, callback=valid_models_callback, expose_value=False, help='Print valid models that contain "gpt" in their names')
@click.option('--all-valid-models', is_flag=True, callback=all_valid_models_callback, expose_value=False, help='Print all valid models')
@click.option('-v', '--version', is_flag=True, callback=version_callback, expose_value=False, help='Print the version')
@click.option('-o', '--option', multiple=True, type=(str, str), help='Additional options for show_resp in the form of key=value')
def main( message, model, base_url, api_base, api_key, use_env
, c, regenerate, print):
, c, regenerate, print, option):
"""Interact with ChatGPT in terminal via chattool"""
setup()

Check warning on line 159 in askchat/cli.py

View check run for this annotation

Codecov / codecov/patch

askchat/cli.py#L159

Added line #L159 was not covered by tests
message_text = ' '.join(message).strip()
Expand Down Expand Up @@ -205,7 +206,8 @@ def main( message, model, base_url, api_base, api_key, use_env
return
chat.user(message_text)
# Add chat response
chat.assistant(asyncio.run(show_resp(chat)))
options = dict(option)
chat.assistant(asyncio.run(show_resp(chat, **options)))

Check warning on line 210 in askchat/cli.py

View check run for this annotation

Codecov / codecov/patch

askchat/cli.py#L209-L210

Added lines #L209 - L210 were not covered by tests
chat.save(LAST_CHAT_FILE, mode='w')

if __name__ == '__main__':
Expand Down

0 comments on commit 5db6b5b

Please sign in to comment.