pygpt-net 2.4.37__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.
Files changed (340) hide show
  1. CHANGELOG.md +37 -0
  2. README.md +176 -182
  3. pygpt_net/CHANGELOG.txt +37 -0
  4. pygpt_net/__init__.py +3 -3
  5. pygpt_net/app.py +3 -1
  6. pygpt_net/controller/__init__.py +7 -3
  7. pygpt_net/controller/access/control.py +1 -1
  8. pygpt_net/controller/access/voice.py +11 -5
  9. pygpt_net/controller/agent/experts.py +11 -6
  10. pygpt_net/controller/agent/legacy.py +8 -6
  11. pygpt_net/controller/agent/llama.py +4 -2
  12. pygpt_net/controller/assistant/__init__.py +9 -4
  13. pygpt_net/controller/assistant/batch.py +38 -21
  14. pygpt_net/controller/assistant/editor.py +7 -6
  15. pygpt_net/controller/assistant/files.py +23 -7
  16. pygpt_net/controller/assistant/store.py +20 -7
  17. pygpt_net/controller/assistant/threads.py +34 -8
  18. pygpt_net/controller/attachment.py +29 -10
  19. pygpt_net/controller/audio/__init__.py +26 -5
  20. pygpt_net/controller/calendar/__init__.py +23 -4
  21. pygpt_net/controller/calendar/note.py +57 -11
  22. pygpt_net/controller/camera.py +4 -12
  23. pygpt_net/controller/chat/__init__.py +5 -3
  24. pygpt_net/controller/chat/attachment.py +34 -7
  25. pygpt_net/controller/chat/audio.py +2 -2
  26. pygpt_net/controller/chat/command.py +4 -2
  27. pygpt_net/controller/chat/common.py +11 -4
  28. pygpt_net/controller/chat/files.py +10 -3
  29. pygpt_net/controller/chat/image.py +17 -5
  30. pygpt_net/controller/chat/input.py +10 -7
  31. pygpt_net/controller/chat/output.py +21 -6
  32. pygpt_net/controller/chat/render.py +100 -21
  33. pygpt_net/controller/chat/response.py +34 -7
  34. pygpt_net/controller/chat/stream.py +4 -2
  35. pygpt_net/controller/chat/text.py +6 -4
  36. pygpt_net/controller/command.py +11 -3
  37. pygpt_net/controller/config/__init__.py +34 -6
  38. pygpt_net/controller/config/field/checkbox.py +7 -4
  39. pygpt_net/controller/config/field/cmd.py +7 -5
  40. pygpt_net/controller/config/field/combo.py +14 -6
  41. pygpt_net/controller/config/field/dictionary.py +14 -11
  42. pygpt_net/controller/config/field/input.py +9 -6
  43. pygpt_net/controller/config/field/slider.py +11 -8
  44. pygpt_net/controller/config/field/textarea.py +8 -5
  45. pygpt_net/controller/config/placeholder.py +66 -21
  46. pygpt_net/controller/ctx/__init__.py +138 -49
  47. pygpt_net/controller/ctx/common.py +15 -4
  48. pygpt_net/controller/ctx/extra.py +11 -3
  49. pygpt_net/controller/ctx/summarizer.py +24 -5
  50. pygpt_net/controller/debug/__init__.py +27 -6
  51. pygpt_net/controller/dialogs/confirm.py +34 -7
  52. pygpt_net/controller/dialogs/debug.py +4 -2
  53. pygpt_net/controller/dialogs/info.py +7 -2
  54. pygpt_net/controller/files.py +48 -10
  55. pygpt_net/controller/finder.py +11 -5
  56. pygpt_net/controller/idx/__init__.py +10 -3
  57. pygpt_net/controller/idx/common.py +4 -2
  58. pygpt_net/controller/idx/indexer.py +25 -17
  59. pygpt_net/controller/idx/settings.py +9 -3
  60. pygpt_net/controller/kernel/__init__.py +34 -8
  61. pygpt_net/controller/kernel/reply.py +12 -3
  62. pygpt_net/controller/kernel/stack.py +5 -3
  63. pygpt_net/controller/lang/custom.py +2 -7
  64. pygpt_net/controller/lang/mapping.py +5 -3
  65. pygpt_net/controller/layout.py +2 -2
  66. pygpt_net/controller/mode.py +16 -4
  67. pygpt_net/controller/model/__init__.py +14 -3
  68. pygpt_net/controller/model/editor.py +8 -3
  69. pygpt_net/controller/notepad.py +26 -12
  70. pygpt_net/controller/painter/capture.py +23 -4
  71. pygpt_net/controller/painter/common.py +9 -7
  72. pygpt_net/controller/plugins/__init__.py +19 -5
  73. pygpt_net/controller/plugins/presets.py +15 -6
  74. pygpt_net/controller/plugins/settings.py +9 -3
  75. pygpt_net/controller/presets/__init__.py +55 -16
  76. pygpt_net/controller/presets/editor.py +26 -10
  77. pygpt_net/controller/settings/__init__.py +3 -2
  78. pygpt_net/controller/settings/editor.py +29 -7
  79. pygpt_net/controller/settings/profile.py +22 -5
  80. pygpt_net/controller/theme/__init__.py +54 -12
  81. pygpt_net/controller/theme/common.py +24 -2
  82. pygpt_net/controller/theme/markdown.py +32 -16
  83. pygpt_net/controller/theme/menu.py +26 -5
  84. pygpt_net/controller/theme/nodes.py +2 -5
  85. pygpt_net/controller/tools/__init__.py +40 -2
  86. pygpt_net/controller/ui/__init__.py +4 -6
  87. pygpt_net/controller/ui/mode.py +16 -21
  88. pygpt_net/controller/ui/tabs.py +363 -65
  89. pygpt_net/core/access/actions.py +6 -4
  90. pygpt_net/core/access/shortcuts.py +4 -3
  91. pygpt_net/core/access/voice.py +6 -5
  92. pygpt_net/core/agents/legacy.py +4 -2
  93. pygpt_net/core/agents/memory.py +7 -2
  94. pygpt_net/core/agents/observer/evaluation.py +15 -7
  95. pygpt_net/core/agents/provider.py +9 -4
  96. pygpt_net/core/agents/runner.py +61 -15
  97. pygpt_net/core/agents/tools.py +23 -5
  98. pygpt_net/core/assistants/__init__.py +6 -4
  99. pygpt_net/core/assistants/files.py +35 -12
  100. pygpt_net/core/assistants/store.py +20 -10
  101. pygpt_net/core/attachments/__init__.py +54 -15
  102. pygpt_net/core/attachments/context.py +92 -29
  103. pygpt_net/core/audio/__init__.py +74 -3
  104. pygpt_net/core/audio/context.py +7 -2
  105. pygpt_net/core/audio/whisper.py +37 -0
  106. pygpt_net/core/bridge/__init__.py +22 -6
  107. pygpt_net/core/bridge/context.py +5 -3
  108. pygpt_net/core/bridge/worker.py +2 -2
  109. pygpt_net/core/calendar/__init__.py +57 -11
  110. pygpt_net/core/chain/__init__.py +8 -2
  111. pygpt_net/core/chain/chat.py +10 -8
  112. pygpt_net/core/chain/completion.py +10 -7
  113. pygpt_net/core/command.py +62 -17
  114. pygpt_net/core/ctx/__init__.py +260 -58
  115. pygpt_net/core/ctx/bag.py +25 -4
  116. pygpt_net/core/ctx/container.py +28 -17
  117. pygpt_net/core/ctx/idx.py +45 -8
  118. pygpt_net/core/ctx/output.py +95 -74
  119. pygpt_net/core/ctx/reply.py +5 -2
  120. pygpt_net/core/db/__init__.py +8 -7
  121. pygpt_net/core/db/viewer.py +17 -11
  122. pygpt_net/core/debug/__init__.py +10 -9
  123. pygpt_net/core/debug/events.py +22 -10
  124. pygpt_net/core/debug/tabs.py +9 -3
  125. pygpt_net/core/docker/__init__.py +11 -5
  126. pygpt_net/core/docker/builder.py +11 -3
  127. pygpt_net/core/events/app.py +5 -3
  128. pygpt_net/core/events/base.py +11 -5
  129. pygpt_net/core/events/control.py +5 -3
  130. pygpt_net/core/events/event.py +17 -7
  131. pygpt_net/core/events/kernel.py +5 -3
  132. pygpt_net/core/events/render.py +5 -3
  133. pygpt_net/core/experts/__init__.py +5 -4
  134. pygpt_net/core/filesystem/__init__.py +52 -34
  135. pygpt_net/core/filesystem/actions.py +8 -5
  136. pygpt_net/core/filesystem/editor.py +13 -3
  137. pygpt_net/core/filesystem/types.py +12 -7
  138. pygpt_net/core/filesystem/url.py +7 -3
  139. pygpt_net/core/history.py +3 -2
  140. pygpt_net/core/idx/__init__.py +48 -27
  141. pygpt_net/core/idx/chat.py +51 -17
  142. pygpt_net/core/idx/context.py +6 -2
  143. pygpt_net/core/idx/indexing.py +107 -42
  144. pygpt_net/core/idx/llm.py +11 -3
  145. pygpt_net/core/idx/metadata.py +13 -3
  146. pygpt_net/core/idx/types/ctx.py +32 -6
  147. pygpt_net/core/idx/types/external.py +41 -7
  148. pygpt_net/core/idx/types/files.py +31 -6
  149. pygpt_net/core/image.py +15 -4
  150. pygpt_net/core/installer.py +2 -4
  151. pygpt_net/core/llm/__init__.py +13 -3
  152. pygpt_net/core/locale.py +34 -8
  153. pygpt_net/core/models.py +63 -17
  154. pygpt_net/core/modes.py +11 -13
  155. pygpt_net/core/notepad.py +10 -5
  156. pygpt_net/core/plugins.py +31 -19
  157. pygpt_net/core/presets.py +37 -17
  158. pygpt_net/core/profile.py +21 -7
  159. pygpt_net/core/prompt/__init__.py +10 -3
  160. pygpt_net/core/prompt/custom.py +7 -6
  161. pygpt_net/core/prompt/template.py +9 -3
  162. pygpt_net/core/render/base.py +117 -22
  163. pygpt_net/core/render/markdown/body.py +27 -7
  164. pygpt_net/core/render/markdown/renderer.py +119 -22
  165. pygpt_net/core/render/plain/body.py +22 -5
  166. pygpt_net/core/render/plain/renderer.py +97 -21
  167. pygpt_net/core/render/web/body.py +75 -25
  168. pygpt_net/core/render/web/parser.py +3 -1
  169. pygpt_net/core/render/web/renderer.py +313 -63
  170. pygpt_net/core/settings.py +10 -5
  171. pygpt_net/core/tabs/__init__.py +290 -103
  172. pygpt_net/core/tabs/tab.py +26 -5
  173. pygpt_net/core/tokens.py +47 -12
  174. pygpt_net/core/updater/__init__.py +20 -7
  175. pygpt_net/core/vision/analyzer.py +29 -6
  176. pygpt_net/core/{web.py → web/__init__.py} +29 -7
  177. pygpt_net/core/web/helpers.py +237 -0
  178. pygpt_net/data/config/config.json +15 -4
  179. pygpt_net/data/config/models.json +3 -3
  180. pygpt_net/data/config/modes.json +3 -3
  181. pygpt_net/data/config/settings.json +55 -10
  182. pygpt_net/data/config/settings_section.json +3 -0
  183. pygpt_net/data/css/style.light.css +1 -0
  184. pygpt_net/data/css/{web.css → web-blocks.css} +162 -133
  185. pygpt_net/data/css/{web.light.css → web-blocks.light.css} +7 -0
  186. pygpt_net/data/css/web-chatgpt.css +350 -0
  187. pygpt_net/data/css/web-chatgpt.dark.css +64 -0
  188. pygpt_net/data/css/web-chatgpt.light.css +75 -0
  189. pygpt_net/data/css/web-chatgpt_wide.css +350 -0
  190. pygpt_net/data/css/web-chatgpt_wide.dark.css +64 -0
  191. pygpt_net/data/css/web-chatgpt_wide.light.css +75 -0
  192. pygpt_net/data/icons/split_screen.svg +1 -0
  193. pygpt_net/data/locale/locale.de.ini +12 -0
  194. pygpt_net/data/locale/locale.en.ini +18 -2
  195. pygpt_net/data/locale/locale.es.ini +12 -0
  196. pygpt_net/data/locale/locale.fr.ini +12 -0
  197. pygpt_net/data/locale/locale.it.ini +12 -0
  198. pygpt_net/data/locale/locale.pl.ini +12 -0
  199. pygpt_net/data/locale/locale.uk.ini +12 -0
  200. pygpt_net/data/locale/locale.zh.ini +12 -0
  201. pygpt_net/data/locale/plugin.cmd_web.de.ini +2 -0
  202. pygpt_net/data/locale/plugin.cmd_web.en.ini +22 -10
  203. pygpt_net/data/locale/plugin.cmd_web.es.ini +2 -0
  204. pygpt_net/data/locale/plugin.cmd_web.fr.ini +2 -0
  205. pygpt_net/data/locale/plugin.cmd_web.it.ini +2 -0
  206. pygpt_net/data/locale/plugin.cmd_web.pl.ini +2 -0
  207. pygpt_net/data/locale/plugin.cmd_web.uk.ini +2 -0
  208. pygpt_net/data/locale/plugin.cmd_web.zh.ini +2 -0
  209. pygpt_net/data/locale/plugin.mailer.en.ini +21 -0
  210. pygpt_net/icons.qrc +1 -0
  211. pygpt_net/icons_rc.py +165 -136
  212. pygpt_net/item/ctx.py +58 -25
  213. pygpt_net/plugin/agent/__init__.py +7 -2
  214. pygpt_net/plugin/audio_input/simple.py +21 -5
  215. pygpt_net/plugin/audio_output/__init__.py +9 -1
  216. pygpt_net/plugin/base/config.py +4 -2
  217. pygpt_net/plugin/base/plugin.py +75 -23
  218. pygpt_net/plugin/base/worker.py +42 -11
  219. pygpt_net/plugin/cmd_code_interpreter/__init__.py +39 -37
  220. pygpt_net/plugin/cmd_code_interpreter/runner.py +25 -12
  221. pygpt_net/plugin/cmd_history/config.py +2 -2
  222. pygpt_net/plugin/cmd_web/__init__.py +48 -9
  223. pygpt_net/plugin/cmd_web/config.py +135 -41
  224. pygpt_net/plugin/cmd_web/websearch.py +74 -33
  225. pygpt_net/plugin/cmd_web/worker.py +142 -13
  226. pygpt_net/plugin/idx_llama_index/config.py +3 -3
  227. pygpt_net/plugin/mailer/__init__.py +123 -0
  228. pygpt_net/plugin/mailer/config.py +149 -0
  229. pygpt_net/plugin/mailer/runner.py +285 -0
  230. pygpt_net/plugin/mailer/worker.py +123 -0
  231. pygpt_net/provider/agents/base.py +5 -2
  232. pygpt_net/provider/agents/openai.py +4 -2
  233. pygpt_net/provider/agents/openai_assistant.py +4 -2
  234. pygpt_net/provider/agents/planner.py +4 -2
  235. pygpt_net/provider/agents/react.py +4 -2
  236. pygpt_net/provider/audio_output/openai_tts.py +5 -11
  237. pygpt_net/provider/core/assistant/base.py +5 -3
  238. pygpt_net/provider/core/assistant/json_file.py +8 -5
  239. pygpt_net/provider/core/assistant_file/base.py +4 -3
  240. pygpt_net/provider/core/assistant_file/db_sqlite/__init__.py +4 -3
  241. pygpt_net/provider/core/assistant_file/db_sqlite/storage.py +3 -2
  242. pygpt_net/provider/core/assistant_store/base.py +6 -4
  243. pygpt_net/provider/core/assistant_store/db_sqlite/__init__.py +5 -4
  244. pygpt_net/provider/core/assistant_store/db_sqlite/storage.py +5 -3
  245. pygpt_net/provider/core/attachment/base.py +5 -3
  246. pygpt_net/provider/core/attachment/json_file.py +4 -3
  247. pygpt_net/provider/core/calendar/base.py +5 -3
  248. pygpt_net/provider/core/calendar/db_sqlite/__init__.py +6 -5
  249. pygpt_net/provider/core/calendar/db_sqlite/storage.py +5 -4
  250. pygpt_net/provider/core/config/base.py +8 -6
  251. pygpt_net/provider/core/config/json_file.py +9 -7
  252. pygpt_net/provider/core/config/patch.py +43 -1
  253. pygpt_net/provider/core/ctx/base.py +30 -25
  254. pygpt_net/provider/core/ctx/db_sqlite/__init__.py +59 -34
  255. pygpt_net/provider/core/ctx/db_sqlite/storage.py +62 -30
  256. pygpt_net/provider/core/ctx/db_sqlite/utils.py +11 -9
  257. pygpt_net/provider/core/index/base.py +129 -23
  258. pygpt_net/provider/core/index/db_sqlite/__init__.py +130 -23
  259. pygpt_net/provider/core/index/db_sqlite/storage.py +130 -23
  260. pygpt_net/provider/core/index/db_sqlite/utils.py +4 -2
  261. pygpt_net/provider/core/mode/base.py +5 -3
  262. pygpt_net/provider/core/mode/json_file.py +7 -6
  263. pygpt_net/provider/core/model/base.py +6 -4
  264. pygpt_net/provider/core/model/json_file.py +9 -7
  265. pygpt_net/provider/core/notepad/base.py +5 -3
  266. pygpt_net/provider/core/notepad/db_sqlite/__init__.py +5 -4
  267. pygpt_net/provider/core/notepad/db_sqlite/storage.py +4 -3
  268. pygpt_net/provider/core/plugin_preset/base.py +4 -2
  269. pygpt_net/provider/core/plugin_preset/json_file.py +5 -3
  270. pygpt_net/provider/core/preset/base.py +6 -4
  271. pygpt_net/provider/core/preset/json_file.py +9 -9
  272. pygpt_net/provider/core/prompt/base.py +6 -3
  273. pygpt_net/provider/core/prompt/json_file.py +11 -6
  274. pygpt_net/provider/gpt/assistants.py +21 -11
  275. pygpt_net/provider/gpt/audio.py +6 -5
  276. pygpt_net/provider/gpt/chat.py +10 -7
  277. pygpt_net/provider/gpt/completion.py +11 -5
  278. pygpt_net/provider/gpt/image.py +9 -2
  279. pygpt_net/provider/gpt/store.py +53 -18
  280. pygpt_net/provider/gpt/vision.py +17 -11
  281. pygpt_net/provider/llms/anthropic.py +7 -2
  282. pygpt_net/provider/llms/azure_openai.py +26 -5
  283. pygpt_net/provider/llms/base.py +47 -9
  284. pygpt_net/provider/llms/google.py +7 -2
  285. pygpt_net/provider/llms/hugging_face.py +13 -3
  286. pygpt_net/provider/llms/hugging_face_api.py +18 -4
  287. pygpt_net/provider/llms/local.py +7 -2
  288. pygpt_net/provider/llms/ollama.py +30 -6
  289. pygpt_net/provider/llms/openai.py +32 -6
  290. pygpt_net/provider/vector_stores/__init__.py +45 -14
  291. pygpt_net/provider/vector_stores/base.py +35 -8
  292. pygpt_net/provider/vector_stores/chroma.py +13 -3
  293. pygpt_net/provider/vector_stores/ctx_attachment.py +31 -12
  294. pygpt_net/provider/vector_stores/elasticsearch.py +12 -3
  295. pygpt_net/provider/vector_stores/pinecode.py +12 -3
  296. pygpt_net/provider/vector_stores/redis.py +12 -3
  297. pygpt_net/provider/vector_stores/simple.py +12 -3
  298. pygpt_net/provider/vector_stores/temp.py +16 -4
  299. pygpt_net/provider/web/base.py +10 -3
  300. pygpt_net/provider/web/google_custom_search.py +9 -3
  301. pygpt_net/provider/web/microsoft_bing.py +9 -3
  302. pygpt_net/tools/__init__.py +20 -4
  303. pygpt_net/tools/audio_transcriber/__init__.py +4 -3
  304. pygpt_net/tools/base.py +28 -7
  305. pygpt_net/tools/code_interpreter/__init__.py +177 -77
  306. pygpt_net/tools/code_interpreter/ui/dialogs.py +21 -103
  307. pygpt_net/tools/code_interpreter/ui/widgets.py +284 -9
  308. pygpt_net/tools/html_canvas/__init__.py +81 -25
  309. pygpt_net/tools/html_canvas/ui/dialogs.py +46 -62
  310. pygpt_net/tools/html_canvas/ui/widgets.py +96 -3
  311. pygpt_net/tools/image_viewer/__init__.py +10 -4
  312. pygpt_net/tools/indexer/__init__.py +8 -7
  313. pygpt_net/tools/media_player/__init__.py +4 -3
  314. pygpt_net/tools/text_editor/__init__.py +36 -10
  315. pygpt_net/ui/base/context_menu.py +2 -2
  316. pygpt_net/ui/layout/chat/input.py +10 -18
  317. pygpt_net/ui/layout/chat/output.py +27 -45
  318. pygpt_net/ui/layout/ctx/ctx_list.py +13 -4
  319. pygpt_net/ui/layout/toolbox/footer.py +18 -2
  320. pygpt_net/ui/main.py +2 -2
  321. pygpt_net/ui/menu/audio.py +12 -1
  322. pygpt_net/ui/menu/config.py +7 -11
  323. pygpt_net/ui/menu/debug.py +11 -1
  324. pygpt_net/ui/menu/theme.py +9 -2
  325. pygpt_net/ui/widget/filesystem/explorer.py +2 -2
  326. pygpt_net/ui/widget/lists/context.py +27 -5
  327. pygpt_net/ui/widget/tabs/Input.py +2 -2
  328. pygpt_net/ui/widget/tabs/body.py +2 -1
  329. pygpt_net/ui/widget/tabs/layout.py +195 -0
  330. pygpt_net/ui/widget/tabs/output.py +218 -55
  331. pygpt_net/ui/widget/textarea/html.py +11 -1
  332. pygpt_net/ui/widget/textarea/output.py +10 -1
  333. pygpt_net/ui/widget/textarea/search_input.py +4 -1
  334. pygpt_net/ui/widget/textarea/web.py +49 -9
  335. {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.42.dist-info}/METADATA +177 -183
  336. {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.42.dist-info}/RECORD +340 -325
  337. /pygpt_net/data/css/{web.dark.css → web-blocks.dark.css} +0 -0
  338. {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.42.dist-info}/LICENSE +0 -0
  339. {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.42.dist-info}/WHEEL +0 -0
  340. {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.42.dist-info}/entry_points.txt +0 -0
