pygpt-net 2.4.37__py3-none-any.whl → 2.4.41__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.
Files changed (255) hide show
  1. CHANGELOG.md +29 -0
  2. README.md +44 -115
  3. pygpt_net/CHANGELOG.txt +29 -0
  4. pygpt_net/__init__.py +3 -3
  5. pygpt_net/controller/__init__.py +7 -3
  6. pygpt_net/controller/access/control.py +1 -1
  7. pygpt_net/controller/access/voice.py +11 -5
  8. pygpt_net/controller/agent/experts.py +11 -6
  9. pygpt_net/controller/agent/legacy.py +8 -6
  10. pygpt_net/controller/agent/llama.py +4 -2
  11. pygpt_net/controller/assistant/__init__.py +9 -4
  12. pygpt_net/controller/assistant/batch.py +38 -21
  13. pygpt_net/controller/assistant/editor.py +7 -6
  14. pygpt_net/controller/assistant/files.py +23 -7
  15. pygpt_net/controller/assistant/store.py +20 -7
  16. pygpt_net/controller/assistant/threads.py +34 -8
  17. pygpt_net/controller/attachment.py +29 -10
  18. pygpt_net/controller/audio/__init__.py +25 -4
  19. pygpt_net/controller/calendar/__init__.py +23 -4
  20. pygpt_net/controller/calendar/note.py +57 -11
  21. pygpt_net/controller/camera.py +3 -2
  22. pygpt_net/controller/chat/__init__.py +5 -3
  23. pygpt_net/controller/chat/attachment.py +34 -7
  24. pygpt_net/controller/chat/command.py +4 -2
  25. pygpt_net/controller/chat/common.py +11 -4
  26. pygpt_net/controller/chat/files.py +10 -3
  27. pygpt_net/controller/chat/image.py +17 -5
  28. pygpt_net/controller/chat/input.py +10 -7
  29. pygpt_net/controller/chat/output.py +21 -6
  30. pygpt_net/controller/chat/render.py +100 -21
  31. pygpt_net/controller/chat/response.py +34 -7
  32. pygpt_net/controller/chat/stream.py +4 -2
  33. pygpt_net/controller/chat/text.py +6 -4
  34. pygpt_net/controller/command.py +11 -3
  35. pygpt_net/controller/config/__init__.py +34 -6
  36. pygpt_net/controller/config/field/checkbox.py +7 -4
  37. pygpt_net/controller/config/field/cmd.py +7 -5
  38. pygpt_net/controller/config/field/combo.py +14 -6
  39. pygpt_net/controller/config/field/dictionary.py +14 -11
  40. pygpt_net/controller/config/field/input.py +9 -6
  41. pygpt_net/controller/config/field/slider.py +11 -8
  42. pygpt_net/controller/config/field/textarea.py +8 -5
  43. pygpt_net/controller/config/placeholder.py +52 -21
  44. pygpt_net/controller/ctx/__init__.py +138 -49
  45. pygpt_net/controller/ctx/common.py +15 -4
  46. pygpt_net/controller/ctx/extra.py +11 -3
  47. pygpt_net/controller/ctx/summarizer.py +24 -5
  48. pygpt_net/controller/debug/__init__.py +27 -6
  49. pygpt_net/controller/dialogs/confirm.py +34 -7
  50. pygpt_net/controller/dialogs/debug.py +4 -2
  51. pygpt_net/controller/dialogs/info.py +7 -2
  52. pygpt_net/controller/files.py +48 -10
  53. pygpt_net/controller/finder.py +11 -5
  54. pygpt_net/controller/idx/__init__.py +10 -3
  55. pygpt_net/controller/idx/common.py +4 -2
  56. pygpt_net/controller/idx/indexer.py +25 -17
  57. pygpt_net/controller/idx/settings.py +9 -3
  58. pygpt_net/controller/kernel/__init__.py +34 -8
  59. pygpt_net/controller/kernel/reply.py +12 -3
  60. pygpt_net/controller/kernel/stack.py +5 -3
  61. pygpt_net/controller/lang/custom.py +2 -7
  62. pygpt_net/controller/lang/mapping.py +5 -3
  63. pygpt_net/controller/layout.py +2 -2
  64. pygpt_net/controller/mode.py +16 -4
  65. pygpt_net/controller/model/__init__.py +14 -3
  66. pygpt_net/controller/model/editor.py +8 -3
  67. pygpt_net/controller/notepad.py +26 -12
  68. pygpt_net/controller/painter/capture.py +23 -4
  69. pygpt_net/controller/painter/common.py +9 -7
  70. pygpt_net/controller/plugins/__init__.py +19 -5
  71. pygpt_net/controller/plugins/presets.py +15 -6
  72. pygpt_net/controller/plugins/settings.py +9 -3
  73. pygpt_net/controller/presets/__init__.py +55 -16
  74. pygpt_net/controller/presets/editor.py +26 -10
  75. pygpt_net/controller/settings/__init__.py +3 -2
  76. pygpt_net/controller/settings/editor.py +29 -7
  77. pygpt_net/controller/settings/profile.py +22 -5
  78. pygpt_net/controller/theme/__init__.py +54 -12
  79. pygpt_net/controller/theme/common.py +24 -2
  80. pygpt_net/controller/theme/markdown.py +32 -16
  81. pygpt_net/controller/theme/menu.py +26 -5
  82. pygpt_net/controller/theme/nodes.py +2 -5
  83. pygpt_net/controller/tools/__init__.py +40 -2
  84. pygpt_net/controller/ui/__init__.py +4 -6
  85. pygpt_net/controller/ui/tabs.py +363 -65
  86. pygpt_net/core/access/actions.py +6 -4
  87. pygpt_net/core/access/shortcuts.py +4 -3
  88. pygpt_net/core/access/voice.py +6 -5
  89. pygpt_net/core/agents/legacy.py +4 -2
  90. pygpt_net/core/agents/memory.py +7 -2
  91. pygpt_net/core/agents/observer/evaluation.py +15 -7
  92. pygpt_net/core/agents/provider.py +9 -4
  93. pygpt_net/core/agents/runner.py +61 -15
  94. pygpt_net/core/agents/tools.py +23 -5
  95. pygpt_net/core/assistants/__init__.py +6 -4
  96. pygpt_net/core/assistants/files.py +35 -12
  97. pygpt_net/core/assistants/store.py +20 -10
  98. pygpt_net/core/attachments/__init__.py +54 -15
  99. pygpt_net/core/attachments/context.py +92 -29
  100. pygpt_net/core/audio/__init__.py +71 -3
  101. pygpt_net/core/audio/context.py +7 -2
  102. pygpt_net/core/bridge/__init__.py +22 -6
  103. pygpt_net/core/bridge/context.py +5 -3
  104. pygpt_net/core/calendar/__init__.py +57 -11
  105. pygpt_net/core/chain/__init__.py +8 -2
  106. pygpt_net/core/chain/chat.py +10 -8
  107. pygpt_net/core/chain/completion.py +10 -7
  108. pygpt_net/core/command.py +62 -17
  109. pygpt_net/core/ctx/__init__.py +260 -58
  110. pygpt_net/core/ctx/bag.py +25 -4
  111. pygpt_net/core/ctx/container.py +28 -17
  112. pygpt_net/core/ctx/idx.py +45 -8
  113. pygpt_net/core/ctx/output.py +95 -74
  114. pygpt_net/core/ctx/reply.py +5 -2
  115. pygpt_net/core/db/__init__.py +8 -7
  116. pygpt_net/core/db/viewer.py +17 -11
  117. pygpt_net/core/debug/__init__.py +10 -9
  118. pygpt_net/core/debug/tabs.py +5 -2
  119. pygpt_net/core/docker/__init__.py +11 -5
  120. pygpt_net/core/docker/builder.py +11 -3
  121. pygpt_net/core/events/app.py +5 -3
  122. pygpt_net/core/events/base.py +11 -5
  123. pygpt_net/core/events/control.py +5 -3
  124. pygpt_net/core/events/event.py +17 -7
  125. pygpt_net/core/events/kernel.py +5 -3
  126. pygpt_net/core/events/render.py +5 -3
  127. pygpt_net/core/experts/__init__.py +5 -4
  128. pygpt_net/core/filesystem/__init__.py +52 -34
  129. pygpt_net/core/filesystem/actions.py +8 -5
  130. pygpt_net/core/filesystem/editor.py +13 -3
  131. pygpt_net/core/filesystem/types.py +12 -7
  132. pygpt_net/core/filesystem/url.py +7 -3
  133. pygpt_net/core/idx/__init__.py +34 -25
  134. pygpt_net/core/idx/chat.py +40 -16
  135. pygpt_net/core/idx/context.py +6 -2
  136. pygpt_net/core/idx/indexing.py +84 -35
  137. pygpt_net/core/idx/llm.py +11 -3
  138. pygpt_net/core/idx/metadata.py +13 -3
  139. pygpt_net/core/idx/types/ctx.py +32 -6
  140. pygpt_net/core/idx/types/external.py +41 -7
  141. pygpt_net/core/idx/types/files.py +31 -6
  142. pygpt_net/core/image.py +15 -4
  143. pygpt_net/core/llm/__init__.py +13 -3
  144. pygpt_net/core/locale.py +34 -8
  145. pygpt_net/core/models.py +4 -3
  146. pygpt_net/core/notepad.py +9 -4
  147. pygpt_net/core/plugins.py +7 -6
  148. pygpt_net/core/presets.py +19 -10
  149. pygpt_net/core/profile.py +12 -6
  150. pygpt_net/core/prompt/__init__.py +10 -3
  151. pygpt_net/core/prompt/custom.py +7 -6
  152. pygpt_net/core/prompt/template.py +9 -3
  153. pygpt_net/core/render/base.py +117 -22
  154. pygpt_net/core/render/markdown/body.py +27 -7
  155. pygpt_net/core/render/markdown/renderer.py +119 -22
  156. pygpt_net/core/render/plain/body.py +22 -5
  157. pygpt_net/core/render/plain/renderer.py +97 -21
  158. pygpt_net/core/render/web/body.py +75 -25
  159. pygpt_net/core/render/web/renderer.py +313 -63
  160. pygpt_net/core/settings.py +9 -4
  161. pygpt_net/core/tabs/__init__.py +290 -103
  162. pygpt_net/core/tabs/tab.py +17 -4
  163. pygpt_net/core/tokens.py +44 -11
  164. pygpt_net/core/updater/__init__.py +20 -7
  165. pygpt_net/core/vision/analyzer.py +29 -6
  166. pygpt_net/core/web.py +130 -2
  167. pygpt_net/data/config/config.json +15 -4
  168. pygpt_net/data/config/models.json +3 -3
  169. pygpt_net/data/config/modes.json +3 -3
  170. pygpt_net/data/config/settings.json +55 -10
  171. pygpt_net/data/config/settings_section.json +3 -0
  172. pygpt_net/data/css/style.light.css +1 -0
  173. pygpt_net/data/css/{web.css → web-blocks.css} +162 -133
  174. pygpt_net/data/css/{web.light.css → web-blocks.light.css} +7 -0
  175. pygpt_net/data/css/web-chatgpt.css +350 -0
  176. pygpt_net/data/css/web-chatgpt.dark.css +64 -0
  177. pygpt_net/data/css/web-chatgpt.light.css +75 -0
  178. pygpt_net/data/css/web-chatgpt_wide.css +350 -0
  179. pygpt_net/data/css/web-chatgpt_wide.dark.css +64 -0
  180. pygpt_net/data/css/web-chatgpt_wide.light.css +75 -0
  181. pygpt_net/data/icons/split_screen.svg +1 -0
  182. pygpt_net/data/locale/locale.de.ini +12 -0
  183. pygpt_net/data/locale/locale.en.ini +17 -2
  184. pygpt_net/data/locale/locale.es.ini +12 -0
  185. pygpt_net/data/locale/locale.fr.ini +12 -0
  186. pygpt_net/data/locale/locale.it.ini +12 -0
  187. pygpt_net/data/locale/locale.pl.ini +12 -0
  188. pygpt_net/data/locale/locale.uk.ini +12 -0
  189. pygpt_net/data/locale/locale.zh.ini +12 -0
  190. pygpt_net/data/locale/plugin.cmd_web.de.ini +2 -0
  191. pygpt_net/data/locale/plugin.cmd_web.en.ini +20 -10
  192. pygpt_net/data/locale/plugin.cmd_web.es.ini +2 -0
  193. pygpt_net/data/locale/plugin.cmd_web.fr.ini +2 -0
  194. pygpt_net/data/locale/plugin.cmd_web.it.ini +2 -0
  195. pygpt_net/data/locale/plugin.cmd_web.pl.ini +2 -0
  196. pygpt_net/data/locale/plugin.cmd_web.uk.ini +2 -0
  197. pygpt_net/data/locale/plugin.cmd_web.zh.ini +2 -0
  198. pygpt_net/icons.qrc +1 -0
  199. pygpt_net/icons_rc.py +165 -136
  200. pygpt_net/item/ctx.py +46 -24
  201. pygpt_net/plugin/audio_input/simple.py +21 -5
  202. pygpt_net/plugin/audio_output/__init__.py +4 -1
  203. pygpt_net/plugin/base/config.py +4 -2
  204. pygpt_net/plugin/base/plugin.py +26 -6
  205. pygpt_net/plugin/base/worker.py +37 -9
  206. pygpt_net/plugin/cmd_code_interpreter/__init__.py +39 -37
  207. pygpt_net/plugin/cmd_code_interpreter/runner.py +25 -12
  208. pygpt_net/plugin/cmd_web/__init__.py +46 -6
  209. pygpt_net/plugin/cmd_web/config.py +74 -48
  210. pygpt_net/plugin/cmd_web/websearch.py +61 -28
  211. pygpt_net/plugin/cmd_web/worker.py +79 -13
  212. pygpt_net/provider/core/config/patch.py +43 -1
  213. pygpt_net/provider/core/ctx/base.py +4 -1
  214. pygpt_net/provider/core/ctx/db_sqlite/__init__.py +10 -1
  215. pygpt_net/provider/core/ctx/db_sqlite/storage.py +22 -1
  216. pygpt_net/provider/gpt/assistants.py +10 -9
  217. pygpt_net/provider/gpt/audio.py +3 -2
  218. pygpt_net/provider/gpt/chat.py +8 -7
  219. pygpt_net/provider/gpt/completion.py +6 -4
  220. pygpt_net/provider/gpt/image.py +9 -2
  221. pygpt_net/provider/gpt/store.py +14 -13
  222. pygpt_net/provider/gpt/vision.py +6 -5
  223. pygpt_net/tools/__init__.py +9 -1
  224. pygpt_net/tools/base.py +15 -1
  225. pygpt_net/tools/code_interpreter/__init__.py +174 -75
  226. pygpt_net/tools/code_interpreter/ui/dialogs.py +21 -103
  227. pygpt_net/tools/code_interpreter/ui/widgets.py +284 -9
  228. pygpt_net/tools/html_canvas/__init__.py +78 -23
  229. pygpt_net/tools/html_canvas/ui/dialogs.py +46 -62
  230. pygpt_net/tools/html_canvas/ui/widgets.py +96 -3
  231. pygpt_net/ui/base/context_menu.py +2 -2
  232. pygpt_net/ui/layout/chat/input.py +10 -18
  233. pygpt_net/ui/layout/chat/output.py +26 -44
  234. pygpt_net/ui/layout/ctx/ctx_list.py +13 -4
  235. pygpt_net/ui/layout/toolbox/footer.py +18 -2
  236. pygpt_net/ui/main.py +2 -2
  237. pygpt_net/ui/menu/config.py +7 -11
  238. pygpt_net/ui/menu/debug.py +11 -1
  239. pygpt_net/ui/menu/theme.py +9 -2
  240. pygpt_net/ui/widget/filesystem/explorer.py +2 -2
  241. pygpt_net/ui/widget/lists/context.py +27 -5
  242. pygpt_net/ui/widget/tabs/Input.py +2 -2
  243. pygpt_net/ui/widget/tabs/body.py +2 -1
  244. pygpt_net/ui/widget/tabs/layout.py +195 -0
  245. pygpt_net/ui/widget/tabs/output.py +218 -55
  246. pygpt_net/ui/widget/textarea/html.py +11 -1
  247. pygpt_net/ui/widget/textarea/output.py +10 -1
  248. pygpt_net/ui/widget/textarea/search_input.py +4 -1
  249. pygpt_net/ui/widget/textarea/web.py +49 -9
  250. {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.41.dist-info}/METADATA +45 -116
  251. {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.41.dist-info}/RECORD +255 -247
  252. /pygpt_net/data/css/{web.dark.css → web-blocks.dark.css} +0 -0
  253. {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.41.dist-info}/LICENSE +0 -0
  254. {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.41.dist-info}/WHEEL +0 -0
  255. {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.41.dist-info}/entry_points.txt +0 -0
