-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathREADME.md
314 lines (189 loc) · 6.4 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<div align="center">
<h1> Tenere </h1>
<img src="assets/logo.png" alt="A crab in the moroccan desert"></img>
<h2> TUI interface for LLMs written in Rust </h2>
</div>
## 📸 Demo
![Demo](https://github.com/pythops/tenere/assets/57548585/b33ed59b-1d94-4bc5-8e61-73e63f41137e)
<br>
## 🪄 Featues
- Syntax highlights
- Chat history
- Save chats to files
- Vim keybinding (most common ops)
- Copy text from/to clipboard (works only on the prompt)
- Multiple backends
- Automatically load the last saved chat into history
<br>
## 💎 Supported Backends
- [x] ChatGPT
- [x] llama.cpp
- [x] ollama
<br>
## 🚀 Installation
### 📥 Binary releases
You can download the pre-built binaries from the [release page](https://github.com/pythops/tenere/releases)
### 📦 crates.io
`tenere` can be installed from [crates.io](https://crates.io/crates/tenere)
```shell
cargo install tenere
```
### ❄️ NixOS / Nix
Tenere is available in nixpkgs and can be installed via configuration.nix:
```nix
environment.systemPackages = with pkgs; [
tenere
];
```
For non-NixOS systems, install directly with:
```nix
nix-env -iA nixpkgs.tenere
```
### ⚒️ Build from source
To build from the source, you need [Rust](https://www.rust-lang.org/) compiler and
[Cargo package manager](https://doc.rust-lang.org/cargo/).
Once Rust and Cargo are installed, run the following command to build:
```shell
cargo build --release
```
This will produce an executable file at `target/release/tenere` that you can copy to a directory in your `$PATH`.
<br>
## ⚙️ Configuration
Tenere can be configured using a TOML configuration file. By default, the configuration file is located at:
- **Linux**: `$HOME/.config/tenere/config.toml` or `$XDG_CONFIG_HOME/tenere/config.toml`
- **Mac**: `$HOME/Library/Application Support/tenere/config.toml`
- **Windows**: `~/AppData/Roaming/tenere/config.toml`
### 🛠 Custom Configuration Path
You can optionally specify a custom path for the configuration file using the `-c` flag. This allows you to override the default configuration file location.
### Example Usage
```sh
# Use the default configuration path
tenere
# Specify a custom configuration path
tenere -c ~/path/to/custom/config.toml
```
### General settings
Here are the available general settings:
- `llm`: the llm model name. Possible values are:
- `chatgpt`
- `llamacpp`
- `ollama`
```toml
llm = "chatgpt"
```
### Key bindings
Tenere supports customizable key bindings.
You can modify some of the default key bindings by updating the `[key_bindings]` section in the configuration file.
Here is an example with the default key bindings
```toml
[key_bindings]
show_help = '?'
show_history = 'h'
new_chat = 'n'
```
ℹ️ Note
> To avoid overlapping with vim key bindings, you need to use `ctrl` + `key` except for help `?`.
## Chatgpt
To use `chatgpt` as the backend, you'll need to provide an API key for OpenAI. There are two ways to do this:
Set an environment variable with your API key:
```shell
export OPENAI_API_KEY="YOUTR KEY HERE"
```
Or
Include your API key in the configuration file:
```toml
[chatgpt]
openai_api_key = "Your API key here"
model = "gpt-3.5-turbo"
url = "https://api.openai.com/v1/chat/completions"
```
The default model is set to `gpt-3.5-turbo`. Check out the [OpenAI documentation](https://platform.openai.com/docs/models/gpt-3-5) for more info.
## llama.cpp
To use `llama.cpp` as the backend, you'll need to provide the url that points to the server :
```toml
[llamacpp]
url = "http://localhost:8080/v1/chat/completions"
```
If you configure the server with an api key, then you need to provide it as well:
Setting an environment variable :
```shell
export LLAMACPP_API_KEY="YOUTR KEY HERE"
```
Or
Include your API key in the configuration file:
```toml
[llamacpp]
url = "http://localhost:8080/v1/chat/completions"
api_key = "Your API Key here"
```
More infos about llama.cpp api [here](https://github.com/ggerganov/llama.cpp/blob/master/examples/server/README.md)
## Ollama
To use `ollama` as the backend, you'll need to provide the url that points to the server with the model name :
```toml
[ollama]
url = "http://localhost:11434/api/chat"
model = "Your model name here"
```
More infos about ollama api [here](https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-chat-completion)
<br>
## ⌨️ Key bindings
### Global
These are the default key bindings regardless of the focused block.
`ctrl + n`: Start a new chat and save the previous one in history and save it to `tenere.archive-i` file in `data directory`.
`Tab`: Switch the focus.
`j` or `Down arrow key`: Scroll down
`k` or `Up arrow key`: Scroll up
`ctrl + h` : Show chat history. Press `Esc` to dismiss it.
`ctrl + t` : Stop the stream response
`q` or `ctrl + c`: Quit the app
`?`: Show the help pop-up. Press `Esc` to dismiss it
### Prompt
There are 3 modes like vim: `Normal`, `Visual` and `Insert`.
#### Insert mode
`Esc`: to switch back to Normal mode.
`Enter`: to create a new line.
`Backspace`: to remove the previous character.
#### Normal mode
`Enter`: to submit the prompt
<br>
`h or Left`: Move the cursor backward by one char.
`j or Down`: Move the cursor down.
`k or Up`: Move the cursor up.
`l or Right`: Move the cursor forward by one char.
`w`: Move the cursor right by one word.
`b`: Move the cursor backward by one word.
`0`: Move the cursor to the start of the line.
`$`: Move the cursor to the end of the line.
`G`: Go to the end.
`gg`: Go to the top.
<br>
`a`: Insert after the cursor.
`A`: Insert at the end of the line.
`i`: Insert before the cursor.
`I`: Insert at the beginning of the line.
`o`: Append a new line below the current line.
`O`: Append a new line above the current line.
<br>
`x`: Delete one char under to the cursor.
`dd`: Cut the current line
`D`: Delete the current line and
`dw`: Delete the word next to the cursor.
`db`: Delete the word on the left of the cursor.
`d0`: Delete from the cursor to the beginning of the line.
`d$`: Delete from the cursor to the end of the line.
<br>
`C`: Change to the end of the line.
`cc`: Change the current line.
`c0`: Change from the cursor to the beginning of the line.
`c$`: Change from the cursor to the end of the line.
`cw`: Change the next word.
`cb`: Change the word on the left of the cursor.
<br>
`u`: Undo
`p`: Paste
#### Visual mode
`v`: Switch to visual.
`y`: Yank the selected text
<br>
## ⚖️ License
GNU General Public License v3.0 or later