@@ -6,12 +6,13 @@
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.14 08:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import copy
13
13
  import datetime
14
14
  import uuid
15
+ from typing import Optional, Tuple, List, Dict
15
16
 
16
17
  from packaging.version import Version
17
18
 
@@ -97,104 +98,250 @@ class Ctx:
97
98
  self.current_sys_prompt = ""
98
99
  self.groups_loaded = False
99
100
 
100
- def get_items(self):
101
- # print(self.container.count_items())
101
+ def get_items(self) -> List[CtxItem]:
102
+ """
103
+ Get context items
104
+
105
+ :return: context items
106
+ """
102
107
  return self.container.get_items()
103
108
 
104
- def set_items(self, items):
109
+ def set_items(self, items: List[CtxItem]):
110
+ """
111
+ Set context items
112
+
113
+ :param items: context items
114
+ """
105
115
  self.container.set_items(items)
106
116
 
107
117
  def clear_items(self):
118
+ """Clear context items"""
108
119
  self.container.clear_items()
109
120
 
110
- def count_items(self):
121
+ def count_items(self) -> int:
122
+ """
123
+ Count context items
124
+ :return: context items count
125
+ """
111
126
  return self.container.count_items()
112
127
 
113
- def get_current(self):
128
+ def get_current(self) -> int:
129
+ """
130
+ Get current context ID
131
+
132
+ :return: current context ID
133
+ """
114
134
  return self.current
