Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat #1

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [
]
resolver = "2"

[profile.release.package.ata2]
[profile.release.package.ata]
strip = false

[profile.release]
Expand Down
12 changes: 12 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
all: README.md ata

README.md: README.md.sh
./$< > $@

.PHONY: ata
ata:
cargo build --release

.PHONY: install
install:
cargo install --path ./ata²
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<h1 align="center"><code>ata²</code>: Ask the Terminal Anything</h1>

<h3 align="center">ChatGPT in the terminal</h3>
Expand Down Expand Up @@ -74,6 +75,45 @@ You may also:
$ cargo install --path .
```

### Keybindings
```text
Keyboard shortcuts:
ata²-specific:
Ctrl-D, EOF (In multiline mode) Send the current message.
F2 Save the current conversation (not including the message
you're typing) to a file.

rustyline:
Ctrl-A, Home Move cursor to the beginning of line
Ctrl-B, Left Move cursor one character left
Ctrl-E, End Move cursor to end of line
Ctrl-F, Right Move cursor one character right
Ctrl-H, Backspace Delete character before cursor
Ctrl-I, Tab Next completion
Ctrl-K Delete from cursor to end of line
Ctrl-L Clear screen
Ctrl-N, Down Next match from history
Ctrl-P, Up Previous match from history
Ctrl-X Ctrl-U Undo
Ctrl-Y Paste from Yank buffer (Meta-Y to paste next yank instead)
Meta-< Move to first entry in history
Meta-> Move to last entry in history
Meta-B, Alt-Left Move cursor to previous word
Meta-C Capitalize the current word
Meta-D Delete forwards one word
Meta-F, Alt-Right Move cursor to next word
Meta-L Lower-case the next word
Meta-T Transpose words
Meta-U Upper-case the next word
Meta-Y See Ctrl-Y
Meta-Backspace Kill from the start of the current word, or, if between
words, to the start of the previous word
Meta-0, 1, ..., - Specify the digit to the argument. – starts a negative
argument.

Thanks to <https://github.com/kkawakam/rustyline#emacs-mode-default-mode>.
```

# License

Copyright 2023 Fredrick R. Brennan &lt;copypaste@kittens.ph&gt;, Rik Huijzer &lt;rikhuijzer@pm.me&gt;, &amp; ATA Project Authors
Expand Down
103 changes: 103 additions & 0 deletions README.md.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
cat << 'EOF'

<h1 align="center"><code>ata²</code>: Ask the Terminal Anything</h1>

<h3 align="center">ChatGPT in the terminal</h3>

[![asciicast](https://asciinema.org/a/sOgAo4BkUXBJTSgyjIZw2mnFr.svg)](https://asciinema.org/a/sOgAo4BkUXBJTSgyjIZw2mnFr)

## This is a fork!

The original project, `ata`, by Rik Huijzer is [elsewhere](https://github.com/rikhuijzer/ata).

This fork implements many new config options and features.

<h3 align=center>
TIP:<br>
Run a terminal with this tool in your background and show/hide it with a keypress.<br>
This can be done via: Iterm2 (Mac), Guake (Ubuntu), scratchpad (i3/sway), yakuake (KDE), or the quake mode for the Windows Terminal.
</h3>

## Productivity benefits

- The terminal starts more quickly and requires **less resources** than a browser.
- The **keyboard shortcuts** allow for quick interaction with the query. For example, press `CTRL + c` to cancel the stream, `CTRL + ↑` to get the previous query again, and `CTRL + w` to remove the last word.
- A terminal can be set to **run in the background and show/hide with one keypress**. To do this, use iTerm2 (Mac), Guake (Ubuntu), scratchpad (i3/sway), or the quake mode for the Windows Terminal.
- The prompts are **reproducible** because each prompt is sent as a stand-alone prompt without history. Tweaking the prompt can be done by pressing `CTRL + ↑` and making changes.

## Usage

Download the binary for your system from [Releases](https://github.com/ctrlcctrlv/ata2/releases).
If you're running Arch Linux, then you can use the AUR package: [ata2](https://aur.archlinux.org/packages/ata2)

To specify the API key and some basic model settings, start the application.
It should give an error and the option to create a configuration file called `ata2.toml` for you.
Press `y` and `ENTER` to create a `ata2.toml` file.

Next, request an API key via <https://beta.openai.com/account/api-keys> and update the key in the example configuration file.

For more information, see:

```sh
$ ata2 --help
```

## FAQ

**How much will I have to pay for the API?**

Using OpenAI's API for chat is very cheap.
Let's say that an average response is about 500 tokens, so costs $0.001.
That means that if you do 100 requests per day, which is a lot, then that will cost you about $0.10 per day ($3 per month).
OpenAI grants you $18.00 for free, so you can use the API for about 180 days (6 months) before having to pay.

**How does this compare to LLM-based search engines such as You.com or Bing Chat?**

At the time of writing, the OpenAI API responds much quicker than the large language model-based search engines and contains no adds.
It is particularly useful to quickly look up some things like Unicode symbols, historical facts, or word meanings.

**Can I build the binary myself?**

Yes, you can clone the repository and build the project via [`Cargo`](https://github.com/rust-lang/cargo).
Make sure that you have `Cargo` installed and then run:

```sh
$ git clone https://github.com/ctrlcctrlv/ata2.git

$ cd ata2/

$ cargo build --release
```
After this, your binary should be available at `target/release/ata2` (Unix-based) or `target/release/ata2.exe` (Windows).

You may also:

```sh
$ cargo install --path .
```

### Keybindings
```text
EOF
cat ./ata²/src/help/keybindings.txt
cat << 'EOF'
```

# License

Copyright 2023 Fredrick R. Brennan &lt;copypaste@kittens.ph&gt;, Rik Huijzer &lt;rikhuijzer@pm.me&gt;, &amp; ATA Project Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

EOF
9 changes: 7 additions & 2 deletions ata²/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "ata2"
version = "3.0.0"
name = "ata"
version = "3.1.0"
edition = "2021"
authors = ["Fredrick R. Brennan <copypaste@kittens.ph>", "Rik Huijzer <t.h.huijzer@rug.nl>", "ATA Project Authors"]
homepage = "https://github.com/ctrlcctrlv/ata2"
repository = "https://github.com/ctrlcctrlv/ata2"
readme = "README.md"
description = "Ask the Terminal Anything² — ChatGPT¾ in your terminal"
license = "Apache-2.0"

[[bin]]
Expand All @@ -28,6 +32,7 @@ once_cell = "1.18.0"
atty = "0.2.14"
async-openai = { version = "0.16.2", features = ["native-tls-vendored"] }
futures-util = { version = "0.3.29", features = ["io"] }
tokio-stream = { version = "0.1.14", features = ["sync", "full"] }

[dev-dependencies]
pretty_assertions = "1"
16 changes: 8 additions & 8 deletions ata²/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Command-line argument parsing (using [`clap`]).
//!
//! # ata²
//!
//! © 2023 Fredrick R. Brennan <copypaste@kittens.ph>
Expand All @@ -15,20 +17,14 @@
//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//! See the License for the specific language governing permissions and
//! limitations under the License.
//!
//! Ask the Terminal Anything (ATA): OpenAI GPT in the terminal

use crate::config::ConfigLocation;

use clap::Parser;

use once_cell::sync::Lazy;

#[allow(non_upper_case_globals)]
static AUTHORS: Lazy<&'static str> = Lazy::new(|| crate_authors!("\n\t"));
use clap::{crate_authors, crate_version};

#[derive(Parser, Debug)]
#[command(author = &*AUTHORS, version = crate_version!(),
#[command(author = crate_authors!(), version = crate_version!(),
about, long_about = None,
help_template = "{before-help}{name} {version} — {about}\
\n\n\
Expand All @@ -49,4 +45,8 @@ pub struct Ata2 {
/// Print the keyboard shortcuts.
#[arg(long)]
pub print_shortcuts: bool,

/// Conversation file to load.
#[arg(short = 'l', long = "load")]
pub load: Option<String>,
}
Loading