pygpt-net 2.4.41__py3-none-any.whl → 2.4.42__py3-none-any.whl
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.
- CHANGELOG.md +8 -0
- README.md +135 -70
- pygpt_net/CHANGELOG.txt +8 -0
- pygpt_net/__init__.py +3 -3
- pygpt_net/app.py +3 -1
- pygpt_net/controller/audio/__init__.py +2 -2
- pygpt_net/controller/camera.py +1 -10
- pygpt_net/controller/chat/audio.py +2 -2
- pygpt_net/controller/config/placeholder.py +15 -1
- pygpt_net/controller/ui/mode.py +16 -21
- pygpt_net/core/audio/__init__.py +4 -1
- pygpt_net/core/audio/whisper.py +37 -0
- pygpt_net/core/bridge/worker.py +2 -2
- pygpt_net/core/debug/events.py +22 -10
- pygpt_net/core/debug/tabs.py +6 -3
- pygpt_net/core/history.py +3 -2
- pygpt_net/core/idx/__init__.py +16 -4
- pygpt_net/core/idx/chat.py +15 -5
- pygpt_net/core/idx/indexing.py +24 -8
- pygpt_net/core/installer.py +2 -4
- pygpt_net/core/models.py +62 -17
- pygpt_net/core/modes.py +11 -13
- pygpt_net/core/notepad.py +4 -4
- pygpt_net/core/plugins.py +27 -16
- pygpt_net/core/presets.py +20 -9
- pygpt_net/core/profile.py +11 -3
- pygpt_net/core/render/web/parser.py +3 -1
- pygpt_net/core/settings.py +5 -5
- pygpt_net/core/tabs/tab.py +10 -2
- pygpt_net/core/tokens.py +8 -6
- pygpt_net/core/web/__init__.py +105 -0
- pygpt_net/core/{web.py → web/helpers.py} +93 -67
- pygpt_net/data/config/config.json +3 -3
- pygpt_net/data/config/models.json +3 -3
- pygpt_net/data/config/modes.json +3 -3
- pygpt_net/data/locale/locale.en.ini +1 -0
- pygpt_net/data/locale/plugin.cmd_web.en.ini +2 -0
- pygpt_net/data/locale/plugin.mailer.en.ini +21 -0
- pygpt_net/item/ctx.py +13 -2
- pygpt_net/plugin/agent/__init__.py +7 -2
- pygpt_net/plugin/audio_output/__init__.py +6 -1
- pygpt_net/plugin/base/plugin.py +58 -26
- pygpt_net/plugin/base/worker.py +20 -17
- pygpt_net/plugin/cmd_history/config.py +2 -2
- pygpt_net/plugin/cmd_web/__init__.py +3 -4
- pygpt_net/plugin/cmd_web/config.py +71 -3
- pygpt_net/plugin/cmd_web/websearch.py +20 -12
- pygpt_net/plugin/cmd_web/worker.py +67 -4
- pygpt_net/plugin/idx_llama_index/config.py +3 -3
- pygpt_net/plugin/mailer/__init__.py +123 -0
- pygpt_net/plugin/mailer/config.py +149 -0
- pygpt_net/plugin/mailer/runner.py +285 -0
- pygpt_net/plugin/mailer/worker.py +123 -0
- pygpt_net/provider/agents/base.py +5 -2
- pygpt_net/provider/agents/openai.py +4 -2
- pygpt_net/provider/agents/openai_assistant.py +4 -2
- pygpt_net/provider/agents/planner.py +4 -2
- pygpt_net/provider/agents/react.py +4 -2
- pygpt_net/provider/audio_output/openai_tts.py +5 -11
- pygpt_net/provider/core/assistant/base.py +5 -3
- pygpt_net/provider/core/assistant/json_file.py +8 -5
- pygpt_net/provider/core/assistant_file/base.py +4 -3
- pygpt_net/provider/core/assistant_file/db_sqlite/__init__.py +4 -3
- pygpt_net/provider/core/assistant_file/db_sqlite/storage.py +3 -2
- pygpt_net/provider/core/assistant_store/base.py +6 -4
- pygpt_net/provider/core/assistant_store/db_sqlite/__init__.py +5 -4
- pygpt_net/provider/core/assistant_store/db_sqlite/storage.py +5 -3
- pygpt_net/provider/core/attachment/base.py +5 -3
- pygpt_net/provider/core/attachment/json_file.py +4 -3
- pygpt_net/provider/core/calendar/base.py +5 -3
- pygpt_net/provider/core/calendar/db_sqlite/__init__.py +6 -5
- pygpt_net/provider/core/calendar/db_sqlite/storage.py +5 -4
- pygpt_net/provider/core/config/base.py +8 -6
- pygpt_net/provider/core/config/json_file.py +9 -7
- pygpt_net/provider/core/ctx/base.py +27 -25
- pygpt_net/provider/core/ctx/db_sqlite/__init__.py +51 -35
- pygpt_net/provider/core/ctx/db_sqlite/storage.py +42 -31
- pygpt_net/provider/core/ctx/db_sqlite/utils.py +11 -9
- pygpt_net/provider/core/index/base.py +129 -23
- pygpt_net/provider/core/index/db_sqlite/__init__.py +130 -23
- pygpt_net/provider/core/index/db_sqlite/storage.py +130 -23
- pygpt_net/provider/core/index/db_sqlite/utils.py +4 -2
- pygpt_net/provider/core/mode/base.py +5 -3
- pygpt_net/provider/core/mode/json_file.py +7 -6
- pygpt_net/provider/core/model/base.py +6 -4
- pygpt_net/provider/core/model/json_file.py +9 -7
- pygpt_net/provider/core/notepad/base.py +5 -3
- pygpt_net/provider/core/notepad/db_sqlite/__init__.py +5 -4
- pygpt_net/provider/core/notepad/db_sqlite/storage.py +4 -3
- pygpt_net/provider/core/plugin_preset/base.py +4 -2
- pygpt_net/provider/core/plugin_preset/json_file.py +5 -3
- pygpt_net/provider/core/preset/base.py +6 -4
- pygpt_net/provider/core/preset/json_file.py +9 -9
- pygpt_net/provider/core/prompt/base.py +6 -3
- pygpt_net/provider/core/prompt/json_file.py +11 -6
- pygpt_net/provider/gpt/assistants.py +15 -6
- pygpt_net/provider/gpt/audio.py +5 -5
- pygpt_net/provider/gpt/chat.py +7 -5
- pygpt_net/provider/gpt/completion.py +8 -4
- pygpt_net/provider/gpt/image.py +3 -3
- pygpt_net/provider/gpt/store.py +46 -12
- pygpt_net/provider/gpt/vision.py +16 -11
- pygpt_net/provider/llms/anthropic.py +7 -2
- pygpt_net/provider/llms/azure_openai.py +26 -5
- pygpt_net/provider/llms/base.py +47 -9
- pygpt_net/provider/llms/google.py +7 -2
- pygpt_net/provider/llms/hugging_face.py +13 -3
- pygpt_net/provider/llms/hugging_face_api.py +18 -4
- pygpt_net/provider/llms/local.py +7 -2
- pygpt_net/provider/llms/ollama.py +30 -6
- pygpt_net/provider/llms/openai.py +32 -6
- pygpt_net/provider/vector_stores/__init__.py +45 -14
- pygpt_net/provider/vector_stores/base.py +35 -8
- pygpt_net/provider/vector_stores/chroma.py +13 -3
- pygpt_net/provider/vector_stores/ctx_attachment.py +31 -12
- pygpt_net/provider/vector_stores/elasticsearch.py +12 -3
- pygpt_net/provider/vector_stores/pinecode.py +12 -3
- pygpt_net/provider/vector_stores/redis.py +12 -3
- pygpt_net/provider/vector_stores/simple.py +12 -3
- pygpt_net/provider/vector_stores/temp.py +16 -4
- pygpt_net/provider/web/base.py +10 -3
- pygpt_net/provider/web/google_custom_search.py +9 -3
- pygpt_net/provider/web/microsoft_bing.py +9 -3
- pygpt_net/tools/__init__.py +13 -5
- pygpt_net/tools/audio_transcriber/__init__.py +4 -3
- pygpt_net/tools/base.py +15 -8
- pygpt_net/tools/code_interpreter/__init__.py +4 -3
- pygpt_net/tools/html_canvas/__init__.py +4 -3
- pygpt_net/tools/image_viewer/__init__.py +10 -4
- pygpt_net/tools/indexer/__init__.py +8 -7
- pygpt_net/tools/media_player/__init__.py +4 -3
- pygpt_net/tools/text_editor/__init__.py +36 -10
- pygpt_net/ui/layout/chat/output.py +2 -2
- pygpt_net/ui/menu/audio.py +12 -1
- {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/METADATA +136 -71
- {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/RECORD +139 -132
- {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/LICENSE +0 -0
- {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/WHEEL +0 -0
- {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/entry_points.txt +0 -0
@@ -6,90 +6,116 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.12.
|
9
|
+
# Updated Date: 2024.12.15 01:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
import os
|
13
13
|
import uuid
|
14
|
-
from typing import Optional, List, Dict
|
14
|
+
from typing import Optional, List, Dict, Tuple, Union
|
15
15
|
|
16
16
|
import requests
|
17
17
|
|
18
18
|
from bs4 import BeautifulSoup
|
19
19
|
from urllib.parse import urljoin
|
20
20
|
|
21
|
-
from pygpt_net.provider.web.base import BaseProvider
|
22
21
|
|
23
|
-
|
24
|
-
class Web:
|
22
|
+
class Helpers:
|
25
23
|
def __init__(self, window=None):
|
26
24
|
"""
|
27
|
-
Web
|
25
|
+
Web helpers core
|
28
26
|
|
29
27
|
:param window: Window instance
|
30
28
|
"""
|
31
29
|
self.window = window
|
32
|
-
self.providers = {
|
33
|
-
"search_engine": {},
|
34
|
-
}
|
35
|
-
|
36
|
-
def is_registered(self, id: str, type: str = "search_engine") -> bool:
|
37
|
-
"""
|
38
|
-
Check if provider is registered
|
39
|
-
|
40
|
-
:param id: provider id
|
41
|
-
:param type: provider type
|
42
|
-
:return: True if registered
|
43
|
-
"""
|
44
|
-
if type in self.providers:
|
45
|
-
return id in self.providers[type]
|
46
|
-
return False
|
47
|
-
|
48
|
-
def get_providers(self, type: str = "search_engine") -> dict:
|
49
|
-
"""
|
50
|
-
Get all providers
|
51
|
-
|
52
|
-
:param type: provider type
|
53
|
-
:return: providers dict
|
54
|
-
"""
|
55
|
-
if type in self.providers:
|
56
|
-
return self.providers[type]
|
57
|
-
return {}
|
58
|
-
|
59
|
-
def get_ids(self, type: str = "search_engine") -> list:
|
60
|
-
"""
|
61
|
-
Get all providers ids
|
62
30
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
:param
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
31
|
+
def request(
|
32
|
+
self,
|
33
|
+
url: str = "",
|
34
|
+
method: str = "GET",
|
35
|
+
headers: Optional[dict] = None,
|
36
|
+
params: Optional[dict] = None,
|
37
|
+
data: Optional[Union[str, dict]] = None,
|
38
|
+
json: Optional[dict] = None,
|
39
|
+
files: Optional[dict] = None,
|
40
|
+
cookies: Optional[dict] = None,
|
41
|
+
timeout: int = 10,
|
42
|
+
disable_ssl_verify: bool = False,
|
43
|
+
allow_redirects: bool = True,
|
44
|
+
stream: bool = False,
|
45
|
+
user_agent: Optional[str] = None,
|
46
|
+
) -> Tuple[Optional[int], Optional[str]]:
|
47
|
+
"""
|
48
|
+
Make HTTP request
|
49
|
+
|
50
|
+
:param url: URL
|
51
|
+
:param method: HTTP method
|
52
|
+
:param headers: Headers
|
53
|
+
:param params: GET parameters
|
54
|
+
:param data: POST data
|
55
|
+
:param json: JSON data
|
56
|
+
:param files: Files
|
57
|
+
:param cookies: Cookies
|
58
|
+
:param timeout: Timeout
|
59
|
+
:param disable_ssl_verify: Disable SSL verification
|
60
|
+
:param allow_redirects: Allow redirects
|
61
|
+
:param stream: Stream
|
62
|
+
:param user_agent: User agent
|
63
|
+
:return: status code, response text
|
64
|
+
"""
|
65
|
+
upload = {}
|
66
|
+
try:
|
67
|
+
method = method.upper()
|
68
|
+
session = requests.Session()
|
69
|
+
args = {}
|
70
|
+
|
71
|
+
if data:
|
72
|
+
args['data'] = data
|
73
|
+
if json:
|
74
|
+
args['json'] = json
|
75
|
+
if cookies:
|
76
|
+
args['cookies'] = cookies
|
77
|
+
if params:
|
78
|
+
args['params'] = params
|
79
|
+
if headers:
|
80
|
+
args['headers'] = headers
|
81
|
+
|
82
|
+
args['timeout'] = timeout
|
83
|
+
if disable_ssl_verify:
|
84
|
+
args['verify'] = False
|
85
|
+
if not allow_redirects:
|
86
|
+
args['allow_redirects'] = False
|
87
|
+
if stream:
|
88
|
+
args['stream'] = True
|
89
|
+
if user_agent:
|
90
|
+
if 'headers' not in args:
|
91
|
+
args['headers'] = {}
|
92
|
+
args['headers']['User-Agent'] = user_agent
|
93
|
+
|
94
|
+
if files:
|
95
|
+
for key, value in files.items():
|
96
|
+
if os.path.exists(value) and os.path.isfile(value):
|
97
|
+
upload[key] = open(value, 'rb')
|
98
|
+
args['files'] = upload
|
99
|
+
|
100
|
+
if method == 'GET':
|
101
|
+
response = session.get(url, **args)
|
102
|
+
elif method == 'POST':
|
103
|
+
response = session.post(url, **args)
|
104
|
+
elif method == 'PUT':
|
105
|
+
response = session.put(url, **args)
|
106
|
+
elif method == 'DELETE':
|
107
|
+
response = session.delete(url, **args)
|
108
|
+
elif method == 'PATCH':
|
109
|
+
response = session.patch(url, **args)
|
110
|
+
else:
|
111
|
+
return None, f'Invalid HTTP method: {method}'
|
112
|
+
for k in upload:
|
113
|
+
upload[k].close() # close files if opened
|
114
|
+
return response.status_code, response.text
|
115
|
+
except Exception as e:
|
116
|
+
for k in upload:
|
117
|
+
upload[k].close() # close files if opened
|
118
|
+
return None, f'Error: {e}'
|
93
119
|
|
94
120
|
def get_main_image(self, url: str) -> Optional[str]:
|
95
121
|
"""
|
@@ -208,4 +234,4 @@ class Web:
|
|
208
234
|
download_path = os.path.join(dir, name)
|
209
235
|
with open(download_path, 'wb', ) as f:
|
210
236
|
f.write(response.content)
|
211
|
-
return self.window.core.filesystem.make_local(download_path)
|
237
|
+
return self.window.core.filesystem.make_local(download_path)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"__meta__": {
|
3
|
-
"version": "2.4.
|
4
|
-
"app.version": "2.4.
|
5
|
-
"updated_at": "2024-12-
|
3
|
+
"version": "2.4.42",
|
4
|
+
"app.version": "2.4.42",
|
5
|
+
"updated_at": "2024-12-15T00:00:00"
|
6
6
|
},
|
7
7
|
"access.audio.event.speech": false,
|
8
8
|
"access.audio.event.speech.disabled": [],
|
pygpt_net/data/config/modes.json
CHANGED
@@ -683,6 +683,7 @@ menu.audio.control.global = Voice control (global)
|
|
683
683
|
menu.audio.control.plugin = Voice control (inline)
|
684
684
|
menu.audio.input = Input: Speech recognition
|
685
685
|
menu.audio.output = Output: Speech synthesis
|
686
|
+
menu.audio.stop = Stop audio playback
|
686
687
|
menu.config = Config
|
687
688
|
menu.config.access = Accessibility
|
688
689
|
menu.config.change_dir = Change working directory...
|
@@ -17,6 +17,8 @@ cmd.web_index_query.description = Enable `web_index_query` command execution.\nI
|
|
17
17
|
cmd.web_index_query.label = Enable: quick query the Web and external content
|
18
18
|
cmd.web_index_query.tooltip = Example prompt: Query the Website http://example.com about (question).
|
19
19
|
cmd.web_index.tooltip = Example prompt: Index the Website http://example.com.
|
20
|
+
cmd.web_request.description = Enable `web_request` command execution.\nIf enabled, model will be able to send any HTTP request to specified URL or API endpoint.
|
21
|
+
cmd.web_request.label = Enable: sending any HTTP requests
|
20
22
|
cmd.web_search.description = Enable `web_search` command execution.\nIf enabled, the model will be able to search the Web.
|
21
23
|
cmd.web_search.label = Enable: search the Web
|
22
24
|
cmd.web_search.tooltip = Example prompt: Search the Web for (question).
|
@@ -0,0 +1,21 @@
|
|
1
|
+
[LOCALE]
|
2
|
+
cmd.send_mail.label = Enable: send email
|
3
|
+
cmd.send_mail.description = Allows for sending emails.
|
4
|
+
cmd.receive_emails.label = Enable: receive emails
|
5
|
+
cmd.receive_emails.description = Allows for receiving emails.
|
6
|
+
cmd.get_email_body.label = Enable: get email body
|
7
|
+
cmd.get_email_body.description = Allows for receive email body.
|
8
|
+
plugin.description = Provides the ability to send, receive and read emails.
|
9
|
+
plugin.name = Mailer
|
10
|
+
smtp_host.description = SMTP Host, e.g. smtp.domain.com
|
11
|
+
smtp_host.label = Host
|
12
|
+
smtp_port_inbox.description = SMTP Port (Inbox), default: 995
|
13
|
+
smtp_port_inbox.label = Port (Inbox)
|
14
|
+
smtp_port_outbox.description = SMTP Port (Outbox), default: 465
|
15
|
+
smtp_port_outbox.label = Port (Outbox)
|
16
|
+
smtp_user.description = SMTP User, e.g. user@domain.com
|
17
|
+
smtp_user.label = User
|
18
|
+
smtp_password.description = SMTP Password
|
19
|
+
smtp_password.label = Password
|
20
|
+
from_email.description = From (email), e.g. me@domain.com
|
21
|
+
from_email.label = From (email)
|
pygpt_net/item/ctx.py
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.12.
|
9
|
+
# Updated Date: 2024.12.14 18:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
import copy
|
@@ -20,7 +20,7 @@ class CtxItem:
|
|
20
20
|
"""
|
21
21
|
Context item
|
22
22
|
|
23
|
-
:param mode: Mode (completion, chat, img, vision, langchain, assistant, llama_index, agent)
|
23
|
+
:param mode: Mode (completion, chat, img, vision, langchain, assistant, llama_index, agent, expert)
|
24
24
|
"""
|
25
25
|
self.id = None
|
26
26
|
self.meta = None # CtxMeta object
|
@@ -137,6 +137,17 @@ class CtxItem:
|
|
137
137
|
"""
|
138
138
|
return len(self.cmds) > 0 or len(self.tool_calls) > 0
|
139
139
|
|
140
|
+
def audio_read_allowed(self) -> bool:
|
141
|
+
"""
|
142
|
+
Check if audio read allowed
|
143
|
+
|
144
|
+
:return: True if audio read allowed
|
145
|
+
"""
|
146
|
+
allowed = True
|
147
|
+
if self.has_commands() or '~###~{"cmd":' in self.output:
|
148
|
+
allowed = False
|
149
|
+
return allowed
|
150
|
+
|
140
151
|
def add_doc_meta(self, meta: dict):
|
141
152
|
"""
|
142
153
|
Add document meta
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.
|
9
|
+
# Updated Date: 2024.12.14 22:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
from pygpt_net.plugin.base.plugin import BasePlugin
|
@@ -57,7 +57,12 @@ class Plugin(BasePlugin):
|
|
57
57
|
data = event.data
|
58
58
|
ctx = event.ctx
|
59
59
|
|
60
|
-
always_events = [
|
60
|
+
always_events = [
|
61
|
+
Event.FORCE_STOP,
|
62
|
+
Event.PLUGIN_SETTINGS_CHANGED,
|
63
|
+
Event.ENABLE,
|
64
|
+
Event.DISABLE
|
65
|
+
]
|
61
66
|
|
62
67
|
if not self.is_allowed() and name != Event.DISABLE:
|
63
68
|
return
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.12.
|
9
|
+
# Updated Date: 2024.12.14 18:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
from PySide6.QtCore import Slot
|
@@ -167,6 +167,11 @@ class Plugin(BasePlugin):
|
|
167
167
|
cache_file = None
|
168
168
|
if event.data is not None and isinstance(event.data, dict) and "cache_file" in event.data:
|
169
169
|
cache_file = event.data["cache_file"]
|
170
|
+
|
171
|
+
# check for audio read allowed. Prevents reading audio in commands, results, etc.
|
172
|
+
if name == Event.CTX_AFTER:
|
173
|
+
if not ctx.audio_read_allowed():
|
174
|
+
return # abort if audio read is not allowed (commands, results, etc.)
|
170
175
|
|
171
176
|
try:
|
172
177
|
if text is not None and len(text) > 0:
|
pygpt_net/plugin/base/plugin.py
CHANGED
@@ -6,17 +6,14 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.12.14
|
9
|
+
# Updated Date: 2024.12.14 22:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
import copy
|
13
|
-
from typing import Optional
|
13
|
+
from typing import Optional, Any, Dict, List
|
14
14
|
|
15
15
|
from PySide6.QtCore import QObject, Slot
|
16
16
|
|
17
|
-
from pygpt_net.core.types import (
|
18
|
-
MODE_AGENT_LLAMA,
|
19
|
-
)
|
20
17
|
from pygpt_net.core.bridge.context import BridgeContext
|
21
18
|
from pygpt_net.core.events import Event, KernelEvent
|
22
19
|
from pygpt_net.item.ctx import CtxItem
|
@@ -43,7 +40,7 @@ class BasePlugin(QObject):
|
|
43
40
|
self.use_locale = False
|
44
41
|
self.order = 0
|
45
42
|
|
46
|
-
def setup(self) ->
|
43
|
+
def setup(self) -> Dict[str, Any]:
|
47
44
|
"""
|
48
45
|
Return available config options
|
49
46
|
|
@@ -51,7 +48,12 @@ class BasePlugin(QObject):
|
|
51
48
|
"""
|
52
49
|
return self.options
|
53
50
|
|
54
|
-
def add_option(
|
51
|
+
def add_option(
|
52
|
+
self,
|
53
|
+
name: str,
|
54
|
+
type: str,
|
55
|
+
**kwargs
|
56
|
+
) -> Dict[str, Any]:
|
55
57
|
"""
|
56
58
|
Add plugin configuration option
|
57
59
|
|
@@ -84,7 +86,11 @@ class BasePlugin(QObject):
|
|
84
86
|
self.options[name] = option
|
85
87
|
return option
|
86
88
|
|
87
|
-
def add_cmd(
|
89
|
+
def add_cmd(
|
90
|
+
self,
|
91
|
+
cmd: str,
|
92
|
+
**kwargs
|
93
|
+
) -> Dict[str, Any]:
|
88
94
|
"""
|
89
95
|
Add plugin command
|
90
96
|
|
@@ -125,7 +131,10 @@ class BasePlugin(QObject):
|
|
125
131
|
|
126
132
|
return self.add_option(name, "cmd", **kwargs)
|
127
133
|
|
128
|
-
def has_cmd(
|
134
|
+
def has_cmd(
|
135
|
+
self,
|
136
|
+
cmd: str
|
137
|
+
) -> bool:
|
129
138
|
"""
|
130
139
|
Check if command exists
|
131
140
|
|
@@ -138,7 +147,10 @@ class BasePlugin(QObject):
|
|
138
147
|
return self.options[key]["value"]["enabled"]
|
139
148
|
return False
|
140
149
|
|
141
|
-
def cmd_allowed(
|
150
|
+
def cmd_allowed(
|
151
|
+
self,
|
152
|
+
cmd: str
|
153
|
+
) -> bool:
|
142
154
|
"""
|
143
155
|
Check if command allowed
|
144
156
|
|
@@ -157,7 +169,10 @@ class BasePlugin(QObject):
|
|
157
169
|
"""
|
158
170
|
return self.window.core.config.get("cmd")
|
159
171
|
|
160
|
-
def get_cmd(
|
172
|
+
def get_cmd(
|
173
|
+
self,
|
174
|
+
cmd: str
|
175
|
+
) -> Dict[str, Any]:
|
161
176
|
"""
|
162
177
|
Return command
|
163
178
|
|
@@ -170,7 +185,10 @@ class BasePlugin(QObject):
|
|
170
185
|
data = {"cmd": cmd, **data}
|
171
186
|
return data
|
172
187
|
|
173
|
-
def has_option(
|
188
|
+
def has_option(
|
189
|
+
self,
|
190
|
+
name: str
|
191
|
+
) -> bool:
|
174
192
|
"""
|
175
193
|
Check if option exists
|
176
194
|
|
@@ -179,7 +197,10 @@ class BasePlugin(QObject):
|
|
179
197
|
"""
|
180
198
|
return name in self.options
|
181
199
|
|
182
|
-
def get_option(
|
200
|
+
def get_option(
|
201
|
+
self,
|
202
|
+
name: str
|
203
|
+
) -> Dict[str, Any]:
|
183
204
|
"""
|
184
205
|
Return option
|
185
206
|
|
@@ -189,7 +210,10 @@ class BasePlugin(QObject):
|
|
189
210
|
if self.has_option(name):
|
190
211
|
return self.options[name]
|
191
212
|
|
192
|
-
def get_option_value(
|
213
|
+
def get_option_value(
|
214
|
+
self,
|
215
|
+
name: str
|
216
|
+
) -> Any:
|
193
217
|
"""
|
194
218
|
Return option value
|
195
219
|
|
@@ -207,7 +231,12 @@ class BasePlugin(QObject):
|
|
207
231
|
"""
|
208
232
|
self.window = window
|
209
233
|
|
210
|
-
def handle(
|
234
|
+
def handle(
|
235
|
+
self,
|
236
|
+
event: Event,
|
237
|
+
*args,
|
238
|
+
**kwargs
|
239
|
+
):
|
211
240
|
"""
|
212
241
|
Handle event
|
213
242
|
|
@@ -235,7 +264,10 @@ class BasePlugin(QObject):
|
|
235
264
|
"""
|
236
265
|
return
|
237
266
|
|
238
|
-
def trans(
|
267
|
+
def trans(
|
268
|
+
self,
|
269
|
+
text: Optional[str] = None
|
270
|
+
) -> str:
|
239
271
|
"""
|
240
272
|
Translate text using plugin domain
|
241
273
|
|
@@ -247,7 +279,7 @@ class BasePlugin(QObject):
|
|
247
279
|
domain = 'plugin.{}'.format(self.id)
|
248
280
|
return trans(text, False, domain)
|
249
281
|
|
250
|
-
def error(self, err:
|
282
|
+
def error(self, err: Any):
|
251
283
|
"""
|
252
284
|
Send error message to logger and alert dialog
|
253
285
|
|
@@ -257,7 +289,7 @@ class BasePlugin(QObject):
|
|
257
289
|
msg = self.window.core.debug.parse_alert(err)
|
258
290
|
self.window.ui.dialogs.alert("{}: {}".format(self.name, msg))
|
259
291
|
|
260
|
-
def debug(self, data:
|
292
|
+
def debug(self, data: Any):
|
261
293
|
"""
|
262
294
|
Send debug message to logger window
|
263
295
|
|
@@ -337,9 +369,9 @@ class BasePlugin(QObject):
|
|
337
369
|
@Slot(object, object, dict)
|
338
370
|
def handle_finished(
|
339
371
|
self,
|
340
|
-
response:
|
372
|
+
response: Dict[str, Any],
|
341
373
|
ctx: Optional[CtxItem] = None,
|
342
|
-
extra_data: Optional[
|
374
|
+
extra_data: Optional[Dict[str, Any]] = None
|
343
375
|
):
|
344
376
|
"""
|
345
377
|
Handle finished response signal
|
@@ -367,9 +399,9 @@ class BasePlugin(QObject):
|
|
367
399
|
@Slot(object, object, dict)
|
368
400
|
def handle_finished_more(
|
369
401
|
self,
|
370
|
-
responses:
|
402
|
+
responses: List[Dict[str, Any]],
|
371
403
|
ctx: Optional[CtxItem] = None,
|
372
|
-
extra_data: Optional[
|
404
|
+
extra_data: Optional[Dict[str, Any]] = None
|
373
405
|
):
|
374
406
|
"""
|
375
407
|
Handle finished response signal
|
@@ -397,9 +429,9 @@ class BasePlugin(QObject):
|
|
397
429
|
|
398
430
|
def prepare_reply_ctx(
|
399
431
|
self,
|
400
|
-
response:
|
432
|
+
response: Dict[str, Any],
|
401
433
|
ctx: Optional[CtxItem] = None
|
402
|
-
) ->
|
434
|
+
) -> Dict[str, Any]:
|
403
435
|
"""
|
404
436
|
Prepare reply context
|
405
437
|
|
@@ -454,7 +486,7 @@ class BasePlugin(QObject):
|
|
454
486
|
self.window.update_status(str(data))
|
455
487
|
|
456
488
|
@Slot(object)
|
457
|
-
def handle_error(self, err:
|
489
|
+
def handle_error(self, err: Any):
|
458
490
|
"""
|
459
491
|
Handle thread error signal
|
460
492
|
|
@@ -463,7 +495,7 @@ class BasePlugin(QObject):
|
|
463
495
|
self.error(err)
|
464
496
|
|
465
497
|
@Slot(object)
|
466
|
-
def handle_debug(self, msg:
|
498
|
+
def handle_debug(self, msg: Any):
|
467
499
|
"""
|
468
500
|
Handle debug message signal
|
469
501
|
|
pygpt_net/plugin/base/worker.py
CHANGED
@@ -6,10 +6,10 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.12.14
|
9
|
+
# Updated Date: 2024.12.14 22:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
|
-
from typing import Optional, Any
|
12
|
+
from typing import Optional, Any, Dict, List
|
13
13
|
|
14
14
|
from PySide6.QtCore import QObject, QRunnable
|
15
15
|
from typing_extensions import deprecated
|
@@ -44,7 +44,7 @@ class BaseWorker(QObject, QRunnable):
|
|
44
44
|
if self.signals is not None and hasattr(self.signals, "destroyed"):
|
45
45
|
self.signals.destroyed.emit()
|
46
46
|
|
47
|
-
def error(self, err:
|
47
|
+
def error(self, err: Any):
|
48
48
|
"""
|
49
49
|
Emit error signal
|
50
50
|
|
@@ -67,8 +67,8 @@ class BaseWorker(QObject, QRunnable):
|
|
67
67
|
@deprecated("From 2.1.29: BaseWorker.response() is deprecated, use BaseWorker.reply() instead")
|
68
68
|
def response(
|
69
69
|
self,
|
70
|
-
response:
|
71
|
-
extra_data: Optional[
|
70
|
+
response: Dict[str, Any],
|
71
|
+
extra_data: Optional[Dict[str, Any]] = None
|
72
72
|
):
|
73
73
|
"""
|
74
74
|
Emit finished signal (deprecated)
|
@@ -82,8 +82,8 @@ class BaseWorker(QObject, QRunnable):
|
|
82
82
|
|
83
83
|
def reply(
|
84
84
|
self,
|
85
|
-
response:
|
86
|
-
extra_data: Optional[
|
85
|
+
response: Dict[str, Any],
|
86
|
+
extra_data: Optional[Dict[str, Any]] = None
|
87
87
|
):
|
88
88
|
"""
|
89
89
|
Emit finished signal (on reply from command output)
|
@@ -101,8 +101,8 @@ class BaseWorker(QObject, QRunnable):
|
|
101
101
|
|
102
102
|
def reply_more(
|
103
103
|
self,
|
104
|
-
responses:
|
105
|
-
extra_data: Optional[
|
104
|
+
responses: List[Dict[str, Any]],
|
105
|
+
extra_data: Optional[Dict[str, Any]] = None
|
106
106
|
):
|
107
107
|
"""
|
108
108
|
Emit finished_more signal (on reply from command output, multiple responses)
|
@@ -166,7 +166,10 @@ class BaseWorker(QObject, QRunnable):
|
|
166
166
|
self.signals.status.connect(parent.handle_status)
|
167
167
|
self.signals.error.connect(parent.handle_error)
|
168
168
|
|
169
|
-
def from_request(
|
169
|
+
def from_request(
|
170
|
+
self,
|
171
|
+
item: Dict[str, Any]
|
172
|
+
) -> Dict[str, Any]:
|
170
173
|
"""
|
171
174
|
Prepare request item for result
|
172
175
|
|
@@ -177,10 +180,10 @@ class BaseWorker(QObject, QRunnable):
|
|
177
180
|
|
178
181
|
def make_response(
|
179
182
|
self,
|
180
|
-
item:
|
181
|
-
result:
|
182
|
-
extra: Optional[
|
183
|
-
) ->
|
183
|
+
item: Dict[str, Any],
|
184
|
+
result: Any,
|
185
|
+
extra: Optional[Dict[str, Any]] = None
|
186
|
+
) -> Dict[str, Any]:
|
184
187
|
"""
|
185
188
|
Prepare response item
|
186
189
|
|
@@ -211,7 +214,7 @@ class BaseWorker(QObject, QRunnable):
|
|
211
214
|
|
212
215
|
def has_param(
|
213
216
|
self,
|
214
|
-
item:
|
217
|
+
item: Dict[str, Any],
|
215
218
|
param: str
|
216
219
|
) -> bool:
|
217
220
|
"""
|
@@ -227,10 +230,10 @@ class BaseWorker(QObject, QRunnable):
|
|
227
230
|
|
228
231
|
def get_param(
|
229
232
|
self,
|
230
|
-
item:
|
233
|
+
item: Dict[str, Any],
|
231
234
|
param: str,
|
232
235
|
default: Any = None
|
233
|
-
) ->
|
236
|
+
) -> Any:
|
234
237
|
"""
|
235
238
|
Get parameter value from item
|
236
239
|
|