3 个不稳定版本
0.2.0 | 2024 年 5 月 27 日 |
---|---|
0.1.1 | 2024 年 5 月 24 日 |
0.1.0 | 2024 年 5 月 24 日 |
#1253 在 命令行工具
114 每月下载量
2.5MB
829 行
演示
安装
Cargo
cargo install pgpt
pgpt --help
源代码
git clone https://github.com/ammar-ahmed22/pgpt.git
cd pgpt
cargo install --path .
使用方法
首次使用时,pgpt 会提示您输入一个 OpenAI API 密钥。
密钥将保存在/加密到本地配置文件中,以便以后使用。
或者,您可以将 API 密钥传递给环境变量 OPENAI_API_KEY
以不保存它。
配置(《config set》)
模型
设置提问时使用的默认模型。
pgpt config set model <MODEL>
目前支持选项有 gpt-3、
gpt-4 和
gpt-4o
。
缓存长度
设置要保存在缓存中的提示/响应对的数目(正整数
)。将其视为您的聊天历史。默认为 5。
pgpt config set cache-length <LENGTH>
上下文
设置要随查询一起发送的先前提示/响应对的数目(正整数
)。如果值大于 cache-length
,则发送所有保存的值。默认为 0。
pgpt config set context <NUMBER>
API 密钥
设置 OpenAI API 密钥。
pgpt config set api-key <API_KEY>
要显示上述任何选项的配置值,请使用
pgpt config show <OPTION>
或使用 pgpt config show all
显示所有配置值
清除缓存
由于缓存(保存的聊天历史)可能变得非常长或不相关,您可以使用以下命令清除保存的历史记录
pgpt config clear cache
问题
使用保存的配置参数向 ChatGPT 提问
pgpt query what is the meaning of life
这将使用配置中设置的 model
和保存到 context
值的任何聊天历史来查询 ChatGPT。
--cost
传递 --cost
标志将显示使用模型相关价格查询的总成本。
pgpt query --cost how to do a for loop in Rust
-m, --模型
覆盖配置中设置的模型,并使用特定的模型进行查询
pgpt query -m gpt-4o how to reverse a linked list in C++
-c, --上下文
覆盖配置中设置的上下文值。
例如,如果配置中的 context
设置为 3
,但您只想发送带有查询的最后一条消息。
pgpt -c 1 Explain what you just said before this
-, --显示-上下文
显示与查询一起发送的上一条消息
pgpt -s elaborate further
示例
我们将使用 CLI 设置的默认值启动
显示配置
pgpt config show all
Creating configuration file with default values at "/Users/ammar/Library/Application Support/com.pgpt.pgpt/./config.json"
Model: gpt-3
API Key (encrypted): ����p"��Ý�<H*���g�4ق
�"O��?��
��/���s��G�C�EFQ~����Y�t�K���=���x���T�d|���G�;Hud�
Cache Length: 5
Context: 0
To display cache, run `pgpt config show cache`
将上下文设置为最大值
pgpt config set context 5
Setting context to 5
Saved config successfully!
提出一个问题
pgpt query what is a for loop
Saved cache successfully!
Cache capacity 1/5
Response from gpt-3.5-turbo-0125
A for loop is a control flow statement that allows you to iterate over a sequence of elements (such as a list, tuple,
dictionary, etc.) and execute a block of code for each element in the sequence. It consists of three parts:
initialization, condition, and increment/decrement. The loop continues to execute as long as the condition is true,
and the increment/decrement part is used to update the loop variable.
显示当前缓存
pgpt config show cache
Cache:
Cached 1/1
You said: what is a for loop
GPT said:
A for loop is a control flow statement that allows you to iterate over a sequence of elements (such as a list, tuple, dictionary, etc.) and execute a block of code for each element in the sequence. It consists of three parts: initialization, condition, and increment/decrement. The loop continues to execute as long as the condition is true, and the increment/decrement part is used to update the loop variable.
提出后续问题(包括总成本和上一条消息)
pgpt query --cost --show-context how do I do that in Rust
Saved cache successfully!
Cache capacity 2/5
You said:
what is a for loop
GPT said:
A for loop is a control flow statement that allows you to iterate over a sequence of elements (such as a list, tuple,
dictionary, etc.) and execute a block of code for each element in the sequence. It consists of three parts:
initialization, condition, and increment/decrement. The loop continues to execute as long as the condition is true,
and the increment/decrement part is used to update the loop variable.
You said:
how do I do that in Rust
Response from gpt-3.5-turbo-0125
In Rust, you can use the for loop to iterate over a collection of items. Here is an example of a basic for loop in
Rust:
fn main() {
let numbers = [1, 2, 3, 4, 5];
for number in numbers.iter() {
println!("{}", number);
}
}
In this example, the for loop iterates over each element in the numbers array and prints it out. The iter() method is
used to create an iterator over the array.
You can also use ranges in for loops in Rust. Here's an example:
fn main() {
for i in 0..5 {
println!("{}", i);
}
}
In this example, the for loop iterates over a range from 0 to 5 (excluding 5) and prints each number.
Cost: $0.000345
[!注意] 上述输出显示的是终端中不会显示的格式。大多数终端支持 ANSI 颜色,会在终端 markdown 中显示 ChatGPT 的响应。
许可证
依赖项
~15–30MB
~444K SLoC