@@ -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.11.26 19:00:00 #
9
+ # Updated Date: 2024.12.13 08:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  from PySide6.QtCore import Slot
@@ -127,12 +127,15 @@ class Plugin(BasePlugin):
127
127
  elif name == Event.CTX_AFTER:
128
128
  if mode == MODE_AUDIO:
129
129
  return # skip if audio mode
130
+ self.stop_audio()
130
131
  self.on_generate(ctx, event)
131
132
 
132
133
  elif name == Event.AUDIO_READ_TEXT:
134
+ self.stop_audio()
133
135
  self.on_generate(ctx, event)
134
136
 
135
137
  elif name == Event.AUDIO_PLAYBACK:
138
+ self.stop_audio()
136
139
  self.on_playback(ctx, event)
137
140
 
138
141
  elif name == Event.AUDIO_OUTPUT_STOP:
@@ -6,16 +6,18 @@
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.11.16 05:00:00 #
9
+ # Updated Date: 2024.12.14 00:00:00 #
10
10
  # ================================================== #
11
11
 
12
+ from typing import Optional
13
+
12
14
  from .plugin import BasePlugin
13
15
 
14
16
  class BaseConfig:
15
17
  def __init__(self, plugin: BasePlugin = None, *args, **kwargs):
16
18
  self.plugin = plugin
