10 个版本
0.4.5 | 2024 年 6 月 1 日 |
---|---|
0.4.4 | 2024 年 2 月 13 日 |
0.4.2 | 2023 年 6 月 16 日 |
0.3.1 | 2023 年 6 月 10 日 |
0.2.2 | 2023 年 6 月 6 日 |
#66 在 机器学习 中
72 每月下载次数
40KB
527 行
ask.sh: 从终端读取并写入的 AI 终端助手
ask.sh
是一个基于 OpenAI API(如 GPT-3.5/4)的 AI 终端助手!- 独特之处?
ask.sh
可以 从您的终端读取和写入!- 无需将错误文本复制粘贴到浏览器窗口中,然后再将解决方案带回终端!
- 它保持一定的记忆,可以处理多轮对话!
ask.sh
为您的终端提供ask
命令
演示
从使用 curl 命令下载泰坦尼克号数据集到使用 awk
命令计算所有性别和舱位组合的生存率,无需离开终端。(以 2 倍速播放。使用 gpt-3.5-turbo
)
https://github.com/hmirin/ask.sh/assets/1284876/4311db79-c56e-46c9-9cfe-66fce8f800df
您可能对 其他示例 感兴趣
快速开始
如果您使用 Bash
bash -c "$(curl -fsSL https://raw.githubusercontent.com/hmirin/ask.sh/main/install.sh)"
如果您使用 Zsh
zsh -c "$(curl -fsSL https://raw.githubusercontent.com/hmirin/ask.sh/main/install.sh)"
然后,按照安装程序显示的说明进行操作。有关手动安装的信息,请参阅 设置。
主要功能
从您的终端查询 AI
无需烦恼使用单独的浏览器。直接从您的终端咨询 AI。以下是一个示例
❯ ask how to unzip tar gz
AI 的响应
❯ ask how to unzip tar gz
To unzip a tar.gz file, you can use the following command in a terminal:
`tar -xzf file.tar.gz`
where "file.tar.gz" is the name of your compressed file. This command will extract the contents of the file into a directory with the same name as the file. If you want to extract the contents into a different directory, you can specify the path with the -C option:
`tar -xzf file.tar.gz -C /path/to/directory`
Once the extraction is complete, you should have access to the uncompressed files in the directory where you extracted them.
答案会分批打印,确保您不必等待完整响应才可用!
AI 理解您的上下文!
AI 终端助手可以理解您的操作上下文,提供更有意义的建议和解释。请看这个示例
您输入了一个命令并遇到了错误。
❯ rm .git
rm: .git: is a directory
只需询问 AI
❯ ask what does this mean
AI 的响应
❯ ask what does this mean
The message "is a directory" means that you are trying to remove a directory (in this case, the .git directory). In order to remove a directory, you need to use the command "rm -r" instead of just "rm". The "-r" flag tells the "rm" command to remove directories recursively. However, be careful when using this command as it can delete multiple files and directories at once.
太棒了!不是吗?
注意:您需要使用tmux来使用此功能。请参阅问答。
在您的终端与 AI 进行多轮对话
通过理解您的终端环境,ask.sh
不仅仅是提出问题并接收答案;它涉及到多轮深入的对话。以下是一个可能的对话示例
❯ git init
Reinitialized existing Git repository in /path/to/ask.sh/.git/
你知道再次运行git init
时会发生什么吗?让我们来问问
❯ ask what does reinitialized mean
"Reinitialized" means that Git has reset the repository's initialization parameters. When you run `git init` in an existing Git repository, Git will re-run the repository's initialization process, but with the existing repository metadata in place. This allows you to reset the repository configuration without losing the existing commit history and other Git metadata.
嗯,还有问题吗?再问一遍
❯ ask what configuration is reset
When you run init` with the `--reinitialize` or `-o` option, Git will re-run the repository's initialization process, but with the existing repository metadata in place. This allows you to reset the repository configuration without losing the existing commit history and other Git metadata. The specific configuration that is reset depends on what options you passed to `git init`. If you did not pass any options, then Git will reset all initialization parameters to their default values. Is there anything else I can help you with?
让 AI 直接写入您的终端!
ask
命令让您可以直接将AI建议的命令输入到shell中。
让AI生成如下命令
❯ ask allocate 5GB file here
AI会给出一些命令的建议
To allocate a 5GB file here, you can use the `fallocate` command. `fallocate` can be used to allocate space for a file using either the preallocated or the zeroed method.
To allocate space for a 5GB file with the preallocated method, run the following command:
```
fallocate -l 5G filename
```
Remember to replace `filename` with the desired name for your file. This will create a file of size 5GB without actually allocating the space until it is actually used.
To allocate space for a 5GB file with the zeroed method, run the following command:
```
fallocate -l 5G -z filename
```
This will create a file of size 5GB with all bits set to 0.
如果AI建议了要执行的命令,它将询问您是否想使用这些命令。
👋 Hey, AI has suggested some commands that can be typed into your terminal.
🔍 Press Enter to view and select the commands, or type any other key to exit:
按下Enter键后,将出现一个覆盖选择器(peco
),允许您选择最合适的命令。
AI suggested commands (Enter to use / Ctrl+C to exit):
fallocate -l 5G filename
fallocate -l 5G -z filename
选定的命令将直接输入到shell中。只需按Enter键即可执行。
❯ fallocate -l 5G filename
您不会在终端上挣扎文本选择!
操作系统 / CPU架构 / 适应对话!
ask
命令知道您的shell、操作系统和CPU架构。因此,您可以提出有关shell、操作系统和CPU架构的具体问题。
❯ ask how to install tmux
AI 的响应
❯ ask how to install tmux
To install tmux on your macOS machine, you can use Homebrew package manager. Here are the steps:
1. Open the terminal.
2. Install Homebrew package manager by running the following command:
```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
3. Once Homebrew is installed, install tmux:
```
brew install tmux
```
4. Wait for the installation to complete.
That's it! Now you can use tmux on your macOS machine.
完美!不是吗?(有些人可能不喜欢homebrew...)
想看更多吗?
请参阅示例!
设置
先决条件
- rust
peco
:ask
命令使用peco让您从AI建议的命令中选择要执行的命令。
可选的,但如果您想使ask
命令运行得更顺畅,则强烈推荐
tmux
:如果您在tmux中运行ask
命令,则可以将当前终端发送到AI以进行上下文感知输入。zsh
:如果您在zsh(不是Bash)中运行ask
命令,则可以让AI直接将下一个命令写入您的终端。无需复制粘贴。
安装
- 如果您使用Bash或zsh,安装脚本应该可以工作。
- 如果您遇到任何问题,请提交问题!
- 如果您想手动安装
ask.sh
,请按照以下步骤操作- 安装先决条件
- 使用cargo安装
ask.sh
:cargo install ask-sh
- 在您的shell中设置
ASK_SH_OPENAI_API_KEY
- 您可以从OpenAI获取您的API密钥。
- 如果您不想使用tmux或不想将您的终端输出发送到OpenAI服务器,设置
ASK_SH_NO_PANE=true
- 如果您在查询
ask
时没有设置此变量,则ask
命令将始终建议您使用tmux。
- 如果您在查询
- 设置您的shell环境
- 将
eval "$(ask-sh --init)"
添加到您的rc文件中(例如,~/.bashrc
,~/.zshrc
) - 不要忘记源您的shell配置文件或重新启动shell。
- 将
- 使用
ask hey whats up
测试命令- 如果AI响应带有“作为一个AI助手,我无法体验情绪等等”之类的短语,则表示设置正确。
额外内容!
- 我们很快将推出一个Chrome扩展程序,允许您以终端输出方式打开chat.openai.com。
- 如果您需要更多功能,请通过创建问题来告诉我们!(但请注意,我最近有点忙。)
许可证
本项目根据MIT许可证条款授权。
免责声明
-
自行承担风险:本软件按“现状”提供,不提供任何形式的保证,无论是明示的还是暗示的。使用本软件由您自行决定和承担风险,您将单独对其使用造成的任何损害或损失承担责任。
-
向OpenAI传输数据:使用本软件时,您输入的文本以及某些终端信息将作为软件运行的一部分发送到OpenAI。
-
意外数据传输的可能性:请注意,由于软件错误或意外行为,可能将意外数据发送到OpenAI或其他地方。虽然我们努力确保您数据的隐私和安全,但这些风险永远无法完全消除。
问答
为什么还需要另一个终端AI助手?
当然,已经有很多针对终端AI助手的优秀项目了。但根据我的经验,这些工具中没有一个完全符合我认为的基本标准。
- 简单的API:谁想记住复杂的命令和选项?我们一开始不就是为了需要AI才这样做的吗?
- 多轮能力:大多数工具都针对单轮查询,因为它们缺乏记忆,这是我认为的一个重要特性。
- 终端阅读:从终端复制粘贴?不,谢谢!
- 在zsh/bash上直接执行命令:在包装环境或REPL中运行命令不是我所喜欢的。
这就是我为什么创建了ask.sh
的原因。
类似项目
- Github Copilot for CLI
- 它很棒,但它主要专注于单轮对话以生成命令。
- ShellGPT
- 这是一项开创性的工作,具有许多优秀特性!然而,我发现API过于复杂,并且我不喜欢它在REPL中运行命令的方式。
ask.sh是如何发送当前终端输出的?
- ask.sh使用
tmux capture-pane -p
来获取当前的终端状态。因此,如果您在tmux面板中运行ask
,面板上的文本将被发送到OpenAI。 - 这将给AI提供您请求的上下文,并提高结果。
- 如果您不想使用此功能,请在您的shell中将
ASK_SH_NO_PANE=true
设置为true。
隐私问题?
- 截至2023年7月5日,OpenAI 表示,除非您明确同意,否则他们不会使用客户通过其API提交的数据来训练或改进其模型。
- 当然,您可以在不向OpenAI服务器发送当前终端输出的情况下使用ask.sh。只需在您的shell中将
ASK_SH_NO_PANE=true
设置为true。
我可以使用GPT-4吗?
- 是的!您可以通过设置环境变量
ASK_SH_OPENAI_MODEL=gpt-4
来使用GPT-4。- 此环境变量只是传递给OpenAI API。因此,您可以使用OpenAI提供的任何模型。
- 目前,默认模型设置为
gpt-3.5-turbo
。
为什么选择Rust?
- 这仅仅是因为Shell工具应该有更少的依赖!
- 据我所知,在Python中还没有一种标准的方法可以使一个命令在所有地方可用。
贡献
- 当然,我们欢迎贡献!请随意打开一个issue或提交一个pull request。
致谢
特别感谢 @xarsh 在调试、测试和提供宝贵反馈方面的努力,对改进此项目做出了重大贡献。我们对 @matsurih 在我们工作中做出的杰出贡献表示衷心的感谢,这是项目的首个PR。
依赖
~11–25MB
~380K SLoC