shell-gpt-plus 1.1.0__tar.gz

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.
Files changed (42) hide show
  1. shell_gpt_plus-1.1.0/LICENSE +21 -0
  2. shell_gpt_plus-1.1.0/PKG-INFO +601 -0
  3. shell_gpt_plus-1.1.0/README.md +555 -0
  4. shell_gpt_plus-1.1.0/pyproject.toml +106 -0
  5. shell_gpt_plus-1.1.0/sgpt/__init__.py +5 -0
  6. shell_gpt_plus-1.1.0/sgpt/__main__.py +3 -0
  7. shell_gpt_plus-1.1.0/sgpt/__version__.py +1 -0
  8. shell_gpt_plus-1.1.0/sgpt/app.py +276 -0
  9. shell_gpt_plus-1.1.0/sgpt/cache.py +61 -0
  10. shell_gpt_plus-1.1.0/sgpt/config.py +92 -0
  11. shell_gpt_plus-1.1.0/sgpt/function.py +67 -0
  12. shell_gpt_plus-1.1.0/sgpt/functions/execute_shell.py +86 -0
  13. shell_gpt_plus-1.1.0/sgpt/functions/fetch_url.py +44 -0
  14. shell_gpt_plus-1.1.0/sgpt/functions/recall.py +39 -0
  15. shell_gpt_plus-1.1.0/sgpt/functions/remember.py +37 -0
  16. shell_gpt_plus-1.1.0/sgpt/functions/web_search.py +52 -0
  17. shell_gpt_plus-1.1.0/sgpt/handlers/__init__.py +0 -0
  18. shell_gpt_plus-1.1.0/sgpt/handlers/chat_handler.py +177 -0
  19. shell_gpt_plus-1.1.0/sgpt/handlers/default_handler.py +22 -0
  20. shell_gpt_plus-1.1.0/sgpt/handlers/handler.py +253 -0
  21. shell_gpt_plus-1.1.0/sgpt/handlers/repl_handler.py +66 -0
  22. shell_gpt_plus-1.1.0/sgpt/init_config.py +27 -0
  23. shell_gpt_plus-1.1.0/sgpt/integration.py +27 -0
  24. shell_gpt_plus-1.1.0/sgpt/llm_functions/__init__.py +0 -0
  25. shell_gpt_plus-1.1.0/sgpt/llm_functions/common/execute_shell.py +42 -0
  26. shell_gpt_plus-1.1.0/sgpt/llm_functions/init_functions.py +35 -0
  27. shell_gpt_plus-1.1.0/sgpt/llm_functions/mac/apple_script.py +47 -0
  28. shell_gpt_plus-1.1.0/sgpt/printer.py +65 -0
  29. shell_gpt_plus-1.1.0/sgpt/role.py +189 -0
  30. shell_gpt_plus-1.1.0/sgpt/roles/Code Generator.json +4 -0
  31. shell_gpt_plus-1.1.0/sgpt/roles/Shell Command Descriptor.json +4 -0
  32. shell_gpt_plus-1.1.0/sgpt/roles/Shell Command Generator.json +4 -0
  33. shell_gpt_plus-1.1.0/sgpt/roles/ShellGPT.json +4 -0
  34. shell_gpt_plus-1.1.0/sgpt/utils.py +95 -0
  35. shell_gpt_plus-1.1.0/tests/__init__.py +0 -0
  36. shell_gpt_plus-1.1.0/tests/_integration.py +498 -0
  37. shell_gpt_plus-1.1.0/tests/conftest.py +8 -0
  38. shell_gpt_plus-1.1.0/tests/test_code.py +144 -0
  39. shell_gpt_plus-1.1.0/tests/test_default.py +250 -0
  40. shell_gpt_plus-1.1.0/tests/test_roles.py +55 -0
  41. shell_gpt_plus-1.1.0/tests/test_shell.py +189 -0
  42. shell_gpt_plus-1.1.0/tests/utils.py +59 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Farkhod Sadykov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,601 @@