17
19
 
18
- def from_defaults(self, plugin: BasePlugin = None):
20
+ def from_defaults(self, plugin: Optional[BasePlugin] = None):
19
21
  """
20
22
  Set default options for plugin
21
23
 
@@ -6,10 +6,11 @@
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.11.21 20:00:00 #
9
+ # Updated Date: 2024.12.14 00:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import copy
13
+ from typing import Optional
13
14
 
14
15
  from PySide6.QtCore import QObject, Slot
15
16
 
@@ -234,7 +235,7 @@ class BasePlugin(QObject):
234
235
  """
235
236
  return
236
237
 
237
- def trans(self, text: str = None) -> str:
238
+ def trans(self, text: Optional[str] = None) -> str:
238
239
  """
239
240
  Translate text using plugin domain
240
241
 
@@ -264,7 +265,12 @@ class BasePlugin(QObject):
264
265
  """
265
266
  self.window.core.debug.info(data)
266
267
 
267
- def reply(self, response: dict, ctx: CtxItem = None, extra_data: dict = None):
268
+ def reply(
269
+ self,
270
+ response: dict,
271
+ ctx: Optional[CtxItem] = None,
272
+ extra_data: Optional[dict] = None
273
+ ):
268
274
  """
269
275
  Send reply from plugin (command response)
270
276
 
@@ -329,7 +335,12 @@ class BasePlugin(QObject):
329
335
  }))
330
336
 
331
337
  @Slot(object, object, dict)
332
- def handle_finished(self, response: dict, ctx: CtxItem = None, extra_data: dict = None):
338
+ def handle_finished(
339
+ self,
340
+ response: dict,
341
+ ctx: Optional[CtxItem] = None,
342
+ extra_data: Optional[dict] = None
343
+ ):
333
344
  """