115
135
 
116
- def set_current(self, current):
136
+ def set_current(self, current: int):
137
+ """
138
+ Set current context ID
139
+
140
+ :param current: current context ID
141
+ """
117
142
  self.current = current
118
143
 
119
144
  def clear_current(self):
145
+ """Clear current context ID"""
120
146
  self.current = None
121
147
 
122
- def get_last_item(self):
148
+ def get_last_item(self) -> Optional[CtxItem]:
149
+ """
150
+ Get last item
151
+
152
+ :return: last item
153
+ """
123
154
  return self.last_item
124
155
 
125
- def set_last_item(self, last_item):
156
+ def set_last_item(self, last_item: Optional[CtxItem]):
157
+ """
158
+ Set last item
159
+
160
+ :param last_item: last item
161
+ """
126
162
  self.last_item = last_item
127
163
 
128
- def get_assistant(self):
164
+ def get_assistant(self) -> str:
165
+ """
166
+ Get assistant name
167
+
168
+ :return: assistant name
169
+ """
129
170
  return self.assistant
130
171
 
131
- def set_assistant(self, assistant):
172
+ def set_assistant(self, assistant: str):
173
+ """
174
+ Set assistant name
175
+
176
+ :param assistant: assistant name
177
+ :return: assistant name
178
+ """
132
179
  self.assistant = assistant
