#ChatGPT #openai-api #command-line-tool #api-response #api-key #message #stdin

bin+lib daberu

一个简单的与ChatGPT对话的命令行工具

2个版本

0.1.1 2024年5月14日
0.1.0 2023年6月2日

#1080命令行工具

MIT/Apache

14KB
251

daberu

daberu License

一个简单的与ChatGPT对话的命令行工具。

"daberu"是"chatting"的日语翻译。

$ daberu -h
ChatGPT client tool that reads your message from stdin and writes the response to stdout

Usage: daberu [OPTIONS] --api-key <OPENAI_API_KEY>

Options:
      --api-key <OPENAI_API_KEY>  OpenAI API key [env: OPENAI_API_KEY]
      --log <LOG_FILE_PATH>       Log file path to save the conversation history. If the file already exists, the history will be considered in the next conversation
      --model <MODEL>             ChatGPT model name [env: CHATGPT_MODEL=] [default: gpt-4o] [possible values: gpt-4, gpt-4o, gpt-4-0314, gpt-4-32k, gpt-4-32k-0314, gpt-3.5-turbo, gpt-3.5-turbo-0301]
      --system <SYSTEM_MESSAGE>   If specified, the system role message will be added to the beginning of the conversation [env: CHATGPT_SYSTEM_MESSAGE=]
      --verbose                   If specified, HTTP request and response body JSONs are printed to stderr
  -h, --help                      Print help
  -V, --version                   Print version

安装

$ cargo install daberu
$ export OPENAI_API_KEY="YOUR API KEY"

使用示例

// Conversation without history.
$ echo hi | daberu
Hello! How can I assist you today?

// Conversation with history.
$ echo "Translate to Japanese: 'hi'" | daberu --log chat.log
こんにちは

$ echo "Next, translate to Spanish" | daberu --log chat.log
hola

$ jq . chat.log
[
  {
    "role": "user",
    "content": "Translate to Japanese: 'hi'\n"
  },
  {
    "role": "assistant",
    "content": "こんにちは"
  },
  {
    "role": "user",
    "content": "Next, translate to Spanish\n"
  },
  {
    "role": "assistant",
    "content": "hola"
  }
]

以下示例利用shell管道从ChatGPT获取现有文件的建议

$ git clone https://github.com/sile/daberu
$ cd daberu/

$ echo 'How to improve the following code?:' | cat - src/main.rs | daberu
The code looks concise and well-structured. A few suggestions to further improve it could be:

1. Add more documentation to the code, especially to the `Args` struct and its fields. This will help users understand the purpose and usage of each field.

2. Handle errors and display meaningful error messages to the user. Right now, the code uses the `orfail` crate to return an error message, but it doesn't provide any additional context or information about the error. Consider adding more descriptive error messages or logging errors to a file.

3. Add unit tests to verify the correctness of the code. This is especially important since the code relies on external libraries and APIs.

4. Consider adding more features to the ChatGPT client tool, such as allowing users to specify the input and output files, or enabling interactive mode where the user can have multiple conversations with the model.

在下一个示例中,使用系统角色消息来指令ChatGPT

$ git diff d8be79e..cb34a00 | daberu --system 'Please write consice changelog entries for the following diff.'
- Added author, license, description, homepage, repository, and readme fields to Cargo.toml
- Removed documentation badge and Actions Status badge from README.md
- Added an example utilizing shell pipeline to get advice from ChatGPT about an existing file to README.md

参考

依赖项

~3.5–4.5MB
~113K SLoC