334
345
  Handle finished response signal
335
346
 
@@ -354,7 +365,12 @@ class BasePlugin(QObject):
354
365
  self.window.dispatch(event)
355
366
 
356
367
  @Slot(object, object, dict)
357
- def handle_finished_more(self, responses: list, ctx: CtxItem = None, extra_data: dict = None):
368
+ def handle_finished_more(
369
+ self,
370
+ responses: list,
371
+ ctx: Optional[CtxItem] = None,
372
+ extra_data: Optional[dict] = None
373
+ ):
358
374
  """
359
375
  Handle finished response signal
360
376
 
@@ -379,7 +395,11 @@ class BasePlugin(QObject):
379
395
  })
380
396
  self.window.dispatch(event)
381
397
 
382
- def prepare_reply_ctx(self, response: dict, ctx: CtxItem = None) -> dict:
398
+ def prepare_reply_ctx(
399
+ self,
400
+ response: dict,
401
+ ctx: Optional[CtxItem] = None
402
+ ) -> dict:
383
403
  """
384
404
  Prepare reply context
385
405
 
@@ -6,9 +6,11 @@
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.11.24 04:00:00 #
9
+ # Updated Date: 2024.12.14 00:00:00 #
10
10
  # ================================================== #
11
11
 
12
+ from typing import Optional, Any
13
+
12
14
  from PySide6.QtCore import QObject, QRunnable