133
180
 
134
- def get_mode(self):
181
+ def get_mode(self) -> str:
182
+ """
183
+ Get mode
184
+
185
+ :return: mode
186
+ """
135
187
  return self.mode
136
188
 
137
- def set_mode(self, mode):
189
+ def set_mode(self, mode: str):
190
+ """
191
+ Set mode
192
+
193
+ :param mode: mode
194
+ """
138
195
  self.mode = mode
139
196
 
140
- def get_model(self):
197
+ def get_model(self) -> str:
198
+ """
199
+ Get model name
200
+ :return: model name
201
+ """
141
202
  return self.model
142
203
 
143
- def set_model(self, model):
204
+ def set_model(self, model: str):
205
+ """
206
+ Set model name
207
+
208
+ :param model: model name
209
+ """
144
210
  self.model = model
145
211
 
146
- def get_preset(self):
212
+ def get_preset(self) -> str:
213
+ """
214
+ Get preset name
215
+ :return: preset
216
+ """
147
217
  return self.preset
148
218
 
149
- def set_preset(self, preset):
219
+ def set_preset(self, preset: str):
220
+ """
221
+ Set preset name
222
+
223
+ :param preset: preset name
224
+ """
150
225
  self.preset = preset
151
226
 
152
- def get_run(self):
227
+ def get_run(self) -> str:
228
+ """
229
+ Get run ID
230
+
231
+ :return: run ID
232
+ """
153
233
  return self.run
