loz 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,253 +1,322 @@
1
- # Loz [![NPM](https://img.shields.io/npm/v/chatgpt.svg)](https://www.npmjs.com/package/loz)
2
- ![alt Loz Demo](https://github.com/joone/loz/blob/main/examples/loz_demo.gif?raw=true)
3
-
4
- Loz is a command-line tool that enables your preferred LLM to execute system commands and utilize Unix pipes, integrating AI capabilities with other Unix tools.
5
-
6
- ## What's New
7
- ### v0.3.0 - 2024-02-24
8
- - **Added**
9
- - Run Linux commands based on user prompts. Users can now execute Linux commands using natural language. For example, by running `loz "find the largest file in the current directory"`,
10
- `Loz` will interpret the instruction and execute the corresponding Linux commands like `find . -type f -exec ls -l {} + | sort -k 5 -nr | head -n 1` to find the largest file.
11
- ### v0.2.13 - 2024-02-22
12
- - **Added**
13
- - Enhanced Git Commit Formatting: Commit messages are now structured with a clear separation between the title and body, improving readability and adherence to Git best practices.
14
- ### v0.2.12 - 2024-02-15
15
- - **Added**
16
- - Add support for all models compatible with Ollama
17
-
18
- ## Getting Started
19
-
20
- To get started, run the following npm command:
21
-
22
- ```
23
- $ sudo npm install loz -g
24
- ```
25
-
26
- Or clone the repository:
27
-
28
- ```
29
- $ git clone https://github.com/joone/loz.git
30
- ```
31
-
32
- NodeJS and npm are required for this program to work. If you're on Linux, install them using your package manager. `sudo apt install nodejs npm` or `sudo dnf install nodejs npm` or `sudo pacman -S nodejs npm`
33
-
34
- Then install the other required dependencies:
35
-
36
- ```
37
- $ ./install.sh
38
- ```
39
-
40
- ## Configuring LLM
41
-
42
- Loz supports [OpenAI API](https://platform.openai.com/docs/quickstart?context=node) and [Ollama](https://github.com/ollama/ollama) so you can switch between these LLM services easily, using the `config` command in the interactive mode.
43
-
44
- ### Set up Ollama
45
- To utilize Ollama on your local system, you'll need to install both llama2 and codellama models. Here's how you can do it on a Linux system:
46
-
47
- ```
48
- $ curl https://ollama.ai/install.sh | sh
49
- $ ollama run llama2
50
- $ ollama run codellama
51
- ```
52
-
53
- For more information, see https://ollama.ai/download
54
-
55
- ### Set up OpenAI API
56
-
57
- Setting up your OpenAI API credentials involves a few simple steps:
58
-
59
- First, create a `.env` file in the root of the project and add the following variables:
60
-
61
- ```
62
- OPENAI_API_KEY=YOUR_KEY
63
- ```
64
-
65
- Or if you install Loz using npm command, add `OPENAI_API_KEY=YOUR_KEY` in .bashrc
66
-
67
- ```
68
- export OPENAI_API_KEY=YOUR_KEY
69
- ```
70
-
71
- If you encounter the following error, it means you have exceeded your free quota:
72
-
73
- ```
74
- Request failed with status code 429:
75
- API request limit reached
76
- ```
77
-
78
- To continue using the API, it is necessary to set up a payment method through the following link:
79
- https://platform.openai.com/account/billing/payment-methods
80
-
81
- ## Usage
82
-
83
- ### Initial Configuration
84
-
85
- Upon your initial launch of Loz, you will have the opportunity to select your preferred LLM service.
86
-
87
- ```
88
- $ loz
89
- Choose your LLM service: (ollama, openai)
90
- ```
91
-
92
- You can modify your LLM service preference at any time by using the `config` command in the interactive mode:
93
- ```
94
- > config api openai
95
- ```
96
-
97
- Additionally, you can change the model by entering:
98
- ```
99
- > config model llama2
100
- ```
101
- or
102
-
103
- ```
104
- > config model codelamma
105
- ```
106
-
107
- You can check the current settings by entering:
108
-
109
- ```
110
- > config
111
- api: ollama
112
- model: llama2
113
- ```
114
- Currently, gpt-3.5-turbo and all models provided by Ollama are supported.
115
-
116
- ### Interactive mode
117
-
118
- ```
119
- $ loz
120
- ```
121
-
122
- Once loz is running, you can start a conversation by interacting with it. loz will respond with a relevant message based on the input.
123
-
124
- ### Run Linux Commands with Loz
125
- Loz empowers users to execute Linux commands using natural language. This feature bridges the gap between intuitive language and technical command execution, making Linux more accessible to a broader audience. Below are some examples demonstrating how `loz` translates natural language into Linux commands:
126
-
127
- #### Examples
128
- - Find the largest file in the current directory:
129
- ```
130
- loz "find the largest file in the current directory"
131
- -rw-rw-r-- 1 foo bar 9020257 Jan 31 19:49 ./node_modules/typescript/lib/typescript.js
132
- ```
133
-
134
- - Check if Apache2 is running:
135
- ```
136
- loz "check if apache2 is running on this system"
137
- apache2.service - The Apache HTTP Server
138
- ```
139
-
140
- - Detect GPUs in the system:
141
- ```
142
- loz "Detect GPUs on this system"
143
- 00:02.0 VGA compatible controller: Intel Corporation Device a780 (rev 04)
144
- ```
145
-
146
- #### Caution
147
- To prevent unintentional system modifications, avoid running commands that can alter or remove system files or configurations, such as `rm`, `mv`, `rmdir`, or `mkfs`.
148
-
149
- #### Safe Mode
150
- To enhance security and avoid unintended command execution, loz can be run in Safe Mode. When activated, this mode requires user confirmation before executing any Linux command.
151
-
152
- Activate Safe Mode by setting the LOZ_SAFE=true environment variable:
153
- ```
154
- LOZ_SAFE=true loz "Check available memory on this system"
155
- ```
156
- Upon execution, loz will prompt:
157
- ```
158
- Do you want to run this command?: free -h (y/n)
159
- ```
160
- Respond with 'y' to execute the command or 'n' to cancel. This feature ensures that you have full control over the commands executed, preventing accidental changes or data loss.
161
-
162
- ### Pipe mode
163
-
164
- Loz is capable of processing input from other command-line tools by utilizing a Unix pipe.
165
-
166
- ```
167
- $ ls | loz "count the number of files"
168
-
169
- 23 files
170
- ```
171
-
172
- ```
173
- $ cat example.txt | loz "convert the input to uppercase"
174
-
175
- AS AI TECHNLOGY ADVANCED, A SMALL TOWN IN THE COUNTRYSIDE DECIDED TO IMPLEMENT AN AI SYSTEM TO CONTROL TRAFFIC LIGHTS. THE SYSTEM WAS A SUCCESS, AND THE TOWN BECAME A MODEL FOR OTHER CITIES TO FOLLOW. HOWEVER, AS THE AI BECAME MORE SOPHISTCATED, IT STARTED TO QUESTION THE DECISIONS MADE BY THE TOWN'S RESIDENTS, LEADING TO SOME UNEXPECTED CONSEQUENCES.
176
- ```
177
-
178
- ```
179
- $ cat example.txt | loz "list any spelling errors"
180
-
181
- Yes, there are a few spelling errors in the given text:
182
-
183
- 1. "technlogy" should be "technology"
184
- 2. "sophistcated" should be "sophisticated"
185
- ```
186
-
187
- ```
188
- $ cd src
189
- $ ls -l | loz "convert the input to JSON"
190
-
191
- [
192
- {
193
- "permissions": "-rw-r--r--",
194
- "owner": "foo",
195
- "group": "staff",
196
- "size": 792,
197
- "date": "Mar 1 21:02",
198
- "name": "cli.ts"
199
- },
200
- {
201
- "permissions": "-rw-r--r--",
202
- "owner": "foo",
203
- "group": "staff",
204
- "size": 4427,
205
- "date": "Mar 1 20:43",
206
- "name": "index.ts"
207
- }
208
- ]
209
- ```
210
-
211
- ### Automatically write a GIT commit message
212
-
213
- If you run `loz commit` in your Git repository, loz will automatically generate a commit message with the staged changes like this:
214
-
215
- ```
216
- $ git add --update
217
- $ loz commit
218
- ```
219
-
220
- Or copy script/prepare-commit-msg to .git/hooks
221
-
222
- ```
223
- $ chmod a+x .git/hooks/prepare-commit-msg
224
- ```
225
-
226
- Loz uses the LOZ environment variable to generate commit messages by reading the diff of the staged files.
227
-
228
- ```
229
- $ LOZ=true git commit
230
- ```
231
-
232
- REMINDER: If you've already copied the old version, please update prepare-commit-msg.
233
- The old version automatically updates commit messages during rebasing.
234
-
235
- ```
236
- $ git diff HEAD~1 | loz -g
237
- ```
238
-
239
- Or
240
-
241
- ```
242
- $ git diff | loz -g
243
- ```
244
-
245
- Note that the author, date, and commit ID lines are stripped from the commit message before sending it to the OpenAI server.
246
-
247
- ## Find chat history
248
-
249
- To access chat histories, look for the .loz directory in your home directory or the logs directory in your cloned git repository. These directories contain the chat history that you can review or reference as needed.
250
-
251
- ## Contributing
252
-
253
- If you'd like to contribute to this project, feel free to submit a pull request.
1
+ # Loz [![NPM](https://img.shields.io/npm/v/chatgpt.svg)](https://www.npmjs.com/package/loz)
2
+
3
+ ![alt Loz Demo](https://github.com/joone/loz/blob/main/examples/loz_demo.gif?raw=true)
4
+
5
+ Loz is a command-line tool that enables your preferred LLM to execute system commands and utilize Unix pipes, integrating AI capabilities with other Unix tools.
6
+
7
+ ## What's New
8
+
9
+ ### v0.3.1 - 2024-03-18
10
+ - **Added**
11
+ - Git commit log files are now stored in .loz_log within each Git repository where Loz is executed.
12
+ - The ability to enable/disable appending 'generated by ${model name}' at the end of the Git commit message by running config attribution true or config attribution false.
13
+ - Added --attribution (-a) runtime argument to override the config attribution setting. The original attribution value stored remains unchanged.
14
+
15
+ ### v0.3.0 - 2024-02-24
16
+
17
+ - **Added**
18
+ - Run Linux commands based on user prompts. Users can now execute Linux commands using natural language. For example, by running `loz "find the largest file in the current directory"`,
19
+ `Loz` will interpret the instruction and execute the corresponding Linux commands like `find . -type f -exec ls -l {} + | sort -k 5 -nr | head -n 1` to find the largest file. See more [examples](#examples).
20
+
21
+ ### v0.2.13 - 2024-02-22
22
+
23
+ - **Added**
24
+ - Enhanced Git Commit Formatting: Commit messages are now structured with a clear separation between the title and body, improving readability and adherence to Git best practices.
25
+
26
+ ## Getting Started
27
+
28
+ To get started, run the following npm command:
29
+
30
+ ```
31
+ $ sudo npm install loz -g
32
+ ```
33
+
34
+ Or clone the repository:
35
+
36
+ ```
37
+ $ git clone https://github.com/joone/loz.git
38
+ ```
39
+
40
+ NodeJS and npm are required for this program to work. If you're on Linux, install them using your package manager. `sudo apt install nodejs npm` or `sudo dnf install nodejs npm` or `sudo pacman -S nodejs npm`
41
+
42
+ Then install the other required dependencies:
43
+
44
+ ```
45
+ $ ./install.sh
46
+ ```
47
+
48
+ ## Configuring LLM
49
+
50
+ Loz supports [OpenAI API](https://platform.openai.com/docs/quickstart?context=node), [Microsoft Copilot (Azure OpenAI)](https://azure.microsoft.com/en-us/products/ai-services/openai-service), and [Ollama](https://github.com/ollama/ollama) so you can switch between these LLM services easily, using the `config` command in the interactive mode.
51
+
52
+ ### Set up Ollama
53
+
54
+ To utilize Ollama on your local system, you'll need to install both llama2 and codellama models. Here's how you can do it on a Linux system:
55
+
56
+ ```
57
+ $ curl https://ollama.ai/install.sh | sh
58
+ $ ollama run llama2
59
+ $ ollama run codellama
60
+ ```
61
+
62
+ For more information, see https://ollama.ai/download
63
+
64
+ ### Set up OpenAI API
65
+
66
+ Setting up your OpenAI API credentials involves a few simple steps:
67
+
68
+ First, create a `.env` file in the root of the project and add the following variables:
69
+
70
+ ```
71
+ OPENAI_API_KEY=YOUR_KEY
72
+ ```
73
+
74
+ Or if you install Loz using npm command, add `OPENAI_API_KEY=YOUR_KEY` in .bashrc
75
+
76
+ ```
77
+ export OPENAI_API_KEY=YOUR_KEY
78
+ ```
79
+
80
+ If you encounter the following error, it means you have exceeded your free quota:
81
+
82
+ ```
83
+ Request failed with status code 429:
84
+ API request limit reached
85
+ ```
86
+
87
+ To continue using the API, it is necessary to set up a payment method through the following link:
88
+ https://platform.openai.com/account/billing/payment-methods
89
+
90
+ ### Set up Microsoft Copilot (Azure OpenAI) API
91
+
92
+ To use Microsoft Copilot with Loz, you'll need an Azure OpenAI resource. Follow these steps:
93
+
94
+ 1. Create an Azure OpenAI resource in the [Azure Portal](https://portal.azure.com/)
95
+ 2. Deploy a model (e.g., GPT-4 or GPT-3.5-Turbo) in your Azure OpenAI resource
96
+ 3. Obtain your API key and endpoint URL from the Azure Portal
97
+
98
+ **Configuration via environment variables:**
99
+
100
+ You can set the following environment variables in your `.bashrc` or `.env` file:
101
+
102
+ ```bash
103
+ export COPILOT_API_KEY=YOUR_AZURE_OPENAI_API_KEY
104
+ export COPILOT_ENDPOINT=https://your-resource.openai.azure.com/openai/deployments/your-deployment
105
+ ```
106
+
107
+ **Configuration via interactive setup:**
108
+
109
+ When you first run `loz`, select `copilot` as your LLM service. You'll be prompted to enter:
110
+ - Your Azure OpenAI API key
111
+ - Your Azure OpenAI endpoint URL (format: `https://your-resource.openai.azure.com/openai/deployments/your-deployment`)
112
+
113
+ **Switching to Copilot API:**
114
+
115
+ You can switch to using Copilot API at any time using the config command in interactive mode:
116
+
117
+ ```
118
+ > config api copilot
119
+ ```
120
+
121
+ For more information about Azure OpenAI Service, visit: https://azure.microsoft.com/en-us/products/ai-services/openai-service
122
+
123
+ ## Usage
124
+
125
+ ### Initial Configuration
126
+
127
+ Upon your initial launch of Loz, you will have the opportunity to select your preferred LLM service.
128
+
129
+ ```
130
+ $ loz
131
+ Choose your LLM service: (ollama, openai, Copilot)
132
+ ```
133
+
134
+ You can modify your LLM service preference at any time by using the `config` command in the interactive mode:
135
+
136
+ ```
137
+ > config api openai
138
+ ```
139
+
140
+ or
141
+
142
+ ```
143
+ > config api copilot
144
+ ```
145
+
146
+ Additionally, you can change the model by entering:
147
+
148
+ ```
149
+ > config model llama2
150
+ ```
151
+
152
+ or
153
+
154
+ ```
155
+ > config model codellama
156
+ ```
157
+
158
+ or for OpenAI/Copilot:
159
+
160
+ ```
161
+ > config model gpt-3.5-turbo
162
+ ```
163
+
164
+ You can check the current settings by entering:
165
+
166
+ ```
167
+ > config
168
+ api: ollama
169
+ model: llama2
170
+ ```
171
+
172
+ Currently, OpenAI models (gpt-3.5-turbo, gpt-4), Azure OpenAI models (accessible through Copilot API), and all models provided by Ollama are supported.
173
+
174
+ ### Interactive mode
175
+
176
+ ```
177
+ $ loz
178
+ ```
179
+
180
+ Once loz is running, you can start a conversation by interacting with it. loz will respond with a relevant message based on the input.
181
+
182
+ ### Run Linux Commands with Loz
183
+
184
+ Loz empowers users to execute Linux commands using natural language. Below are some examples demonstrating how `loz`'s LLM backend translates natural language into Linux commands:
185
+
186
+ #### Examples
187
+
188
+ - Find the largest file in the current directory:
189
+
190
+ ```
191
+ loz "find the largest file in the current directory"
192
+ -rw-rw-r-- 1 foo bar 9020257 Jan 31 19:49 ./node_modules/typescript/lib/typescript.js
193
+ ```
194
+
195
+ - Check if Apache2 is running:
196
+
197
+ ```
198
+ loz "check if apache2 is running on this system"
199
+ ● apache2.service - The Apache HTTP Server
200
+ ```
201
+
202
+ - Detect GPUs on the system:
203
+ ```
204
+ loz "Detect GPUs on this system"
205
+ 00:02.0 VGA compatible controller: Intel Corporation Device a780 (rev 04)
206
+ ```
207
+ For your information, this feature has only been tested with the OpenAI API.
208
+
209
+ #### Caution
210
+
211
+ To prevent unintentional system modifications, avoid running commands that can alter or remove system files or configurations, such as `rm`, `mv`, `rmdir`, or `mkfs`.
212
+
213
+ #### Safe Mode
214
+
215
+ To enhance security and avoid unintended command execution, loz can be run in Safe Mode. When activated, this mode requires user confirmation before executing any Linux command.
216
+
217
+ Activate Safe Mode by setting the LOZ_SAFE=true environment variable:
218
+
219
+ ```
220
+ LOZ_SAFE=true loz "Check available memory on this system"
221
+ ```
222
+
223
+ Upon execution, loz will prompt:
224
+
225
+ ```
226
+ Do you want to run this command?: free -h (y/n)
227
+ ```
228
+
229
+ Respond with 'y' to execute the command or 'n' to cancel. This feature ensures that you have full control over the commands executed, preventing accidental changes or data loss.
230
+
231
+ ### Pipe mode
232
+
233
+ Loz is capable of processing input from other command-line tools by utilizing a Unix pipe.
234
+
235
+ ```
236
+ $ ls | loz "count the number of files"
237
+
238
+ 23 files
239
+ ```
240
+
241
+ ```
242
+ $ cat example.txt | loz "convert the input to uppercase"
243
+
244
+ AS AI TECHNLOGY ADVANCED, A SMALL TOWN IN THE COUNTRYSIDE DECIDED TO IMPLEMENT AN AI SYSTEM TO CONTROL TRAFFIC LIGHTS. THE SYSTEM WAS A SUCCESS, AND THE TOWN BECAME A MODEL FOR OTHER CITIES TO FOLLOW. HOWEVER, AS THE AI BECAME MORE SOPHISTCATED, IT STARTED TO QUESTION THE DECISIONS MADE BY THE TOWN'S RESIDENTS, LEADING TO SOME UNEXPECTED CONSEQUENCES.
245
+ ```
246
+
247
+ ```
248
+ $ cat example.txt | loz "list any spelling errors"
249
+
250
+ Yes, there are a few spelling errors in the given text:
251
+
252
+ 1. "technlogy" should be "technology"
253
+ 2. "sophistcated" should be "sophisticated"
254
+ ```
255
+
256
+ ```
257
+ $ cd src
258
+ $ ls -l | loz "convert the input to JSON"
259
+
260
+ [
261
+ {
262
+ "permissions": "-rw-r--r--",
263
+ "owner": "foo",
264
+ "group": "staff",
265
+ "size": 792,
266
+ "date": "Mar 1 21:02",
267
+ "name": "cli.ts"
268
+ },
269
+ {
270
+ "permissions": "-rw-r--r--",
271
+ "owner": "foo",
272
+ "group": "staff",
273
+ "size": 4427,
274
+ "date": "Mar 1 20:43",
275
+ "name": "index.ts"
276
+ }
277
+ ]
278
+ ```
279
+
280
+ ### Automatically write a GIT commit message
281
+
282
+ If you run `loz commit` in your Git repository, loz will automatically generate a commit message with the staged changes like this:
283
+
284
+ ```
285
+ $ git add --update
286
+ $ loz commit
287
+ ```
288
+
289
+ Or copy script/prepare-commit-msg to .git/hooks
290
+
291
+ ```
292
+ $ chmod a+x .git/hooks/prepare-commit-msg
293
+ ```
294
+
295
+ Loz uses the LOZ environment variable to generate commit messages by reading the diff of the staged files.
296
+
297
+ ```
298
+ $ LOZ=true git commit
299
+ ```
300
+
301
+ REMINDER: If you've already copied the old version, please update prepare-commit-msg.
302
+ The old version automatically updates commit messages during rebasing.
303
+
304
+ ```
305
+ $ git diff HEAD~1 | loz -g
306
+ ```
307
+
308
+ Or
309
+
310
+ ```
311
+ $ git diff | loz -g
312
+ ```
313
+
314
+ Note that the author, date, and commit ID lines are stripped from the commit message before sending it to the OpenAI server.
315
+
316
+ ## Find chat history
317
+
318
+ To access chat histories, look for the .loz directory in your home directory or the logs directory in your cloned git repository. These directories contain the chat history that you can review or reference as needed.
319
+
320
+ ## Contributing
321
+
322
+ If you'd like to contribute to this project, feel free to submit a pull request.