13
15
  from typing_extensions import deprecated
14
16
 
@@ -17,7 +19,7 @@ from .signals import BaseSignals
17
19
 
18
20
 
19
21
  class BaseWorker(QObject, QRunnable):
20
- def __init__(self, plugin: BasePlugin = None, *args, **kwargs):
22
+ def __init__(self, plugin: Optional[BasePlugin] = None, *args, **kwargs):
21
23
  QObject.__init__(self)
22
24
  QRunnable.__init__(self)
23
25
  self.plugin = plugin
@@ -63,7 +65,11 @@ class BaseWorker(QObject, QRunnable):
63
65
  self.signals.log.emit(msg)
64
66
 
65
67
  @deprecated("From 2.1.29: BaseWorker.response() is deprecated, use BaseWorker.reply() instead")
66
- def response(self, response: dict, extra_data: dict = None):
68
+ def response(
69
+ self,
70
+ response: dict,
71
+ extra_data: Optional[dict] = None
72
+ ):
67
73
  """
68
74
  Emit finished signal (deprecated)
69
75
 
@@ -74,7 +80,11 @@ class BaseWorker(QObject, QRunnable):
74
80
  self.debug("BaseWorker.response is deprecated from 2.1.29, use BaseWorker.reply instead")
75
81
  self.reply(response, extra_data)
76
82
 
77
- def reply(self, response: dict, extra_data: dict = None):
83
+ def reply(
84
+ self,
85
+ response: dict,
86
+ extra_data: Optional[dict] = None
87
+ ):
78
88
  """