154
234
 
155
- def set_status(self, status):
235
+ def set_status(self, status: int):
236
+ """
237
+ Set status (label color)
238
+
239
+ :param status: status
240
+ """
156
241
  self.status = status
157
242
 
158
- def get_status(self):
243
+ def get_status(self) -> int:
244
+ """
245
+ Get status (label color)
246
+
247
+ :return: status
248
+ """
159
249
  return self.status
160
250
 
161
- def set_run(self, run):
251
+ def set_run(self, run: str):
252
+ """
253
+ Set run ID
254
+
255
+ :param run: run ID
256
+ """
162
257
  self.preset = run
163
258
 
164
- def get_thread(self):
259
+ def get_thread(self) -> str:
260
+ """
261
+ Get thread ID
262
+
263
+ :return: thread ID
264
+ """
165
265
  return self.thread
166
266
 
167
- def set_thread(self, thread):
267
+ def set_thread(self, thread: str):
268
+ """
269
+ Set thread ID
270
+
271
+ :param thread: thread ID
272
+ """
168
273
  self.thread = thread
169
274
 
170
275
  def clear_thread(self):
276
+ """Clear thread ID"""
171
277
  self.thread = None
172
278
 
173
- def get_last_mode(self):
279
+ def get_last_mode(self) -> str:
280
+ """
281
+ Get last mode
282
+
283
+ :return: last mode
284
+ """
174
285
  return self.last_mode