1
+ Metadata-Version: 2.4
2
+ Name: shell-gpt-plus
3
+ Version: 1.1.0
4
+ Summary: A command-line productivity tool powered by large language models (Chinese enhanced, with web search and tool-use).
5
+ Project-URL: homepage, https://github.com/zzzjjj-ss/shell-gpt-plus
6
+ Project-URL: repository, https://github.com/zzzjjj-ss/shell-gpt-plus
7
+ Project-URL: documentation, https://github.com/zzzjjj-ss/shell-gpt-plus/blob/main/README.md
8
+ Author-email: Farkhod Sadykov <farkhod@sadykov.dev>, zzzjjj-ss <15728641935@163.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: cheet-sheet,chinese,cli,deepseek,gpt,ollama,openai,productivity,shell
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Information Technology
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development
22
+ Requires-Python: >=3.10
23
+ Requires-Dist: beautifulsoup4
24
+ Requires-Dist: distro<2.0.0,>=1.8.0
25
+ Requires-Dist: lxml
26
+ Requires-Dist: openai<3.0.0,>=2.0.0
27
+ Requires-Dist: prompt-toolkit>=3.0.51
28
+ Requires-Dist: pyreadline3<4.0.0,>=3.4.1; sys_platform == 'win32'
29
+ Requires-Dist: requests
30
+ Requires-Dist: rich<14.0.0,>=13.1.0
31
+ Requires-Dist: typer<1.0.0,>=0.7.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: pre-commit<4.0.0,>=3.1.1; extra == 'dev'
34
+ Requires-Dist: ruff==0.0.256; extra == 'dev'
35
+ Provides-Extra: litellm
36
+ Requires-Dist: litellm==1.83.4; extra == 'litellm'
37
+ Provides-Extra: test
38
+ Requires-Dist: black==23.1.0; extra == 'test'
39
+ Requires-Dist: codespell<3.0.0,>=2.2.5; extra == 'test'
40
+ Requires-Dist: isort<6.0.0,>=5.12.0; extra == 'test'
41
+ Requires-Dist: mypy==1.1.1; extra == 'test'
42
+ Requires-Dist: pytest<8.0.0,>=7.2.2; extra == 'test'
43
+ Requires-Dist: requests-mock[fixture]<2.0.0,>=1.10.0; extra == 'test'
44
+ Requires-Dist: types-requests==2.28.11.17; extra == 'test'
45
+ Description-Content-Type: text/markdown
46
+
47
+ # shell-gpt-plus (中文增强版)
48
+
49
+ 基于 [TheR1D/shell_gpt](https://github.com/TheR1D/shell_gpt) 深度定制的命令行 AI 助手,专为国内用户优化,支持 **DeepSeek** 等兼容 OpenAI 接口的模型,内置联网搜索与文件操作工具,全中文交互,开箱即用。
50
+
51
+ ## ✨ 增强功能
52
+
53
+ - 🧠 **修复函数调用兼容性** – 解决与 DeepSeek 思维链(`reasoning_content`)的冲突,函数调用稳定可用。
54
+ - 🌐 **内置联网搜索** – 提供 `web_search` 和 `fetch_url` 工具,让 AI 实时查询网页内容。
55
+ - 🔧 **可扩展工具集** – 已包含 `execute_shell_command`、`web_search`、`fetch_url`,可按需自定义。
56
+ - 🧰 **全中文角色** – 所有系统角色(Shell 命令生成、代码生成、命令解释等)均已汉化。
57
+ - 📦 **一键部署** – 安装后首次运行自动部署中文角色和工具,无需手动复制文件。
58
+ - 🚀 **国内 API 直连** – 默认配置指向 DeepSeek(`api.deepseek.com`),也可自行修改。
59
+
60
+ ## 快速开始
61
+
62
+ ### 前置条件
63
+
64
+ - **Python 3.10 或以上**
65
+ - **Git**(用于 `pip install git+...`)
66
+ - **DeepSeek API Key**([申请地址](https://platform.deepseek.com/))或其他兼容 OpenAI 接口的 Key
67
+
68
+ ### 安装
69
+
70
+ 在终端中执行:
71
+
72
+ ```bash
73
+ py -m pip install git+https://github.com/zzzjjj-ss/shell-gpt-plus.git@v1.0.0
74
+ ```
75
+
76
+ ### 使用
77
+
78
+ 在终端中执行:
79
+
80
+ ```bash
81
+ py -m sgpt "你好"
82
+ ```
83
+
84
+
85
+
86
+ ### Windows 平台快速调用(可选)
87
+
88
+ 为方便在任意路径下直接使用 `sgpt` 命令,可创建批处理脚本并添加至系统 PATH。
89
+
90
+ 1. 在项目目录(或固定路径,例如 `C:\Tools\shell-gpt-plus`)新建文件 `sgpt.bat`,写入以下内容:
91
+
92
+ ```batch
93
+ @echo off
94
+ py -m sgpt %*
95
+ ```
96
+
97
+ 2. 将 `sgpt.bat` 所在目录的**绝对路径**添加到系统环境变量 `PATH` 中:
98
+ - 按 `Win + R`,输入 `sysdm.cpl` 并回车。
99
+ - 点击 **高级** → **环境变量**。
100
+ - 在 **用户变量** 或 **系统变量** 中找到 `Path`,双击编辑。
101
+ - 点击 **新建**,粘贴目录路径(如 `C:\Tools\shell-gpt-plus`),依次确定保存。
102
+
103
+ 3. 重新打开任意命令行窗口,输入以下命令验证:
104
+
105
+ ```batch
106
+ sgpt "你好"
107
+ ```
108
+
109
+ 正常返回 AI 回复即表示配置成功。
110
+
111
+
112
+
113
+ ### 卸载
114
+
115
+ 若需从系统中完全移除 shell-gpt-plus,请按以下步骤操作:
116
+
117
+ 1. **卸载 Python 包**
118
+ ```bash
119
+ py -m pip uninstall shell-gpt-plus
120
+ ```
121
+
122
+ 2. **移除 Windows 快速调用配置(如已配置)**
123
+ - 删除之前创建的 `sgpt.bat` 文件。
124
+ - 从系统环境变量 `PATH` 中删除该文件所在目录(参考上方第2步进入环境变量设置)。
125
+
126
+ 3. **删除配置文件与缓存(可选)**
127
+ - **Linux / macOS**:`rm ~/.config/shell_gpt`
128
+ - **Windows**:手动删除 `C:\Users\你的用户名\.config\shell_gpt` 文件夹。
129
+
130
+
131
+
132
+ ###注意
133
+ 本项目AI没有上下文/记忆
134
+
135
+
136
+
137
+ * * *
138
+
139
+ # 以下为原版 README
140
+
141
+ # ShellGPT
142
+ A command-line productivity tool powered by AI large language models (LLM). This command-line tool offers streamlined generation of **shell commands, code snippets, documentation**, eliminating the need for external resources (like Google search). Supports Linux, macOS, Windows and compatible with all major Shells like PowerShell, CMD, Bash, Zsh, etc.
143
+
144
+ https://github.com/TheR1D/shell_gpt/assets/16740832/721ddb19-97e7-428f-a0ee-107d027ddd59
145
+
146
+ ## Installation
147
+ ```shell
148
+ pip install shell-gpt
149
+ ```
150
+ By default, ShellGPT uses OpenAI's API and GPT-4 model. You'll need an API key, you can generate one [here](https://platform.openai.com/api-keys). You will be prompted for your key which will then be stored in `~/.config/shell_gpt/.sgptrc`. OpenAI API is not free of charge, please refer to the [OpenAI pricing](https://openai.com/pricing) for more information.
151
+
152
+ > [!TIP]
153
+ > Alternatively, you can run open-source models locally for free. This requires setting up your own LLM backend, such as [Ollama](https://github.com/ollama/ollama). To get ShellGPT working with Ollama, follow this detailed [guide](https://github.com/TheR1D/shell_gpt/wiki/Ollama)
154
+ >
155
+ > **❗️Note that ShellGPT is not optimized for local models and may not work as expected.**
156
+
157
+ ## Usage
158
+ **ShellGPT** is designed to quickly analyse and retrieve information. It's useful for straightforward requests ranging from technical configurations to general knowledge.
159
+ ```shell
160
+ sgpt "What is the fibonacci sequence"
161
+ # -> The Fibonacci sequence is a series of numbers where each number ...
162
+ ```
163
+
164
+ ShellGPT accepts prompt from both stdin and command line argument. Whether you prefer piping input through the terminal or specifying it directly as arguments, `sgpt` got you covered. For example, you can easily generate a git commit message based on a diff:
165
+ ```shell
166
+ git diff | sgpt "Generate git commit message, for my changes"
167
+ # -> Added main feature details into README.md
168
+ ```
169
+
170
+ You can analyze logs from various sources by passing them using stdin, along with a prompt. For instance, we can use it to quickly analyze logs, identify errors and get suggestions for possible solutions:
171
+ ```shell
172
+ docker logs -n 20 my_app | sgpt "check logs, find errors, provide possible solutions"
173
+ ```
174
+ ```text
175
+ Error Detected: Connection timeout at line 7.
176
+ Possible Solution: Check network connectivity and firewall settings.
177
+ Error Detected: Memory allocation failed at line 12.
178
+ Possible Solution: Consider increasing memory allocation or optimizing application memory usage.
179
+ ```
180
+
181
+ You can also use all kind of redirection operators to pass input:
182
+ ```shell
183
+ sgpt "summarise" < document.txt
184
+ # -> The document discusses the impact...
185
+ sgpt << EOF
186
+ What is the best way to lear Golang?
187
+ Provide simple hello world example.
188
+ EOF
189
+ # -> The best way to learn Golang...
190
+ sgpt <<< "What is the best way to learn shell redirects?"
191
+ # -> The best way to learn shell redirects is through...
192
+ ```
193
+
194
+
195
+ ### Shell commands
196
+ Have you ever found yourself forgetting common shell commands, such as `find`, and needing to look up the syntax online? With `--shell` or shortcut `-s` option, you can quickly generate and execute the commands you need right in the terminal.
197
+ ```shell
198
+ sgpt --shell "find all json files in current folder"
199
+ # -> find . -type f -name "*.json"
200
+ # -> [E]xecute, [D]escribe, [A]bort: e
201
+ ```
202
+
203
+ Shell GPT is aware of OS and `$SHELL` you are using, it will provide shell command for specific system you have. For instance, if you ask `sgpt` to update your system, it will return a command based on your OS. Here's an example using macOS:
204
+ ```shell
205
+ sgpt -s "update my system"
206
+ # -> sudo softwareupdate -i -a
207
+ # -> [E]xecute, [D]escribe, [A]bort: e
208
+ ```
209
+
210
+ The same prompt, when used on Ubuntu, will generate a different suggestion:
211
+ ```shell
212
+ sgpt -s "update my system"
213
+ # -> sudo apt update && sudo apt upgrade -y
214
+ # -> [E]xecute, [D]escribe, [A]bort: e
215
+ ```
216
+
217
+ Let's try it with Docker:
218
+ ```shell
219
+ sgpt -s "start nginx container, mount ./index.html"
220
+ # -> docker run -d -p 80:80 -v $(pwd)/index.html:/usr/share/nginx/html/index.html nginx
221
+ # -> [E]xecute, [D]escribe, [A]bort: e
222
+ ```
223
+
224
+ We can still use pipes to pass input to `sgpt` and generate shell commands:
225
+ ```shell
226
+ sgpt -s "POST localhost with" < data.json
227
+ # -> curl -X POST -H "Content-Type: application/json" -d '{"a": 1, "b": 2}' http://localhost
228
+ # -> [E]xecute, [D]escribe, [A]bort: e
229
+ ```
230
+
231
+ Applying additional shell magic in our prompt, in this example passing file names to `ffmpeg`:
232
+ ```shell
233
+ ls
234
+ # -> 1.mp4 2.mp4 3.mp4
235
+ sgpt -s "ffmpeg combine $(ls -m) into one video file without audio."
236
+ # -> ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -filter_complex "[0:v] [1:v] [2:v] concat=n=3:v=1 [v]" -map "[v]" out.mp4
237
+ # -> [E]xecute, [D]escribe, [A]bort: e
238
+ ```
239
+
240
+ If you would like to pass generated shell command using pipe, you can use `--no-interaction` option. This will disable interactive mode and will print generated command to stdout. In this example we are using `pbcopy` to copy generated command to clipboard:
241
+ ```shell
242
+ sgpt -s "find all json files in current folder" --no-interaction | pbcopy
243
+ ```
244
+
245
+
246
+ ### Shell integration
247
+ This is a **very handy feature**, which allows you to use `sgpt` shell completions directly in your terminal, without the need to type `sgpt` with prompt and arguments. Shell integration enables the use of ShellGPT with hotkeys in your terminal, supported by both Bash and ZSH shells. This feature puts `sgpt` completions directly into terminal buffer (input line), allowing for immediate editing of suggested commands.
248
+
249
+ https://github.com/TheR1D/shell_gpt/assets/16740832/bead0dab-0dd9-436d-88b7-6abfb2c556c1
250
+
251
+ To install shell integration, run `sgpt --install-integration` and restart your terminal to apply changes. This will add few lines to your `.bashrc` or `.zshrc` file. After that, you can use `Ctrl+l` (by default) to invoke ShellGPT. When you press `Ctrl+l` it will replace you current input line (buffer) with suggested command. You can then edit it and just press `Enter` to execute.
252
+
253
+ ### Generating code
254
+ By using the `--code` or `-c` parameter, you can specifically request pure code output, for instance:
255
+ ```shell
256
+ sgpt --code "solve fizz buzz problem using python"
257
+ ```
258
+
259
+ ```python
260
+ for i in range(1, 101):
261
+ if i % 3 == 0 and i % 5 == 0:
262
+ print("FizzBuzz")
263
+ elif i % 3 == 0:
264
+ print("Fizz")
265
+ elif i % 5 == 0:
266
+ print("Buzz")
267
+ else:
268
+ print(i)
269
+ ```
270
+ Since it is valid python code, we can redirect the output to a file:
271
+ ```shell
272
+ sgpt --code "solve classic fizz buzz problem using Python" > fizz_buzz.py
273
+ python fizz_buzz.py
274
+ # 1
275
+ # 2
276
+ # Fizz
277
+ # 4
278
+ # Buzz
279
+ # ...
280
+ ```
281
+
282
+ We can also use pipes to pass input:
283
+ ```shell
284
+ cat fizz_buzz.py | sgpt --code "Generate comments for each line of my code"
285
+ ```
286
+ ```python
287
+ # Loop through numbers 1 to 100
288
+ for i in range(1, 101):
289
+ # Check if number is divisible by both 3 and 5
290
+ if i % 3 == 0 and i % 5 == 0:
291
+ # Print "FizzBuzz" if number is divisible by both 3 and 5
292
+ print("FizzBuzz")
293
+ # Check if number is divisible by 3
294
+ elif i % 3 == 0:
295
+ # Print "Fizz" if number is divisible by 3
296
+ print("Fizz")
297
+ # Check if number is divisible by 5
298
+ elif i % 5 == 0:
299
+ # Print "Buzz" if number is divisible by 5
300
+ print("Buzz")
301
+ # If number is not divisible by 3 or 5, print the number itself
302
+ else:
303
+ print(i)
304
+ ```
305
+
306
+ ### Chat Mode
307
+ Often it is important to preserve and recall a conversation. `sgpt` creates conversational dialogue with each LLM completion requested. The dialogue can develop one-by-one (chat mode) or interactively, in a REPL loop (REPL mode). Both ways rely on the same underlying object, called a chat session. The session is located at the [configurable](#runtime-configuration-file) `CHAT_CACHE_PATH`.
308
+
309
+ To start a conversation, use the `--chat` option followed by a unique session name and a prompt.
310
+ ```shell
311
+ sgpt --chat conversation_1 "please remember my favorite number: 4"
312
+ # -> I will remember that your favorite number is 4.
313
+ sgpt --chat conversation_1 "what would be my favorite number + 4?"
314
+ # -> Your favorite number is 4, so if we add 4 to it, the result would be 8.
315
+ ```
316
+
317
+ You can use chat sessions to iteratively improve GPT suggestions by providing additional details. It is possible to use `--code` or `--shell` options to initiate `--chat`:
318
+ ```shell
319
+ sgpt --chat conversation_2 --code "make a request to localhost using python"
320
+ ```
321
+ ```python
322
+ import requests
323
+
324
+ response = requests.get('http://localhost')
325
+ print(response.text)
326
+ ```
327
+
328
+ Let's ask LLM to add caching to our request:
329
+ ```shell
330
+ sgpt --chat conversation_2 --code "add caching"
331
+ ```
332
+ ```python
333
+ import requests
334
+ from cachecontrol import CacheControl
335
+
336
+ sess = requests.session()
337
+ cached_sess = CacheControl(sess)
338
+
339
+ response = cached_sess.get('http://localhost')
340
+ print(response.text)
341
+ ```
342
+
343
+ Same applies for shell commands:
344
+ ```shell
345
+ sgpt --chat conversation_3 --shell "what is in current folder"
346
+ # -> ls
347
+ sgpt --chat conversation_3 "Sort by name"
348
+ # -> ls | sort
349
+ sgpt --chat conversation_3 "Concatenate them using FFMPEG"
350
+ # -> ffmpeg -i "concat:$(ls | sort | tr '\n' '|')" -codec copy output.mp4
351
+ sgpt --chat conversation_3 "Convert the resulting file into an MP3"
352
+ # -> ffmpeg -i output.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 final_output.mp3
353
+ ```
354
+
355
+ To list all the sessions from either conversational mode, use the `--list-chats` or `-lc` option:
356
+ ```shell
357
+ sgpt --list-chats
358
+ # .../shell_gpt/chat_cache/conversation_1
359
+ # .../shell_gpt/chat_cache/conversation_2
360
+ ```
361
+
362
+ To show all the messages related to a specific conversation, use the `--show-chat` option followed by the session name:
363
+ ```shell
364
+ sgpt --show-chat conversation_1
365
+ # user: please remember my favorite number: 4
366
+ # assistant: I will remember that your favorite number is 4.
367
+ # user: what would be my favorite number + 4?
368
+ # assistant: Your favorite number is 4, so if we add 4 to it, the result would be 8.
369
+ ```
370
+
371
+ ### REPL Mode
372
+ There is very handy REPL (read–eval–print loop) mode, which allows you to interactively chat with GPT models. To start a chat session in REPL mode, use the `--repl` option followed by a unique session name. You can also use "temp" as a session name to start a temporary REPL session. Note that `--chat` and `--repl` are using same underlying object, so you can use `--chat` to start a chat session and then pick it up with `--repl` to continue the conversation in REPL mode.
373
+
374
+ <p align="center">
375
+ <img src="https://s10.gifyu.com/images/repl-demo.gif" alt="gif">
376
+ </p>
377
+
378
+ ```text
379
+ sgpt --repl temp
380
+ Entering REPL mode, press Ctrl+C to exit.
381
+ >>> What is REPL?
382
+ REPL stands for Read-Eval-Print Loop. It is a programming environment ...
383
+ >>> How can I use Python with REPL?
384
+ To use Python with REPL, you can simply open a terminal or command prompt ...
385
+ ```
386
+
387
+ REPL mode can work with `--shell` and `--code` options, which makes it very handy for interactive shell commands and code generation:
388
+ ```text
389
+ sgpt --repl temp --shell
390
+ Entering shell REPL mode, type [e] to execute commands or press Ctrl+C to exit.
391
+ >>> What is in current folder?
392
+ ls
393
+ >>> Show file sizes
394
+ ls -lh
395
+ >>> Sort them by file sizes
396
+ ls -lhS
397
+ >>> e (enter just e to execute commands, or d to describe them)
398
+ ```
399
+
400
+ To provide multiline prompt use triple quotes `"""`:
401
+ ```text
402
+ sgpt --repl temp
403
+ Entering REPL mode, press Ctrl+C to exit.
404
+ >>> """
405
+ ... Explain following code:
406
+ ... import random
407
+ ... print(random.randint(1, 10))
408
+ ... """
409
+ It is a Python script that uses the random module to generate and print a random integer.
410
+ ```
411
+
412
+ You can also enter REPL mode with initial prompt by passing it as an argument or stdin or even both:
413
+ ```shell
414
+ sgpt --repl temp < my_app.py
415
+ ```
416
+ ```text
417
+ Entering REPL mode, press Ctrl+C to exit.
418
+ ──────────────────────────────────── Input ────────────────────────────────────
419
+ name = input("What is your name?")
420
+ print(f"Hello {name}")
421
+ ───────────────────────────────────────────────────────────────────────────────
422
+ >>> What is this code about?
423
+ The snippet of code you've provided is written in Python. It prompts the user...
424
+ >>> Follow up questions...
425
+ ```
426
+
427
+ ### Function calling
428
+ [Function calls](https://platform.openai.com/docs/guides/function-calling) is a powerful feature OpenAI provides. It allows LLM to execute functions in your system, which can be used to accomplish a variety of tasks. To install [default functions](https://github.com/TheR1D/shell_gpt/tree/main/sgpt/llm_functions/) run:
429
+ ```shell
430
+ sgpt --install-functions
431
+ ```
432
+
433
+ ShellGPT has a convenient way to define functions and use them. In order to create your custom function, navigate to `~/.config/shell_gpt/functions` and create a new .py file with the function name. Inside this file, you can define your function using this [example](https://github.com/TheR1D/shell_gpt/blob/main/sgpt/llm_functions/common/execute_shell.py).
434
+
435
+ The docstring comment inside the class will be passed to OpenAI API as a description for the function, along with the `title` attribute and parameters descriptions. The `execute` function will be called if LLM decides to use your function. In this case we are allowing LLM to execute any Shell commands in our system. Since we are returning the output of the command, LLM will be able to analyze it and decide if it is a good fit for the prompt. Here is an example how the function might be executed by LLM:
436
+ ```shell
437
+ sgpt "What are the files in /tmp folder?"
438
+ # -> @FunctionCall execute_shell_command(shell_command="ls /tmp")
439
+ # -> The /tmp folder contains the following files and directories:
440
+ # -> test.txt
441
+ # -> test.json
442
+ ```
443
+
444
+ Note that if for some reason the function (execute_shell_command) will return an error, LLM might try to accomplish the task based on the output. Let's say we don't have installed `jq` in our system, and we ask LLM to parse JSON file:
445
+ ```shell
446
+ sgpt "parse /tmp/test.json file using jq and return only email value"
447
+ # -> @FunctionCall execute_shell_command(shell_command="jq -r '.email' /tmp/test.json")
448
+ # -> It appears that jq is not installed on the system. Let me try to install it using brew.
449
+ # -> @FunctionCall execute_shell_command(shell_command="brew install jq")
450
+ # -> jq has been successfully installed. Let me try to parse the file again.
451
+ # -> @FunctionCall execute_shell_command(shell_command="jq -r '.email' /tmp/test.json")
452
+ # -> The email value in /tmp/test.json is johndoe@example.
453
+ ```
454
+
455
+ It is also possible to chain multiple function calls in the prompt:
456
+ ```shell
457
+ sgpt "Play music and open hacker news"
458
+ # -> @FunctionCall play_music()
459
+ # -> @FunctionCall open_url(url="https://news.ycombinator.com")
460
+ # -> Music is now playing, and Hacker News has been opened in your browser. Enjoy!
461
+ ```
462
+
463
+ This is just a simple example of how you can use function calls. It is truly a powerful feature that can be used to accomplish a variety of complex tasks. We have dedicated [category](https://github.com/TheR1D/shell_gpt/discussions/categories/functions) in GitHub Discussions for sharing and discussing functions.
464
+ LLM might execute destructive commands, so please use it at your own risk❗️
465
+
466
+ ### Roles
467
+ ShellGPT allows you to create custom roles, which can be utilized to generate code, shell commands, or to fulfill your specific needs. To create a new role, use the `--create-role` option followed by the role name. You will be prompted to provide a description for the role, along with other details. This will create a JSON file in `~/.config/shell_gpt/roles` with the role name. Inside this directory, you can also edit default `sgpt` roles, such as **shell**, **code**, and **default**. Use the `--list-roles` option to list all available roles, and the `--show-role` option to display the details of a specific role. Here's an example of a custom role:
468
+ ```shell
469
+ sgpt --create-role json_generator
470
+ # Enter role description: Provide only valid json as response.
471
+ sgpt --role json_generator "random: user, password, email, address"
472
+ ```
473
+ ```json
474
+ {
475
+ "user": "JohnDoe",
476
+ "password": "p@ssw0rd",
477
+ "email": "johndoe@example.com",
478
+ "address": {
479
+ "street": "123 Main St",
480
+ "city": "Anytown",
481
+ "state": "CA",
482
+ "zip": "12345"
483
+ }
484
+ }
485
+ ```
486
+
487
+ If the description of the role contains the words "APPLY MARKDOWN" (case sensitive), then chats will be displayed using markdown formatting unless it is explicitly turned off with `--no-md`.
488
+
489
+ ### Request cache
490
+ Control cache using `--cache` (default) and `--no-cache` options. This caching applies for all `sgpt` requests to OpenAI API:
491
+ ```shell
492
+ sgpt "what are the colors of a rainbow"
493
+ # -> The colors of a rainbow are red, orange, yellow, green, blue, indigo, and violet.
494
+ ```
495
+ Next time, same exact query will get results from local cache instantly. Note that `sgpt "what are the colors of a rainbow" --temperature 0.5` will make a new request, since we didn't provide `--temperature` (same applies to `--top-probability`) on previous request.
496
+
497
+ This is just some examples of what we can do using OpenAI GPT models, I'm sure you will find it useful for your specific use cases.
498
+
499
+ ### Runtime configuration file
500
+ You can setup some parameters in runtime configuration file `~/.config/shell_gpt/.sgptrc`:
501
+ ```text
502
+ # API key, also it is possible to define OPENAI_API_KEY env.
503
+ OPENAI_API_KEY=your_api_key
504
+ # Base URL of the backend server. If "default" URL will be resolved based on --model.
505
+ API_BASE_URL=default
506
+ # Max amount of cached message per chat session.
507
+ CHAT_CACHE_LENGTH=100
508
+ # Chat cache folder.
509
+ CHAT_CACHE_PATH=/tmp/shell_gpt/chat_cache
510
+ # Request cache length (amount).
511
+ CACHE_LENGTH=100
512
+ # Request cache folder.
513
+ CACHE_PATH=/tmp/shell_gpt/cache
514
+ # Request timeout in seconds.
515
+ REQUEST_TIMEOUT=60
516
+ # Default OpenAI model to use.
517
+ DEFAULT_MODEL=gpt-5.4-mini
518
+ # Default color for shell and code completions.
519
+ DEFAULT_COLOR=magenta
520
+ # When in --shell mode, default to "Y" for no input.
521
+ DEFAULT_EXECUTE_SHELL_CMD=false
522
+ # Disable streaming of responses
523
+ DISABLE_STREAMING=false
524
+ # The pygment theme to view markdown (default/describe role).
525
+ CODE_THEME=default
526
+ # Path to a directory with functions.
527
+ OPENAI_FUNCTIONS_PATH=/Users/user/.config/shell_gpt/functions
528
+ # Print output of functions when LLM uses them.
529
+ SHOW_FUNCTIONS_OUTPUT=false
530
+ # Allows LLM to use functions.
531
+ OPENAI_USE_FUNCTIONS=true
532
+ # Enforce LiteLLM usage (for local LLMs).
533
+ USE_LITELLM=false
534
+ ```
535
+ Possible options for `DEFAULT_COLOR`: black, red, green, yellow, blue, magenta, cyan, white, bright_black, bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white.
536
+ Possible options for `CODE_THEME`: https://pygments.org/styles/
537
+
538
+ ### Full list of arguments
539
+ ```text
540
+ ╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────╮
541
+ │ prompt [PROMPT] The prompt to generate completions for. │
542
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
543
+ ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────╮
544
+ │ --model TEXT Large language model to use. [default: gpt-5.4-mini] │
545
+ │ --temperature FLOAT RANGE [0.0<=x<=2.0] Randomness of generated output. [default: 0.0] │
546
+ │ --top-p FLOAT RANGE [0.0<=x<=1.0] Limits highest probable tokens (words). [default: 1.0] │
547
+ │ --md --no-md Prettify markdown output. [default: md] │
548
+ │ --editor Open $EDITOR to provide a prompt. [default: no-editor] │
549
+ │ --cache Cache completion results. [default: cache] │
550
+ │ --version Show version. │
551
+ │ --help Show this message and exit. │
552
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
553
+ ╭─ Assistance Options ─────────────────────────────────────────────────────────────────────────────────────╮
554
+ │ --shell -s Generate and execute shell commands. │
555
+ │ --interaction --no-interaction Interactive mode for --shell option. [default: interaction] │
556
+ │ --describe-shell -d Describe a shell command. │
557
+ │ --code -c Generate only code. │
558
+ │ --functions --no-functions Allow function calls. [default: functions] │
559
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
560
+ ╭─ Chat Options ───────────────────────────────────────────────────────────────────────────────────────────╮
561
+ │ --chat TEXT Follow conversation with id, use "temp" for quick session. [default: None] │
562
+ │ --repl TEXT Start a REPL (Read–eval–print loop) session. [default: None] │
563
+ │ --show-chat TEXT Show all messages from provided chat id. [default: None] │
564
+ │ --list-chats -lc List all existing chat ids. │
565
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
566
+ ╭─ Role Options ───────────────────────────────────────────────────────────────────────────────────────────╮
567
+ │ --role TEXT System role for GPT model. [default: None] │
568
+ │ --create-role TEXT Create role. [default: None] │
569
+ │ --show-role TEXT Show role. [default: None] │
570
+ │ --list-roles -lr List roles. │
571
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
572
+ ```
573
+
574
+ ## Docker
575
+ Run the container using the `OPENAI_API_KEY` environment variable, and a docker volume to store cache. Consider to set the environment variables `OS_NAME` and `SHELL_NAME` according to your preferences.
576
+ ```shell
577
+ docker run --rm \
578
+ --env OPENAI_API_KEY=api_key \
579
+ --env OS_NAME=$(uname -s) \
580
+ --env SHELL_NAME=$(echo $SHELL) \
581
+ --volume gpt-cache:/tmp/shell_gpt \
582
+ ghcr.io/ther1d/shell_gpt -s "update my system"
583
+ ```
584
+
585
+ Example of a conversation, using an alias and the `OPENAI_API_KEY` environment variable:
586
+ ```shell
587
+ alias sgpt="docker run --rm --volume gpt-cache:/tmp/shell_gpt --env OPENAI_API_KEY --env OS_NAME=$(uname -s) --env SHELL_NAME=$(echo $SHELL) ghcr.io/ther1d/shell_gpt"
588
+ export OPENAI_API_KEY="your OPENAI API key"
589
+ sgpt --chat rainbow "what are the colors of a rainbow"
590
+ sgpt --chat rainbow "inverse the list of your last answer"
591
+ sgpt --chat rainbow "translate your last answer in french"
592
+ ```
593
+
594
+ You also can use the provided `Dockerfile` to build your own image:
595
+ ```shell
596
+ docker build -t sgpt .
597
+ ```
598
+
599
+ ## Additional documentation
600
+ * [Azure integration](https://github.com/TheR1D/shell_gpt/wiki/Azure)
601
+ * [Ollama integration](https://github.com/TheR1D/shell_gpt/wiki/Ollama)