79
89
  Emit finished signal (on reply from command output)
80
90
 
@@ -89,7 +99,11 @@ class BaseWorker(QObject, QRunnable):
89
99
  if self.signals is not None and hasattr(self.signals, "finished"):
90
100
  self.signals.finished.emit(response, self.ctx, extra_data)
91
101
 
92
- def reply_more(self, responses: list, extra_data: dict = None):
102
+ def reply_more(
103
+ self,
104
+ responses: list,
105
+ extra_data: Optional[dict] = None
106
+ ):
93
107
  """
94
108
  Emit finished_more signal (on reply from command output, multiple responses)
95
109
 
@@ -161,7 +175,12 @@ class BaseWorker(QObject, QRunnable):
161
175
  """
162
176
  return {"cmd": item["cmd"]}
163
177
 
164
- def make_response(self, item: dict, result: any, extra: dict = None) -> dict:
178
+ def make_response(
179
+ self,
180
+ item: dict,
181
+ result: any,
182
+ extra: Optional[dict] = None
183
+ ) -> dict:
165
184
  """
166
185
  Prepare response item
167
186
 
@@ -190,7 +209,11 @@ class BaseWorker(QObject, QRunnable):
190
209
  self.log(msg)
191
210
  return msg
192
211
 
193
- def has_param(self, item: dict, param: str) -> bool:
212
+ def has_param(
213
+ self,
214
+ item: dict,
215
+ param: str
216
+ ) -> bool:
194
217
  """
195
218
  Check if item has parameter
196
219
 
@@ -202,7 +225,12 @@ class BaseWorker(QObject, QRunnable):
202
225
  return False
203
226
  return "params" in item and param in item["params"]
204
227
 
205
- def get_param(self, item: dict, param: str, default: any = None) -> any:
228
+ def get_param(
229
+ self,
230
+ item: dict,
231
+ param: str,
232
+ default: Any = None
233
+ ) -> any:
206
234
  """
207
235
  Get parameter value from item
208
236
 
@@ -215,7 +243,7 @@ class BaseWorker(QObject, QRunnable):
215
243
  return item["params"][param]
216
244
  return default
217
245
 
218
- def is_stopped(self):
246
+ def is_stopped(self) -> bool:
219
247
  """
220
248
  Check if worker is stopped
221
249
 
@@ -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.11.25 02:00:00 #
9
+ # Updated Date: 2024.12.12 01:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import os
@@ -118,42 +118,6 @@ class Plugin(BasePlugin):
118
118
  "directory is mapped as volume in host machine to: {}").format(legacy_data)
119
119
  data['cmd'].append(cmd) # append command
120
120
 
121
- @Slot(object, str)
122
- def handle_interpreter_output(self, data, type):
123
- """
124
- Handle interpreter output
125
-
126
- :param data: output data
127
- :param type: output type
128
- """
129
- if not self.get_option_value("attach_output"):
130
- return
131
- self.window.tools.get("interpreter").append_output(data, type)
132
-
133
- @Slot()
134
- def handle_interpreter_clear(self):
135
- """Handle interpreter clear"""
136
- self.window.tools.get("interpreter").clear_all()
137
-
138
- @Slot(object)
139
- def handle_html_output(self, data):
140
- """
141
- Handle HTML/JS canvas output
142
-
143
- :param data: HTML/JS code
144
- """
145
- self.window.tools.get("html_canvas").set_output(data)
146
- self.window.tools.get("html_canvas").open()
147
- def get_interpreter(self):
148
- """
149
- Get interpreter
150
-
151
- :return: interpreter
152
- """
153
- if self.get_option_value("sandbox_ipython"):
154
- return self.ipython_docker
155
- else:
156
- return self.ipython_local
157
121
 
158
122
  def cmd(self, ctx: CtxItem, cmds: list, silent: bool = False):