175
286
 
176
- def set_last_mode(self, last_mode):
287
+ def set_last_mode(self, last_mode: str):
288
+ """
289
+ Set last mode
290
+
291
+ :param last_mode: last mode
292
+ """
177
293
  self.last_mode = last_mode
178
294
 
179
- def get_last_model(self):
295
+ def get_last_model(self) -> str:
296
+ """
297
+ Get last model name
298
+
299
+ :return: last model
300
+ """
180
301
  return self.last_model
181
302
 
182
- def set_last_model(self, last_model):
303
+ def set_last_model(self, last_model: str):
304
+ """
305
+ Set last model name
306
+
307
+ :param last_model: last model name
308
+ """
183
309
  self.last_model = last_model
184
310
 
185
- def get_tmp_meta(self):
311
+ def get_tmp_meta(self) -> Optional[CtxMeta]:
312
+ """
313
+ Get temporary meta
314
+
315
+ :return: temporary meta
316
+ """
186
317
  return self.tmp_meta
187
318
 
188
- def set_tmp_meta(self, tmp_meta):
319
+ def set_tmp_meta(self, tmp_meta: Optional[CtxMeta]):
320
+ """
321
+ Set temporary meta
322
+
323
+ :param tmp_meta: temporary meta
324
+ """
189
325
  self.tmp_meta = tmp_meta
190
326
 
191
- def get_search_string(self):
327
+ def get_search_string(self) -> Optional[str]:
328
+ """
329
+ Get search string
330
+
331
+ :return: search string
332
+ """
192
333
  return self.search_string
193
334
 
194
- def set_search_string(self, search_string):
335
+ def set_search_string(self, search_string: Optional[str]):
336
+ """
337
+ Set search string
338
+
339
+ :param search_string: search string
340
+ """
195
341
  self.search_string = search_string
196
342
 
197
343
  def clear_search_string(self):
344
+ """Clear search string"""
198
345
  self.search_string = None
199
346
 
200
347
  def install(self):
@@ -218,7 +365,11 @@ class Ctx:
218
365
  """
219
366
  return self.provider
220
367
 
221
- def select(self, id: int, restore_model: bool = True):
368
+ def select(
369
+ self,
370
+ id: int,
371
+ restore_model: bool = True
372
+ ):
222
373
  """
223
374
  Select ctx meta by ID and load ctx items
224
375
 
@@ -254,7 +405,10 @@ class Ctx:
254
405
 
255
406
  self.set_items(self.load(id))
256
407
 
257
- def new(self, group_id: int = None) -> CtxMeta or None:
408
+ def new(
409
+ self,
410
+ group_id: Optional[int] = None
411
+ ) -> Optional[CtxMeta]:
258
412
  """
259
413
  Create new ctx and set as current
260
414
 
@@ -294,7 +448,10 @@ class Ctx:
294
448
  meta.initialized = False
295
449
  return meta
296
450
 
297
- def create(self, group_id: int = None) -> CtxMeta:
451
+ def create(
452
+ self,
453
+ group_id: Optional[int] = None
454
+ ) -> CtxMeta:
298
455
  """
299
456
  Send created meta to provider and return new ID
300
457
 
@@ -308,7 +465,11 @@ class Ctx:
308
465
  meta.id = id
309
466
  return meta
310
467
 
311
- def add(self, item: CtxItem, parent_id: int = None):
468
+ def add(
469
+ self,
470
+ item: CtxItem,
471
+ parent_id: Optional[int] = None
472
+ ):
312
473
  """
313
474
  Add CtxItem to contexts and saves context
314
475
 
@@ -333,7 +494,11 @@ class Ctx:
333
494
  if not result:
334
495
  self.store() # if not stored, e.g. in JSON file provider, then store whole ctx (save all)
335
496
 
336
- def add_to_meta(self, item: CtxItem, meta_id: int = None):
497
+ def add_to_meta(
498
+ self,
499
+ item: CtxItem,
500
+ meta_id: Optional[int] = None
501
+ ):
337
502
  """
338
503
  Add CtxItem to custom meta
339
504
 
@@ -490,6 +655,16 @@ class Ctx:
490
655
  for item in self.get_items():
