Skip to content

Commit 7ca2441

Browse files
committed
Added Custom Commands plugin
1 parent 75a3c9e commit 7ca2441

File tree

13 files changed

+374
-16
lines changed

13 files changed

+374
-16
lines changed

README.md

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# PYGPT v2
22

3-
Release: **2.0.8** build: **2023.12.08** | Official website: https://pygpt.net | Docs: https://pygpt.readthedocs.io
3+
Release: **2.0.9** build: **2023.12.09** | Official website: https://pygpt.net | Docs: https://pygpt.readthedocs.io
44

55
PyPi: https://pypi.org/project/pygpt-net
66

77
### **Compiled versions for Linux and Windows**: https://pygpt.net/#download
88

99
## Overview
1010

11-
**PYGPT** is **all-in-one** desktop AI assistant that provides direct interaction with OpenAI language models, including `GPT-4`, `GPT-4 Vision`, and `GPT-3.5`, through the `OpenAI API`. The application also integrates with alternative LLMs, like those available on `HuggingFace`, by utilizing `Langchain`.
11+
**PYGPT** is **all-in-one** Desktop AI Assistant that provides direct interaction with OpenAI language models, including `GPT-4`, `GPT-4 Vision`, and `GPT-3.5`, through the `OpenAI API`. The application also integrates with alternative LLMs, like those available on `HuggingFace`, by utilizing `Langchain`.
1212

13-
This assistant offers multiple modes of operation such as chat, assistants, completions, and image-related tasks using `DALL-E 3` for generation and `GPT-4 Vision` for analysis. **PYGPT** has filesystem capabilities for file I/O, can generate and run Python code, execute system commands, and manage file transfers. It also allows models to perform web searches with the `Google Custom Search API`.
13+
This assistant offers multiple modes of operation such as chat, assistants, completions, and image-related tasks using `DALL-E 3` for generation and `GPT-4 Vision` for analysis. **PYGPT** has filesystem capabilities for file I/O, can generate and run Python code, execute system commands, execute custom commands and manage file transfers. It also allows models to perform web searches with the `Google Custom Search API`.
1414

1515
For audio interactions, **PYGPT** includes speech synthesis using the `Microsoft Azure Text-to-Speech API` and `OpenAI's TTS API`. Additionally, it features speech recognition capabilities provided by `OpenAI Whisper`, enabling the application to understand spoken commands and transcribe audio inputs into text. It features context memory with save and load functionality, enabling users to resume interactions from predefined points in the conversation. Prompt creation and management are streamlined through an intuitive preset system.
1616

@@ -35,6 +35,7 @@ You can download compiled version for Windows and Linux here: https://pygpt.net/
3535
- Image analysis via `GPT-4 Vision`.
3636
- Integrated `Langchain` support (you can connect to any LLM, e.g., on `HuggingFace`).
3737
- Commands execution (via plugins: access to the local filesystem, Python code interpreter, system commands execution).
38+
- Custom commands creation and execution
3839
- Manages files and attachments with options to upload, download, and organize.
3940
- Context history with the capability to revert to previous contexts (long-term memory).
4041
- Allows you to easily manage prompts with handy editable presets.
@@ -370,6 +371,8 @@ The plugin can also execute system commands, allowing GPT to integrate with your
370371
Plugins can work in conjunction to perform sequential tasks; for example, the `Files` plugin can write generated
371372
Python code to a file, which the `Code Interpreter` can execute it and return its result to GPT.
372373

374+
- `Command: Custom Commands` - allows you to create and execute custom commands on your system.
375+
373376
- `Audio Output (Microsoft Azure)` - provides voice synthesis using the Microsoft Azure Text To Speech API.
374377

375378
- `Audio Output (OpenAI TTS)` - provides voice synthesis using the OpenAI Text To Speech API.
@@ -522,10 +525,11 @@ The plugin allows for file management within the local filesystem. It enables th
522525
Plugin capabilities include:
523526

524527
- Reading files
528+
- Appending to files
525529
- Writing files
526-
- Executing code from files
527-
- Creating directories
530+
- Deleting files
528531
- Listing files and directories
532+
- Creating directories
529533

530534
If a file being created (with the same name) already exists, a prefix including the date and time is added to the file name.
531535

@@ -589,6 +593,69 @@ Allow Python code execution from existing file. *Default:* `True`
589593
Allow system commands execution. *Default:* `True`
590594