159
123
  """
@@ -270,3 +234,41 @@ class Plugin(BasePlugin):
270
234
  self.window.tools.get("interpreter").append_output(cleaned_data)
271
235
  if self.window.tools.get("interpreter").opened:
272
236
  self.window.update_status("")
237
+
238
+ @Slot(object, str)
239
+ def handle_interpreter_output(self, data, type):
240
+ """
241
+ Handle interpreter output
242
+
243
+ :param data: output data
244
+ :param type: output type
245
+ """
246
+ if not self.get_option_value("attach_output"):
247
+ return
248
+ self.window.tools.get("interpreter").append_output(data, type)
249
+
250
+ @Slot()
251
+ def handle_interpreter_clear(self):
252
+ """Handle interpreter clear"""
253
+ self.window.tools.get("interpreter").clear_all()
254
+
255
+ @Slot(object)
256
+ def handle_html_output(self, data):
257
+ """
258
+ Handle HTML/JS canvas output
259
+
260
+ :param data: HTML/JS code
261
+ """
262
+ self.window.tools.get("html_canvas").set_output(data)
263
+ self.window.tools.get("html_canvas").auto_open()
264
+
265
+ def get_interpreter(self):
266
+ """
267
+ Get interpreter
268
+
269
+ :return: interpreter
270
+ """
271
+ if self.get_option_value("sandbox_ipython"):
272
+ return self.ipython_docker
273
+ else:
274
+ return self.ipython_local
@@ -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.11.26 04:00:00 #
9
+ # Updated Date: 2024.12.12 01:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import os.path
@@ -164,6 +164,14 @@ class Runner:
164
164
  """
165
165
  return self.plugin.get_option_value('sandbox_docker')
166
166
 
167
+ def is_sandbox_ipython(self) -> bool:
168
+ """
169
+ Check if sandbox is enabled for IPython
170
+
171
+ :return: True if sandbox is enabled
172
+ """
173
+ return self.plugin.get_option_value('sandbox_ipython')
174
+
167
175
  def get_docker(self) -> docker.client.DockerClient:
168
176
  """
169
177
  Get docker client
@@ -392,13 +400,14 @@ class Runner:
392
400
  :param all: execute all
393
401
  :return: response dict
394
402
  """
403
+ sandbox = self.is_sandbox_ipython()
395
404
  data = item["params"]['code']
396
405
  if not all:
397
406
  path = self.plugin.window.tools.get("interpreter").file_current
398
407
  if "path" in item["params"]:
399
408
  path = item["params"]['path']
400
409
  msg = "Saving Python file: {}".format(path)
401
- self.log(msg, sandbox=True)
410
+ self.log(msg, sandbox=sandbox)
402
411
  with open(self.prepare_path(path, on_host=True), 'w', encoding="utf-8") as file:
403
412
  file.write(data)
404
413
  else:
@@ -412,12 +421,13 @@ class Runner:
412
421
 
413
422
  # run code in IPython interpreter
414
423
  msg = "Executing Python code: {}".format(item["params"]['code'])
415
- self.log(msg, sandbox=True)
416
- self.log("Connecting to IPython interpreter...", sandbox=True)
424
+ self.log(msg, sandbox=sandbox)
425
+ self.log("Connecting to IPython interpreter...", sandbox=sandbox)
417
426
  try:
418
- self.log("Please wait...", sandbox=True)
427
+ self.log("Please wait...", sandbox=sandbox)
419
428
  result = self.plugin.get_interpreter().execute(data, current=False)
420
429
  result = self.handle_result_ipython(ctx, result)
430
+ self.log("Python Code Executed.", sandbox=sandbox)
421
431
  except Exception as e:
422
432
  self.error(e)
423
433
  result = str(e)
@@ -437,13 +447,14 @@ class Runner:
437
447
  :param all: execute all
438
448
  :return: response dict
439
449
  """
450
+ sandbox = self.is_sandbox_ipython()
440
451
  data = item["params"]['code']
441
452
  if not all:
442
453
  path = self.plugin.window.tools.get("interpreter").file_current
443
454
  if "path" in item["params"]:
444
455
  path = item["params"]['path']
445
456
  msg = "Saving Python file: {}".format(path)
446
- self.log(msg, sandbox=True)
457
+ self.log(msg, sandbox=sandbox)
447
458
  with open(self.prepare_path(path, on_host=True), 'w', encoding="utf-8") as file:
448
459
  file.write(data)
449
460
  else:
@@ -457,12 +468,13 @@ class Runner:
457
468
 
458
469
  # run code in IPython interpreter
459
470
  msg = "Executing Python code: {}".format(item["params"]['code'])
460
- self.log(msg, sandbox=True)
461
- self.log("Connecting to IPython interpreter...", sandbox=True)
471
+ self.log(msg, sandbox=sandbox)
472
+ self.log("Connecting to IPython interpreter...", sandbox=sandbox)
462
473
  try:
463
- self.log("Please wait...", sandbox=True)
474
+ self.log("Please wait...", sandbox=sandbox)
464
475
  result = self.plugin.get_interpreter().execute(data, current=True)
465
476
  result = self.handle_result_ipython(ctx, result)
477
+ self.log("Python Code Executed.", sandbox=sandbox)
466
478
  except Exception as e:
467
479
  self.error(e)
468
480
  result = str(e)
@@ -482,13 +494,14 @@ class Runner:
482
494
  :param all: execute all
483
495
  :return: response dict
484
496
  """