491
656
  if item.id == id:
492
657
  return item
658
+ return self.fetch_item_by_id(id) # if no item found, try to fetch from DB
659
+
660
+ def fetch_item_by_id(self, id: int) -> CtxItem:
661
+ """
662
+ Fetch ctx item by id
663
+
664
+ :param id: item id
665
+ :return: context item
666
+ """
667
+ return self.provider.get_item_by_id(id)
493
668
 
494
669
  def get_meta(self, reload: bool = False) -> dict:
495
670
  """
@@ -502,7 +677,7 @@ class Ctx:
502
677
  self.load_meta()
503
678
  return self.meta
504
679
 
505
- def get_current_meta(self) -> CtxMeta or None:
680
+ def get_current_meta(self) -> Optional[CtxMeta]:
506
681
  """
507
682
  Get current meta
508
683
 
@@ -555,7 +730,7 @@ class Ctx:
555
730
  if id in self.meta:
556
731
  return self.meta[id]
557
732
 
558
- def get_last(self) -> CtxItem or None:
733
+ def get_last(self) -> Optional[CtxItem]:
559
734
  """
560
735
  Return last item from ctx
561
736
 
@@ -587,7 +762,7 @@ class Ctx:
587
762
  return self.get_items()[-1].id == item_id
588
763
  return False
589
764
 
590
- def get_previous_item(self, item_id: int) -> CtxItem or None:
765
+ def get_previous_item(self, item_id: int) -> Optional[CtxItem]:
591
766
  """
592
767
  Get previous item from ctx
593
768
 
@@ -633,7 +808,10 @@ class Ctx:
633
808
  """
634
809
  return len(self.meta)
635
810
 
636
- def all(self, meta_id: int = None) -> list:
811
+ def all(
812
+ self,
813
+ meta_id: Optional[int] = None
814
+ ) -> List[CtxItem]:
637
815
  """
638
816
  Return ctx items (current or by meta_id if provided)
639
817
 
@@ -667,7 +845,11 @@ class Ctx:
667
845
  self.provider.remove_item(id)
668
846
  break
669
847
 
670
- def remove_items_from(self, meta_id: int, item_id: int):
848
+ def remove_items_from(
849
+ self,
850
+ meta_id: int,
851
+ item_id: int
852
+ ):
671
853
  """
672
854
  Remove ctx items from meta_id
673
855
 
@@ -731,7 +913,11 @@ class Ctx:
731
913
  self.meta[self.current].status = self.status
732
914
  self.save(self.current)
733
915
 
734
- def get_or_create_slave_meta(self, master_ctx: CtxItem, preset_id: str) -> CtxMeta:
916
+ def get_or_create_slave_meta(
917
+ self,
918
+ master_ctx: CtxItem,
919
+ preset_id: str
920
+ ) -> CtxMeta:
735
921
  """
736
922
  Get or create slave meta
737
923
 
@@ -758,7 +944,7 @@ class Ctx:
758
944
  slave.id = id
759
945
  return slave
760
946
 
761
- def get_prev(self) -> int or None:
947
+ def get_prev(self) -> Optional[int]:
762
948
  """
763
949
  Get previous context
764
950
 
@@ -771,7 +957,7 @@ class Ctx:
771
957
  if idx > 0:
772
958
  return self.get_id_by_idx(idx - 1)
773
959
 
774
- def get_next(self) -> int or None:
960
+ def get_next(self) -> Optional[int]:
775
961
  """
776
962
  Get next context
777
963
 
@@ -784,7 +970,7 @@ class Ctx:
784
970
  if idx < self.count_meta() - 1:
785
971
  return self.get_id_by_idx(idx + 1)
786
972
 
787
- def get_last_meta(self) -> int or None:
973
+ def get_last_meta(self) -> Optional[int]:
788
974
  """
789
975
  Get last context
790
976
 
@@ -794,12 +980,12 @@ class Ctx:
794
980
 
795
981
  def count_history(
796
982
  self,
797
- history_items: list,
983
+ history_items: List[CtxItem],
798
984
  model: str,
799
985
  mode: str,
800
986
  used_tokens: int = 100,
801
987
  max_tokens: int = 1000
802
- ) -> (int, int):
988
+ ) -> Tuple[int, int]:
803
989
  """
804
990
  Count ctx items to add to prompt
805
991
 
@@ -826,7 +1012,7 @@ class Ctx:
826
1012
 
827
1013
  def get_history(
828
1014
  self,
829
- history_items: list,
1015
+ history_items: List[CtxItem],
830
1016
  model: str,
831
1017
  mode: str = MODE_CHAT,
832
1018
  used_tokens: int = 100,
@@ -867,7 +1053,7 @@ class Ctx:
867
1053
  mode: str,
868
1054
  used_tokens: int = 100,
869
1055
  max_tokens: int = 1000
870
- ) -> (int, int):
1056
+ ) -> Tuple[int, int]:
871
1057
  """
872
1058
  Count ctx items to add to prompt
873
1059
 
@@ -1007,7 +1193,11 @@ class Ctx:
1007
1193
  """
1008
1194
  self.filters = filters
1009
1195
 
1010
- def is_allowed_for_mode(self, mode: str, check_assistant: bool = True) -> bool:
1196
+ def is_allowed_for_mode(
1197
+ self,
1198
+ mode: str,
1199
+ check_assistant: bool = True
1200
+ ) -> bool:
1011
1201
  """
1012
1202
  Check if ctx is allowed for this mode
1013
1203
 
@@ -1159,7 +1349,7 @@ class Ctx:
1159
1349
  }
1160
1350
  return filters
1161
1351
 
1162
- def load(self, id: int) -> list:
1352
+ def load(self, id: int) -> List[CtxItem]:
1163
1353
  """