591595

596+
## Command: Custom Commands
597+
598+
With the `Custom Commands` plugin, you can integrate PYGPT with your operating system and scripts or applications. You can define an unlimited number of custom commands and instruct GPT on when and how to execute them. Configuration is straightforward, and PYGPT includes a simple tutorial command for testing and learning how it works:
599+
600+
![v2_custom_cmd](https://github.com/szczyglis-dev/py-gpt/assets/61396542/f236a30e-3c17-49f4-94df-597cf41feed7)
601+
602+
To add a new custom command, click the 'ADD' button and then:
603+
604+
1. Provide a name for your command: this is a unique identifier for GPT.
605+
2. Provide an `instruction` explaining what this command does; GPT will know when to use the command based on this instruction.
606+
3. Define `params`, separated by commas - GPT will send data to your commands using these params. These params will be placed into placeholders you have defined in the `cmd` field. For example:
607+
608+
If you want instruct GPT to execute your Python script named `smart_home_lights.py` with an argument, such as `1` to turn the light ON, and `0` to turn it OFF, define it as follows:
609+
610+
- **name**: lights_cmd
611+
- **instruction**: turn lights on/off; use 1 as 'arg' to turn ON, or 0 as 'arg' to turn OFF
612+
- **params**: arg
613+
- **cmd**: `python /path/to/smart_home_lights.py {arg}`
614+
615+
The setup defined above will work as follows:
616+
617+
When you ask GPT to turn your lights ON, GPT will locate this command and prepare the command `python /path/to/smart_home_lights.py {arg}` with `{arg}` replaced with `1`. On your system, it will execute the command:
618+
619+
```python /path/to/smart_home_lights.py 1```
620+
621+
And that's all. GPT will take care of the rest when you ask to turn ON the lights.
622+
623+
You can define as many placeholders and parameters as you desire.
624+
625+
Here are some predefined system placeholders for use:
626+
627+
- `{_time}` - current time in `Y-m-d` format
628+
- `{_date}` - current date in `H:M:S` format
629+
- `{_datetime}` - current date and time in `Y-m-d H:M:S` format
630+
- `{_file}` - path to the file from which the command is invoked
631+
- `{_home}` - path to PYGPT's home/workworking directory
632+
633+
You can connect predefined placeholders with your own params.
634+
635+
*Example:*
636+
637+
- **name**: song_cmd
638+
- **instruction**: store the generated song on hard disk
639+
- **params**: song_text, title
640+
- **cmd**: `echo "{song_text}" > {_home}/{title}.txt`
641+
642+
643+
With the setup above, every time you ask GPT to generate a song for you and save it to the disk, it will:
644+
645+
1. Generate a song.
646+
2. Locate your command.
647+
3. Execute the command by sending the song's title and text.
648+
4. The command will save the song text into a file named with the song's title in the PYGPT working directory.
649+
650+
**Example tutorial command**
651+
652+
PYGPT provides simple tutorial command to show how it work, to run it just ask GPT for execute `tutorial test command` and it will show you how it works:
653+
654+
```> please execute tutorial test command```
655+
656+
![v2_code_execute_example](https://github.com/szczyglis-dev/py-gpt/assets/61396542/acd16409-c66f-461b-ba6f-69ba682805f7)
657+
658+
592659
## Command: Google Web Search
593660

594661
**PYGPT** lets you connect GPT to the internet and carry out web searches in real time as you make queries.
@@ -952,6 +1019,10 @@ may consume additional tokens that are not displayed in the main window.
9521019

9531020
# CHANGELOG
9541021

1022+
## 2.0.9 (2023-12-09)
1023+
1024+
- Added `Custom Commands` feature; it allows to easily create and execute custom commands
1025+
9551026
## 2.0.8 (2023-12-08)
9561027

9571028
- Improved Web Search plugin

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
project = 'PYGPT'
1010
copyright = '2023, pygpt.net'
1111
author = 'szczyglis-dev, Marcin Szczygliński'
12-
release = '2.0.8'
12+
release = '2.0.9'
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
51.2 KB
Loading

docs/source/images/v2_custom_cmd.png

51.1 KB
Loading

docs/source/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
PYGPT v2 - pygpt.net
77
====================
88

9-
| **Last update:** 2023-12-08 17:00
9+
| **Last update:** 2023-12-09 11:00
1010
| **Project website:** https://pygpt.net
1111
| **GitHub:** https://github.com/szczyglis-dev/py-gpt
1212
| **PyPI:** https://pypi.org/project/pygpt-net
13-
| **Release:** 2.0.8 (2023-12-08)
13+
| **Release:** 2.0.9 (2023-12-08)
1414
1515
.. toctree::
1616
:maxdepth: 3

docs/source/intro.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Introduction
44
Overview
55
----------------
66

7-
**PYGPT** is **all-in-one** desktop AI assistant that provides direct interaction with OpenAI language models, including ``GPT-4``, ``GPT-4 Vision``, and ``GPT-3.5``, through the ``OpenAI API``. The application also integrates with alternative LLMs, like those available on ``HuggingFace``, by utilizing ``Langchain``.
7+
**PYGPT** is **all-in-one** Desktop AI Assistant that provides direct interaction with OpenAI language models, including ``GPT-4``, ``GPT-4 Vision``, and ``GPT-3.5``, through the ``OpenAI API``. The application also integrates with alternative LLMs, like those available on ``HuggingFace``, by utilizing ``Langchain``.
88

99
This assistant offers multiple modes of operation such as chat, assistants, completions, and image-related tasks using ``DALL-E 3`` for generation and ``GPT-4 Vision`` for analysis. **PYGPT** has filesystem capabilities for file I/O, can generate and run Python code, execute system commands, and manage file transfers. It also allows models to perform web searches with the ``Google Custom Search API``.
1010

@@ -30,6 +30,7 @@ Features
3030
* Image analysis via ``GPT-4 Vision``.
3131
* Integrated ``Langchain`` support (you can connect to any LLM, e.g., on ``HuggingFace``).
3232
* Commands execution (via plugins: access to the local filesystem, Python code interpreter, system commands execution).
33+
* Custom commands creation and execution
3334
* Manages files and attachments with options to upload, download, and organize.
3435
* Context history with the capability to revert to previous contexts (long-term memory).
3536
* Allows you to easily manage prompts with handy editable presets.

docs/source/plugins.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The following plugins are currently available, and GPT can use them instantly:
88
* ``Command: Google Web Search`` - allows searching the internet via the `Google Custom Search Engine`.
99
* ``Command: Files I/O`` - grants access to the local filesystem, enabling GPT to read and write files, as well as list and create directories.
1010
* ``Command: Code Interpreter`` - responsible for generating and executing Python code, functioning much like the `Code Interpreter` on `ChatGPT`, but locally. This means GPT can interface with any script, application, or code. The plugin can also execute system commands, allowing GPT to integrate with your operating system. Plugins can work in conjunction to perform sequential tasks; for example, the `Files` plugin can write generated Python code to a file, which the `Code Interpreter` can execute it and return its result to GPT.
11+
* ``Command: Custom Commands`` - allows you to create and execute custom commands on your system.
1112
* ``Audio Output (Microsoft Azure)`` - provides voice synthesis using the Microsoft Azure Text To Speech API.
1213
* ``Audio Output (OpenAI TTS)`` - provides voice synthesis using the `OpenAI Text To Speech API`.
1314
* ``Audio Input (OpenAI Whisper)`` - offers speech recognition through the `OpenAI Whisper API`.

docs/source/plugins_list.rst

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ The plugin allows for file management within the local filesystem. It enables th
99
Plugin capabilities include:
1010

1111
* Reading files
12+
* Appending to files
1213
* Writing files
13-
* Executing code from files
14-
* Creating directories
14+
* Deleting files
1515
* Listing files and directories
16+
* Creating directories
1617

1718
If a file being created (with the same name) already exists, a prefix including the date and time is added to the file name.
1819

@@ -62,7 +63,7 @@ Another feature is the ability to execute system commands and return their resul
6263

6364
- ``Python command template`` *python_cmd_tpl*
6465

65-
Python command template (use {filename} as path to file placeholder). *Default:* `python3 {filename}`
66+
Python command template (use {filename} as path to file placeholder). *Default:* ``python3 {filename}``
6667

6768
- ``Enable: Python Code Generate and Execute`` *cmd_code_execute*
6869

@@ -77,6 +78,76 @@ Allow Python code execution from existing file. *Default:* `True`
7778
Allow system commands execution. *Default:* `True`
7879

7980

81+
Command: Custom Commands
82+
------------------------
83+
84+
With the ``Custom Commands`` plugin, you can integrate **PYGPT** with your operating system and scripts or applications. You can define an unlimited number of custom commands and instruct GPT on when and how to execute them. Configuration is straightforward, and **PYGPT** includes a simple tutorial command for testing and learning how it works:
85+
86+
.. image:: images/v2_custom_cmd.png
87+
:width: 800
88+
89+
To add a new custom command, click the **ADD** button and then:
90+
91+
1. Provide a name for your command: this is a unique identifier for GPT.
92+
2. Provide an ``instruction`` explaining what this command does; GPT will know when to use the command based on this instruction.
93+
3. Define ``params``, separated by commas - GPT will send data to your commands using these params. These params will be placed into placeholders you have defined in the ``cmd`` field. For example:
94+
95+
If you want instruct GPT to execute your Python script named ``smart_home_lights.py`` with an argument, such as ``1`` to turn the light ON, and ``0`` to turn it OFF, define it as follows:
96+
97+
- **name**: lights_cmd
98+
- **instruction**: turn lights on/off; use 1 as 'arg' to turn ON, or 0 as 'arg' to turn OFF
99+
- **params**: arg
100+
- **cmd**: ``python /path/to/smart_home_lights.py {arg}``
101+
102+
The setup defined above will work as follows:
103+
104+
When you ask GPT to turn your lights ON, GPT will locate this command and prepare the command ``python /path/to/smart_home_lights.py {arg}`` with ``{arg}`` replaced with ``1``. On your system, it will execute the command:
105+
106+
.. code-block:: console
107+
108+
python /path/to/smart_home_lights.py 1
109+
110+
And that's all. GPT will take care of the rest when you ask to turn ON the lights.
111+
112+
You can define as many placeholders and parameters as you desire.
113+
114+
Here are some predefined system placeholders for use:
115+
116+
- ``{_time}`` - current time in ``Y-m-d`` format
117+
- ``{_date}`` - current date in ``H:M:S`` format
118+
- ``{_datetime}`` - current date and time in ``Y-m-d H:M:S`` format
119+
- ``{_file}`` - path to the file from which the command is invoked
120+
- ``{_home}`` - path to PYGPT's home/working directory
121+
122+
You can connect predefined placeholders with your own params.
123+
124+
*Example:*
125+
126+
- **name**: song_cmd
127+
- **instruction**: store the generated song on hard disk
128+
- **params**: song_text, title
129+
- **cmd**: ``echo "{song_text}" > {_home}/{title}.txt``
130+
131+
132+
With the setup above, every time you ask GPT to generate a song for you and save it to the disk, it will:
133+
134+
1. Generate a song.
135+
2. Locate your command.
136+
3. Execute the command by sending the song's title and text.
137+
4. The command will save the song text into a file named with the song's title in the PYGPT working directory.
138+
139+
**Example tutorial command**
140+
141+
**PYGPT** provides simple tutorial command to show how it work, to run it just ask GPT for execute ``tutorial test command`` and it will show you how it works:
142+
143+
.. code-block:: console
144+
145+
> please execute tutorial test command
146+
147+
.. image:: images/v2_code_execute_example.png
148+
:width: 800
149+
150+
80151
Command: Google Web Search
81152
--------------------------
82153

src/pygpt_net/core/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from .plugin.cmd_web_google.plugin import Plugin as CmdWebGooglePlugin
3838
from .plugin.cmd_files.plugin import Plugin as CmdFilesPlugin
3939
from .plugin.cmd_code_interpreter.plugin import Plugin as CmdCodeInterpreterPlugin
40+
from .plugin.cmd_custom.plugin import Plugin as CmdCustomCommandPlugin
4041

4142
from .llm.OpenAI import OpenAILLM
4243
from .llm.AzureOpenAI import AzureOpenAILLM
@@ -254,6 +255,7 @@ def run():
254255
launcher.add_plugin(CmdWebGooglePlugin())
255256
launcher.add_plugin(CmdFilesPlugin())
256257
launcher.add_plugin(CmdCodeInterpreterPlugin())
258+
launcher.add_plugin(CmdCustomCommandPlugin())
257259

258260
# register langchain LLMs
259261
launcher.add_llm(OpenAILLM())

src/pygpt_net/core/plugin/cmd_custom/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)