497
+ sandbox = self.is_sandbox_ipython()
485
498
  self.append_input("")
486
499
  self.send_interpreter_input("") # send input to interpreter tool
487
500
 
488
501
  # restart IPython interpreter
489
- self.log("Connecting to IPython interpreter...", sandbox=True)
502
+ self.log("Connecting to IPython interpreter...", sandbox=sandbox)
490
503
  try:
491
- self.log("Restarting IPython kernel...", sandbox=True)
504
+ self.log("Restarting IPython kernel...", sandbox=sandbox)
492
505
  response = self.plugin.get_interpreter().restart_kernel()
493
506
  except Exception as e:
494
507
  self.error(e)
@@ -497,7 +510,7 @@ class Runner:
497
510
  result = "Kernel restarted"
498
511
  else:
499
512
  result = "Kernel not restarted"
500
- self.log(result)
513
+ self.log(result, sandbox=sandbox)
501
514
  return {
502
515
  "request": request,
503
516
  "result": str(result),
@@ -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.11.20 21:00:00 #
9
+ # Updated Date: 2024.12.13 08:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import ssl
@@ -40,6 +40,8 @@ class Plugin(BasePlugin):
40
40
  "web_url_raw",
41
41
  "web_index",
42
42
  "web_index_query",
43
+ "web_extract_links",
44
+ "web_extract_images",
43
45
  ]
44
46
  self.order = 100
45
47
  self.use_locale = True
@@ -269,26 +271,66 @@ class Plugin(BasePlugin):
269
271
 
270
272
  :param data: event data dict
271
273
  """
274
+ max_urls = self.get_option_value("max_open_urls")
275
+ is_summary = True
276
+ if self.get_option_value("raw"):
277
+ is_summary = False
278
+
272
279
  for option in self.allowed_cmds:
273
280
  if not self.has_cmd(option):
274
281
  continue
275
282
 
276
- # special case for web_index
277
283
  if option == "web_index":
278
284
  data['cmd'].append(self.prepare_idx_syntax()) # prepare params
279
285
  continue
280
286
  elif option == "web_index_query":
281
287
  data['cmd'].append(self.prepare_idx_query_syntax()) # prepare params
282
288
  continue
289
+ elif option == "web_url_open":
290
+ cmd = self.get_cmd(option)
291
+ try:
292
+ cmd["instruction"] = cmd["instruction"].format(
293
+ max_urls=max_urls,
294
+ )
295
+ if not is_summary:
296
+ for param in list(cmd["params"]):
297
+ if param["name"] == "summarize_prompt":
298
+ cmd["params"].remove(param)
299
+ data['cmd'].append(cmd)
300
+ continue
301
+ except Exception as e:
302
+ pass
303
+ elif option == "web_url_raw":
304
+ cmd = self.get_cmd(option)
305
+ try:
306
+ cmd["instruction"] = cmd["instruction"].format(
307
+ max_urls=max_urls,
308
+ )
309
+ if not is_summary:
310
+ for param in list(cmd["params"]):
311
+ if param["name"] == "summarize_prompt":
312
+ cmd["params"].remove(param)
313
+ data['cmd'].append(cmd)
314
+ continue
315
+ except Exception as e:
316
+ pass
283
317
  elif option == "web_search":
284
318
  max_pages = self.get_option_value("num_pages")
285
319
  cmd = self.get_cmd(option)
286
320
  try:
287
- cmd["instruction"] = cmd["instruction"].format(max_pages=max_pages)
321
+ cmd["instruction"] = cmd["instruction"].format(
322
+ max_pages=max_pages,
323
+ max_urls=max_urls,
324
+ )
325
+ if not is_summary:
326
+ for param in list(cmd["params"]):
327
+ if param["name"] == "summarize_prompt":
328
+ cmd["params"].remove(param)
288
329
  data['cmd'].append(cmd)
289
330
  continue
290
331
  except Exception as e:
291
332
  pass
333
+
292
334
  data['cmd'].append(self.get_cmd(option)) # append command
293
335
 
294
336
  def cmd(self, ctx: CtxItem, cmds: list):
@@ -389,8 +431,6 @@ class Plugin(BasePlugin):
389
431
  req,
390
432
  timeout=self.get_option_value('timeout'),
391
433
  ).read()
392
- except HTTPError as e:
393
- data = str(e)
394
434
  except Exception as e:
395
- raise e
435
+ data = str(e)
396
436
  return data