1164
1354
  Load ctx items from provider and append meta to each item
1165
1355
 
@@ -1187,7 +1377,7 @@ class Ctx:
1187
1377
  return True
1188
1378
  return False
1189
1379
 
1190
- def get_groups(self) -> dict:
1380
+ def get_groups(self) -> Dict[int, CtxGroup]:
1191
1381
  """
1192
1382
  Get groups
1193
1383
 
@@ -1198,7 +1388,7 @@ class Ctx:
1198
1388
  self.groups_loaded = True
1199
1389
  return self.groups
1200
1390
 
1201
- def get_group_by_id(self, id: int) -> CtxGroup or None:
1391
+ def get_group_by_id(self, id: int) -> Optional[CtxGroup]:
1202
1392
  """
1203
1393
  Get group by ID
1204
1394
 
@@ -1212,7 +1402,11 @@ class Ctx:
1212
1402
  return None
1213
1403
  return self.groups[id]
1214
1404
 
1215
- def remove_group(self, group: CtxGroup, all: bool = False):
1405
+ def remove_group(
1406
+ self,
1407
+ group: CtxGroup,
1408
+ all: bool = False
1409
+ ):
1216
1410
  """
1217
1411
  Remove group
1218
1412
 
@@ -1273,9 +1467,9 @@ class Ctx:
1273
1467
  self.provider.update_meta_group_id(id, group_id)
1274
1468
  self.load_groups()
1275
1469
 
1276
- def get_items_by_id(self, id: int) -> list:
1470
+ def get_items_by_id(self, id: int) -> List[str]:
1277
1471
  """
1278
- Get ctx items by id
1472
+ Get ctx items by id as string list
1279
1473
 
1280
1474
  :param id: ctx id
1281
1475
  :return: ctx items list
@@ -1287,7 +1481,11 @@ class Ctx:
1287
1481
  data.append("Human: " + str(item.input) + "\n" + "Assistant: " + str(item.output) + "\n")
1288
1482
  return data
1289
1483
 
1290
- def get_list_in_date_range(self, search_string, limit: int = 0) -> list:
1484
+ def get_list_in_date_range(
1485
+ self,
1486
+ search_string: Optional[str] = None,
1487
+ limit: int = 0
1488
+ ) -> List[Dict[str, Dict]]:
1291
1489
  """
1292
1490
  Get ctx list in date range
1293
1491
 
@@ -1361,10 +1559,13 @@ class Ctx:
1361
1559
  """
1362
1560
  prev_ctx = CtxItem()
1363
1561
  prev_ctx.urls = copy.deepcopy(ctx.urls)
1562
+ prev_ctx.urls_before = copy.deepcopy(ctx.urls_before)
1364
1563
  prev_ctx.images = copy.deepcopy(ctx.images)
1365
1564
  prev_ctx.images_before = copy.deepcopy(ctx.images_before)
1366
1565
  prev_ctx.files = copy.deepcopy(ctx.files)
1566
+ prev_ctx.files_before = copy.deepcopy(ctx.files_before)
1367
1567
  prev_ctx.attachments = copy.deepcopy(ctx.attachments)
1568
+ prev_ctx.attachments_before = copy.deepcopy(ctx.attachments_before)
1368
1569
  prev_ctx.results = copy.deepcopy(ctx.results)
1369
1570
  prev_ctx.index_meta = copy.deepcopy(ctx.index_meta)
1370
1571
  prev_ctx.doc_ids = copy.deepcopy(ctx.doc_ids)
@@ -1372,7 +1573,8 @@ class Ctx:
1372
1573
  prev_ctx.output_name = copy.deepcopy(ctx.output_name)
1373
1574
 
1374
1575
  ctx.clear_reply() # clear current reply result
1375
- ctx.from_previous() # get result from previous if exists
1576
+ if len(ctx.cmds) == 0:
1577
+ ctx.from_previous() # get result from previous if exists
1376
1578
  return prev_ctx
1377
1579
 
1378
1580
  def dump(self, ctx: CtxItem) -> str:
pygpt_net/core/ctx/bag.py CHANGED
@@ -6,9 +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.11.05 23:00:00 #
9
+ # Updated Date: 2024.12.14 08:00:00 #
10
10
  # ================================================== #
11
11
 
12
+ from typing import List
13
+
14
+ from pygpt_net.item.ctx import CtxItem
15
+
16
+
12
17
  class Bag:
13
18
  def __init__(self, window=None):
14
19
  """
@@ -19,14 +24,30 @@ class Bag:
19
24
  self.tab_id = 0
20
25
  self.items = []
21
26
 
22
- def get_items(self):
27
+ def get_items(self) -> List[CtxItem]:
28
+ """
29
+ Return ctx items
30
+
31
+ :return: ctx items
32
+ """
23
33
  return self.items
24
34
 
25
- def set_items(self, items):
35
+ def set_items(self, items: List[CtxItem]):
36
+ """
37
+ Set ctx items
38
+
39
+ :param items: ctx items
40
+ """
26
41
  self.items = items
27
42
 
28
43
  def clear_items(self):
44
+ """Clear items"""
29
45
  self.items = []
30
46
 
31
- def count_items(self):
47
+ def count_items(self) -> int:
48
+ """
49
+ Count ctx items
50
+
51
+ :return: items count
52
+ """
32
53
  return len(self.items)