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.
- CHANGELOG.md +37 -0
- README.md +176 -182
- pygpt_net/CHANGELOG.txt +37 -0
- pygpt_net/__init__.py +3 -3
- pygpt_net/app.py +3 -1
- pygpt_net/controller/__init__.py +7 -3
- pygpt_net/controller/access/control.py +1 -1
- pygpt_net/controller/access/voice.py +11 -5
- pygpt_net/controller/agent/experts.py +11 -6
- pygpt_net/controller/agent/legacy.py +8 -6
- pygpt_net/controller/agent/llama.py +4 -2
- pygpt_net/controller/assistant/__init__.py +9 -4
- pygpt_net/controller/assistant/batch.py +38 -21
- pygpt_net/controller/assistant/editor.py +7 -6
- pygpt_net/controller/assistant/files.py +23 -7
- pygpt_net/controller/assistant/store.py +20 -7
- pygpt_net/controller/assistant/threads.py +34 -8
- pygpt_net/controller/attachment.py +29 -10
- pygpt_net/controller/audio/__init__.py +26 -5
- pygpt_net/controller/calendar/__init__.py +23 -4
- pygpt_net/controller/calendar/note.py +57 -11
- pygpt_net/controller/camera.py +4 -12
- pygpt_net/controller/chat/__init__.py +5 -3
- pygpt_net/controller/chat/attachment.py +34 -7
- pygpt_net/controller/chat/audio.py +2 -2
- pygpt_net/controller/chat/command.py +4 -2
- pygpt_net/controller/chat/common.py +11 -4
- pygpt_net/controller/chat/files.py +10 -3
- pygpt_net/controller/chat/image.py +17 -5
- pygpt_net/controller/chat/input.py +10 -7
- pygpt_net/controller/chat/output.py +21 -6
- pygpt_net/controller/chat/render.py +100 -21
- pygpt_net/controller/chat/response.py +34 -7
- pygpt_net/controller/chat/stream.py +4 -2
- pygpt_net/controller/chat/text.py +6 -4
- pygpt_net/controller/command.py +11 -3
- pygpt_net/controller/config/__init__.py +34 -6
- pygpt_net/controller/config/field/checkbox.py +7 -4
- pygpt_net/controller/config/field/cmd.py +7 -5
- pygpt_net/controller/config/field/combo.py +14 -6
- pygpt_net/controller/config/field/dictionary.py +14 -11
- pygpt_net/controller/config/field/input.py +9 -6
- pygpt_net/controller/config/field/slider.py +11 -8
- pygpt_net/controller/config/field/textarea.py +8 -5
- pygpt_net/controller/config/placeholder.py +66 -21
- pygpt_net/controller/ctx/__init__.py +138 -49
- pygpt_net/controller/ctx/common.py +15 -4
- pygpt_net/controller/ctx/extra.py +11 -3
- pygpt_net/controller/ctx/summarizer.py +24 -5
- pygpt_net/controller/debug/__init__.py +27 -6
- pygpt_net/controller/dialogs/confirm.py +34 -7
- pygpt_net/controller/dialogs/debug.py +4 -2
- pygpt_net/controller/dialogs/info.py +7 -2
- pygpt_net/controller/files.py +48 -10
- pygpt_net/controller/finder.py +11 -5
- pygpt_net/controller/idx/__init__.py +10 -3
- pygpt_net/controller/idx/common.py +4 -2
- pygpt_net/controller/idx/indexer.py +25 -17
- pygpt_net/controller/idx/settings.py +9 -3
- pygpt_net/controller/kernel/__init__.py +34 -8
- pygpt_net/controller/kernel/reply.py +12 -3
- pygpt_net/controller/kernel/stack.py +5 -3
- pygpt_net/controller/lang/custom.py +2 -7
- pygpt_net/controller/lang/mapping.py +5 -3
- pygpt_net/controller/layout.py +2 -2
- pygpt_net/controller/mode.py +16 -4
- pygpt_net/controller/model/__init__.py +14 -3
- pygpt_net/controller/model/editor.py +8 -3
- pygpt_net/controller/notepad.py +26 -12
- pygpt_net/controller/painter/capture.py +23 -4
- pygpt_net/controller/painter/common.py +9 -7
- pygpt_net/controller/plugins/__init__.py +19 -5
- pygpt_net/controller/plugins/presets.py +15 -6
- pygpt_net/controller/plugins/settings.py +9 -3
- pygpt_net/controller/presets/__init__.py +55 -16
- pygpt_net/controller/presets/editor.py +26 -10
- pygpt_net/controller/settings/__init__.py +3 -2
- pygpt_net/controller/settings/editor.py +29 -7
- pygpt_net/controller/settings/profile.py +22 -5
- pygpt_net/controller/theme/__init__.py +54 -12
- pygpt_net/controller/theme/common.py +24 -2
- pygpt_net/controller/theme/markdown.py +32 -16
- pygpt_net/controller/theme/menu.py +26 -5
- pygpt_net/controller/theme/nodes.py +2 -5
- pygpt_net/controller/tools/__init__.py +40 -2
- pygpt_net/controller/ui/__init__.py +4 -6
- pygpt_net/controller/ui/mode.py +16 -21
- pygpt_net/controller/ui/tabs.py +363 -65
- pygpt_net/core/access/actions.py +6 -4
- pygpt_net/core/access/shortcuts.py +4 -3
- pygpt_net/core/access/voice.py +6 -5
- pygpt_net/core/agents/legacy.py +4 -2
- pygpt_net/core/agents/memory.py +7 -2
- pygpt_net/core/agents/observer/evaluation.py +15 -7
- pygpt_net/core/agents/provider.py +9 -4
- pygpt_net/core/agents/runner.py +61 -15
- pygpt_net/core/agents/tools.py +23 -5
- pygpt_net/core/assistants/__init__.py +6 -4
- pygpt_net/core/assistants/files.py +35 -12
- pygpt_net/core/assistants/store.py +20 -10
- pygpt_net/core/attachments/__init__.py +54 -15
- pygpt_net/core/attachments/context.py +92 -29
- pygpt_net/core/audio/__init__.py +74 -3
- pygpt_net/core/audio/context.py +7 -2
- pygpt_net/core/audio/whisper.py +37 -0
- pygpt_net/core/bridge/__init__.py +22 -6
- pygpt_net/core/bridge/context.py +5 -3
- pygpt_net/core/bridge/worker.py +2 -2
- pygpt_net/core/calendar/__init__.py +57 -11
- pygpt_net/core/chain/__init__.py +8 -2
- pygpt_net/core/chain/chat.py +10 -8
- pygpt_net/core/chain/completion.py +10 -7
- pygpt_net/core/command.py +62 -17
- pygpt_net/core/ctx/__init__.py +260 -58
- pygpt_net/core/ctx/bag.py +25 -4
- pygpt_net/core/ctx/container.py +28 -17
- pygpt_net/core/ctx/idx.py +45 -8
- pygpt_net/core/ctx/output.py +95 -74
- pygpt_net/core/ctx/reply.py +5 -2
- pygpt_net/core/db/__init__.py +8 -7
- pygpt_net/core/db/viewer.py +17 -11
- pygpt_net/core/debug/__init__.py +10 -9
- pygpt_net/core/debug/events.py +22 -10
- pygpt_net/core/debug/tabs.py +9 -3
- pygpt_net/core/docker/__init__.py +11 -5
- pygpt_net/core/docker/builder.py +11 -3
- pygpt_net/core/events/app.py +5 -3
- pygpt_net/core/events/base.py +11 -5
- pygpt_net/core/events/control.py +5 -3
- pygpt_net/core/events/event.py +17 -7
- pygpt_net/core/events/kernel.py +5 -3
- pygpt_net/core/events/render.py +5 -3
- pygpt_net/core/experts/__init__.py +5 -4
- pygpt_net/core/filesystem/__init__.py +52 -34
- pygpt_net/core/filesystem/actions.py +8 -5
- pygpt_net/core/filesystem/editor.py +13 -3
- pygpt_net/core/filesystem/types.py +12 -7
- pygpt_net/core/filesystem/url.py +7 -3
- pygpt_net/core/history.py +3 -2
- pygpt_net/core/idx/__init__.py +48 -27
- pygpt_net/core/idx/chat.py +51 -17
- pygpt_net/core/idx/context.py +6 -2
- pygpt_net/core/idx/indexing.py +107 -42
- pygpt_net/core/idx/llm.py +11 -3
- pygpt_net/core/idx/metadata.py +13 -3
- pygpt_net/core/idx/types/ctx.py +32 -6
- pygpt_net/core/idx/types/external.py +41 -7
- pygpt_net/core/idx/types/files.py +31 -6
- pygpt_net/core/image.py +15 -4
- pygpt_net/core/installer.py +2 -4
- pygpt_net/core/llm/__init__.py +13 -3
- pygpt_net/core/locale.py +34 -8
- pygpt_net/core/models.py +63 -17
- pygpt_net/core/modes.py +11 -13
- pygpt_net/core/notepad.py +10 -5
- pygpt_net/core/plugins.py +31 -19
- pygpt_net/core/presets.py +37 -17
- pygpt_net/core/profile.py +21 -7
- pygpt_net/core/prompt/__init__.py +10 -3
- pygpt_net/core/prompt/custom.py +7 -6
- pygpt_net/core/prompt/template.py +9 -3
- pygpt_net/core/render/base.py +117 -22
- pygpt_net/core/render/markdown/body.py +27 -7
- pygpt_net/core/render/markdown/renderer.py +119 -22
- pygpt_net/core/render/plain/body.py +22 -5
- pygpt_net/core/render/plain/renderer.py +97 -21
- pygpt_net/core/render/web/body.py +75 -25
- pygpt_net/core/render/web/parser.py +3 -1
- pygpt_net/core/render/web/renderer.py +313 -63
- pygpt_net/core/settings.py +10 -5
- pygpt_net/core/tabs/__init__.py +290 -103
- pygpt_net/core/tabs/tab.py +26 -5
- pygpt_net/core/tokens.py +47 -12
- pygpt_net/core/updater/__init__.py +20 -7
- pygpt_net/core/vision/analyzer.py +29 -6
- pygpt_net/core/{web.py → web/__init__.py} +29 -7
- pygpt_net/core/web/helpers.py +237 -0
- pygpt_net/data/config/config.json +15 -4
- pygpt_net/data/config/models.json +3 -3
- pygpt_net/data/config/modes.json +3 -3
- pygpt_net/data/config/settings.json +55 -10
- pygpt_net/data/config/settings_section.json +3 -0
- pygpt_net/data/css/style.light.css +1 -0
- pygpt_net/data/css/{web.css → web-blocks.css} +162 -133
- pygpt_net/data/css/{web.light.css → web-blocks.light.css} +7 -0
- pygpt_net/data/css/web-chatgpt.css +350 -0
- pygpt_net/data/css/web-chatgpt.dark.css +64 -0
- pygpt_net/data/css/web-chatgpt.light.css +75 -0
- pygpt_net/data/css/web-chatgpt_wide.css +350 -0
- pygpt_net/data/css/web-chatgpt_wide.dark.css +64 -0
- pygpt_net/data/css/web-chatgpt_wide.light.css +75 -0
- pygpt_net/data/icons/split_screen.svg +1 -0
- pygpt_net/data/locale/locale.de.ini +12 -0
- pygpt_net/data/locale/locale.en.ini +18 -2
- pygpt_net/data/locale/locale.es.ini +12 -0
- pygpt_net/data/locale/locale.fr.ini +12 -0
- pygpt_net/data/locale/locale.it.ini +12 -0
- pygpt_net/data/locale/locale.pl.ini +12 -0
- pygpt_net/data/locale/locale.uk.ini +12 -0
- pygpt_net/data/locale/locale.zh.ini +12 -0
- pygpt_net/data/locale/plugin.cmd_web.de.ini +2 -0
- pygpt_net/data/locale/plugin.cmd_web.en.ini +22 -10
- pygpt_net/data/locale/plugin.cmd_web.es.ini +2 -0
- pygpt_net/data/locale/plugin.cmd_web.fr.ini +2 -0
- pygpt_net/data/locale/plugin.cmd_web.it.ini +2 -0
- pygpt_net/data/locale/plugin.cmd_web.pl.ini +2 -0
- pygpt_net/data/locale/plugin.cmd_web.uk.ini +2 -0
- pygpt_net/data/locale/plugin.cmd_web.zh.ini +2 -0
- pygpt_net/data/locale/plugin.mailer.en.ini +21 -0
- pygpt_net/icons.qrc +1 -0
- pygpt_net/icons_rc.py +165 -136
- pygpt_net/item/ctx.py +58 -25
- pygpt_net/plugin/agent/__init__.py +7 -2
- pygpt_net/plugin/audio_input/simple.py +21 -5
- pygpt_net/plugin/audio_output/__init__.py +9 -1
- pygpt_net/plugin/base/config.py +4 -2
- pygpt_net/plugin/base/plugin.py +75 -23
- pygpt_net/plugin/base/worker.py +42 -11
- pygpt_net/plugin/cmd_code_interpreter/__init__.py +39 -37
- pygpt_net/plugin/cmd_code_interpreter/runner.py +25 -12
- pygpt_net/plugin/cmd_history/config.py +2 -2
- pygpt_net/plugin/cmd_web/__init__.py +48 -9
- pygpt_net/plugin/cmd_web/config.py +135 -41
- pygpt_net/plugin/cmd_web/websearch.py +74 -33
- pygpt_net/plugin/cmd_web/worker.py +142 -13
- 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/config/patch.py +43 -1
- pygpt_net/provider/core/ctx/base.py +30 -25
- pygpt_net/provider/core/ctx/db_sqlite/__init__.py +59 -34
- pygpt_net/provider/core/ctx/db_sqlite/storage.py +62 -30
- 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 +21 -11
- pygpt_net/provider/gpt/audio.py +6 -5
- pygpt_net/provider/gpt/chat.py +10 -7
- pygpt_net/provider/gpt/completion.py +11 -5
- pygpt_net/provider/gpt/image.py +9 -2
- pygpt_net/provider/gpt/store.py +53 -18
- pygpt_net/provider/gpt/vision.py +17 -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 +20 -4
- pygpt_net/tools/audio_transcriber/__init__.py +4 -3
- pygpt_net/tools/base.py +28 -7
- pygpt_net/tools/code_interpreter/__init__.py +177 -77
- pygpt_net/tools/code_interpreter/ui/dialogs.py +21 -103
- pygpt_net/tools/code_interpreter/ui/widgets.py +284 -9
- pygpt_net/tools/html_canvas/__init__.py +81 -25
- pygpt_net/tools/html_canvas/ui/dialogs.py +46 -62
- pygpt_net/tools/html_canvas/ui/widgets.py +96 -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/base/context_menu.py +2 -2
- pygpt_net/ui/layout/chat/input.py +10 -18
- pygpt_net/ui/layout/chat/output.py +27 -45
- pygpt_net/ui/layout/ctx/ctx_list.py +13 -4
- pygpt_net/ui/layout/toolbox/footer.py +18 -2
- pygpt_net/ui/main.py +2 -2
- pygpt_net/ui/menu/audio.py +12 -1
- pygpt_net/ui/menu/config.py +7 -11
- pygpt_net/ui/menu/debug.py +11 -1
- pygpt_net/ui/menu/theme.py +9 -2
- pygpt_net/ui/widget/filesystem/explorer.py +2 -2
- pygpt_net/ui/widget/lists/context.py +27 -5
- pygpt_net/ui/widget/tabs/Input.py +2 -2
- pygpt_net/ui/widget/tabs/body.py +2 -1
- pygpt_net/ui/widget/tabs/layout.py +195 -0
- pygpt_net/ui/widget/tabs/output.py +218 -55
- pygpt_net/ui/widget/textarea/html.py +11 -1
- pygpt_net/ui/widget/textarea/output.py +10 -1
- pygpt_net/ui/widget/textarea/search_input.py +4 -1
- pygpt_net/ui/widget/textarea/web.py +49 -9
- {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.42.dist-info}/METADATA +177 -183
- {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.42.dist-info}/RECORD +340 -325
- /pygpt_net/data/css/{web.dark.css → web-blocks.dark.css} +0 -0
- {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.42.dist-info}/LICENSE +0 -0
- {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.42.dist-info}/WHEEL +0 -0
- {pygpt_net-2.4.37.dist-info → pygpt_net-2.4.42.dist-info}/entry_points.txt +0 -0
@@ -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.
|
9
|
+
# Updated Date: 2024.12.14 22:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
import time
|
13
|
+
from typing import List, Dict, Optional
|
13
14
|
from uuid import uuid4
|
14
15
|
from packaging.version import Version
|
15
16
|
|
@@ -29,6 +30,11 @@ class DbSqliteProvider(BaseProvider):
|
|
29
30
|
self.type = "ctx"
|
30
31
|
|
31
32
|
def attach(self, window):
|
33
|
+
"""
|
34
|
+
Attach window
|
35
|
+
|
36
|
+
:param window: Window instance
|
37
|
+
"""
|
32
38
|
self.window = window
|
33
39
|
self.storage.attach(window)
|
34
40
|
|
@@ -68,14 +74,14 @@ class DbSqliteProvider(BaseProvider):
|
|
68
74
|
|
69
75
|
def get_meta(
|
70
76
|
self,
|
71
|
-
search_string: str = None,
|
72
|
-
order_by: str = None,
|
73
|
-
order_direction: str = None,
|
74
|
-
limit: int = None,
|
75
|
-
offset: int = None,
|
76
|
-
filters: dict = None,
|
77
|
+
search_string: Optional[str] = None,
|
78
|
+
order_by: Optional[str] = None,
|
79
|
+
order_direction: Optional[str] = None,
|
80
|
+
limit: Optional[int] = None,
|
81
|
+
offset: Optional[int] = None,
|
82
|
+
filters: Optional[dict] = None,
|
77
83
|
search_content: bool = False,
|
78
|
-
) ->
|
84
|
+
) -> Dict[int, CtxMeta]:
|
79
85
|
"""
|
80
86
|
Return dict of ctx meta, TODO: add order, limit, offset, etc.
|
81
87
|
|
@@ -102,7 +108,7 @@ class DbSqliteProvider(BaseProvider):
|
|
102
108
|
search_content=search_content,
|
103
109
|
)
|
104
110
|
|
105
|
-
def get_meta_indexed(self) ->
|
111
|
+
def get_meta_indexed(self) -> Dict[int, CtxMeta]:
|
106
112
|
"""
|
107
113
|
Return dict of ctx meta indexed by ID
|
108
114
|
|
@@ -118,7 +124,16 @@ class DbSqliteProvider(BaseProvider):
|
|
118
124
|
"""
|
119
125
|
return self.storage.get_last_meta_id()
|
120
126
|
|
121
|
-
def
|
127
|
+
def get_item_by_id(self, id: int) -> Optional[CtxItem]:
|
128
|
+
"""
|
129
|
+
Get ctx item by ID
|
130
|
+
|
131
|
+
:param id: ctx item ID
|
132
|
+
:return: ctx item
|
133
|
+
"""
|
134
|
+
return self.storage.get_item_by_id(id)
|
135
|
+
|
136
|
+
def load(self, id: int) -> List[CtxItem]:
|
122
137
|
"""
|
123
138
|
Load items for ctx ID
|
124
139
|
|
@@ -128,13 +143,14 @@ class DbSqliteProvider(BaseProvider):
|
|
128
143
|
return self.storage.get_items(id)
|
129
144
|
|
130
145
|
def get_ctx_count_by_day(
|
131
|
-
self,
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
146
|
+
self,
|
147
|
+
year: int,
|
148
|
+
month: Optional[int] = None,
|
149
|
+
day: Optional[int] = None,
|
150
|
+
search_string: Optional[str] = None,
|
151
|
+
filters: Optional[dict] = None,
|
136
152
|
search_content: bool = False,
|
137
|
-
) ->
|
153
|
+
) -> Dict[str, int]:
|
138
154
|
"""
|
139
155
|
Get ctx count by day or by month if only year is provided
|
140
156
|
|
@@ -156,13 +172,14 @@ class DbSqliteProvider(BaseProvider):
|
|
156
172
|
)
|
157
173
|
|
158
174
|
def get_ctx_labels_count_by_day(
|
159
|
-
self,
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
175
|
+
self,
|
176
|
+
year: int,
|
177
|
+
month: Optional[int] = None,
|
178
|
+
day: Optional[int] = None,
|
179
|
+
search_string: Optional[str] = None,
|
180
|
+
filters: Optional[dict] = None,
|
164
181
|
search_content: bool = False,
|
165
|
-
) ->
|
182
|
+
) -> Dict[str, Dict[int, int]]:
|
166
183
|
"""
|
167
184
|
Get ctx labels count by day or by month if only year is provided
|
168
185
|
|
@@ -204,7 +221,7 @@ class DbSqliteProvider(BaseProvider):
|
|
204
221
|
self.storage.update_meta_ts(item.meta_id)
|
205
222
|
return self.storage.update_item(item) is not None
|
206
223
|
|
207
|
-
def save(self, id: int, meta: CtxMeta, items:
|
224
|
+
def save(self, id: int, meta: CtxMeta, items: List[CtxItem]) -> bool:
|
208
225
|
"""
|
209
226
|
Save ctx
|
210
227
|
|
@@ -216,7 +233,7 @@ class DbSqliteProvider(BaseProvider):
|
|
216
233
|
if self.storage.update_meta(meta):
|
217
234
|
return True # update only meta, items are appended separately
|
218
235
|
|
219
|
-
def save_all(self, id: int, meta: CtxMeta, items:
|
236
|
+
def save_all(self, id: int, meta: CtxMeta, items: List[CtxItem]) -> bool:
|
220
237
|
"""
|
221
238
|
Save ctx
|
222
239
|
|
@@ -246,7 +263,7 @@ class DbSqliteProvider(BaseProvider):
|
|
246
263
|
"""
|
247
264
|
return self.storage.delete_item_by_id(id)
|
248
265
|
|
249
|
-
def remove_items_from(self, meta_id: int, item_id: int):
|
266
|
+
def remove_items_from(self, meta_id: int, item_id: int) -> bool:
|
250
267
|
"""
|
251
268
|
Remove ctx items from meta_id
|
252
269
|
|
@@ -319,7 +336,7 @@ class DbSqliteProvider(BaseProvider):
|
|
319
336
|
"""
|
320
337
|
return self.storage.clear_meta_indexed_all()
|
321
338
|
|
322
|
-
def get_groups(self) ->
|
339
|
+
def get_groups(self) -> Dict[int, CtxGroup]:
|
323
340
|
"""
|
324
341
|
Return dict of groups
|
325
342
|
|
@@ -327,7 +344,7 @@ class DbSqliteProvider(BaseProvider):
|
|
327
344
|
"""
|
328
345
|
return self.storage.get_groups()
|
329
346
|
|
330
|
-
def get_meta_by_id(self, id: int) -> CtxMeta
|
347
|
+
def get_meta_by_id(self, id: int) -> Optional[CtxMeta]:
|
331
348
|
"""
|
332
349
|
Get meta by ID
|
333
350
|
|
@@ -344,15 +361,16 @@ class DbSqliteProvider(BaseProvider):
|
|
344
361
|
"""
|
345
362
|
return self.storage.get_meta_by_root_id_and_preset_id(root_id, preset_id)
|
346
363
|
|
347
|
-
def insert_group(self, group: CtxGroup):
|
364
|
+
def insert_group(self, group: CtxGroup) -> int:
|
348
365
|
"""
|
349
366
|
Insert group
|
350
367
|
|
351
368
|
:param group: CtxGroup
|
369
|
+
:return: group ID
|
352
370
|
"""
|
353
371
|
return self.storage.insert_group(group)
|
354
372
|
|
355
|
-
def update_group(self, group: CtxGroup):
|
373
|
+
def update_group(self, group: CtxGroup) -> bool:
|
356
374
|
"""
|
357
375
|
Update group
|
358
376
|
|
@@ -360,32 +378,39 @@ class DbSqliteProvider(BaseProvider):
|
|
360
378
|
"""
|
361
379
|
return self.storage.update_group(group)
|
362
380
|
|
363
|
-
def remove_group(self, id: int, all: bool = False):
|
381
|
+
def remove_group(self, id: int, all: bool = False) -> bool:
|
364
382
|
"""
|
365
383
|
Remove group by ID
|
366
384
|
|
367
385
|
:param id: group ID
|
368
386
|
:param all: remove items
|
387
|
+
:return: True if removed
|
369
388
|
"""
|
370
389
|
return self.storage.delete_group(id, all=all)
|
371
390
|
|
372
|
-
def truncate_groups(self):
|
373
|
-
"""
|
391
|
+
def truncate_groups(self) -> bool:
|
392
|
+
"""
|
393
|
+
Remove groups
|
394
|
+
|
395
|
+
:return: True if removed
|
396
|
+
"""
|
374
397
|
return self.storage.truncate_groups()
|
375
398
|
|
376
|
-
def update_meta_group_id(self, id: int, group_id: int):
|
399
|
+
def update_meta_group_id(self, id: int, group_id: int) -> bool:
|
377
400
|
"""
|
378
401
|
Update meta group ID
|
379
402
|
|
380
403
|
:param id: ctx ID
|
381
404
|
:param group_id: group ID
|
405
|
+
:return: True if updated
|
382
406
|
"""
|
383
407
|
return self.storage.update_meta_group_id(id, group_id)
|
384
408
|
|
385
|
-
def clear_meta(self, id: int):
|
409
|
+
def clear_meta(self, id: int) -> bool:
|
386
410
|
"""
|
387
411
|
Clear meta by ID
|
388
412
|
|
389
413
|
:param id: ctx ID
|
414
|
+
:return: True if cleared
|
390
415
|
"""
|
391
416
|
return self.storage.clear_meta(id)
|
@@ -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.
|
9
|
+
# Updated Date: 2024.12.14 22:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
from datetime import datetime
|
13
13
|
import re
|
14
14
|
import time
|
15
|
+
from typing import Dict, Optional, Tuple, List
|
15
16
|
|
16
17
|
from sqlalchemy import text
|
17
18
|
|
@@ -46,11 +47,11 @@ class Storage:
|
|
46
47
|
|
47
48
|
def prepare_query(
|
48
49
|
self,
|
49
|
-
search_string: str = None,
|
50
|
-
filters: dict = None,
|
50
|
+
search_string: Optional[str] = None,
|
51
|
+
filters: Optional[dict] = None,
|
51
52
|
search_content: bool = False,
|
52
53
|
append_date_ranges: bool = True,
|
53
|
-
):
|
54
|
+
) -> Tuple[str, str, dict]:
|
54
55
|
"""
|
55
56
|
Prepare query for search_string and filters
|
56
57
|
|
@@ -122,14 +123,14 @@ class Storage:
|
|
122
123
|
|
123
124
|
def get_meta(
|
124
125
|
self,
|
125
|
-
search_string: str = None,
|
126
|
-
order_by: str = None,
|
127
|
-
order_direction: str = None,
|
128
|
-
limit: int = None,
|
129
|
-
offset: int = None,
|
130
|
-
filters: dict = None,
|
126
|
+
search_string: Optional[str] = None,
|
127
|
+
order_by: Optional[str] = None,
|
128
|
+
order_direction: Optional[str] = None,
|
129
|
+
limit: Optional[int] = None,
|
130
|
+
offset: Optional[int] = None,
|
131
|
+
filters: Optional[dict] = None,
|
131
132
|
search_content: bool = False,
|
132
|
-
) ->
|
133
|
+
) -> Dict[int, CtxMeta]:
|
133
134
|
"""
|
134
135
|
Return dict with CtxMeta objects, indexed by ID
|
135
136
|
|
@@ -169,7 +170,7 @@ class Storage:
|
|
169
170
|
|
170
171
|
return items
|
171
172
|
|
172
|
-
def get_meta_indexed(self) ->
|
173
|
+
def get_meta_indexed(self) -> Dict[int, CtxMeta]:
|
173
174
|
"""
|
174
175
|
Return dict with indexed CtxMeta objects, indexed by ID
|
175
176
|
|
@@ -189,7 +190,32 @@ class Storage:
|
|
189
190
|
items[meta.id] = meta
|
190
191
|
return items
|
191
192
|
|
192
|
-
def
|
193
|
+
def get_item_by_id(self, id: int) -> Optional[CtxItem]:
|
194
|
+
"""
|
195
|
+
Return ctx item by ID
|
196
|
+
|
197
|
+
:return: CtxItem
|
198
|
+
"""
|
199
|
+
stmt = text("""
|
200
|
+
SELECT * FROM ctx_item WHERE id = :id
|
201
|
+
""").bindparams(id=id)
|
202
|
+
db = self.window.core.db.get_db()
|
203
|
+
with db.connect() as conn:
|
204
|
+
result = conn.execute(stmt)
|
205
|
+
row = result.fetchone()
|
206
|
+
if row:
|
207
|
+
item = CtxItem()
|
208
|
+
unpack_item(item, row._asdict())
|
209
|
+
meta = self.get_meta_by_id(item.meta_id) # append meta
|
210
|
+
item.meta = meta
|
211
|
+
return item
|
212
|
+
return None
|
213
|
+
|
214
|
+
def get_meta_by_root_id_and_preset_id(
|
215
|
+
self,
|
216
|
+
root_id: int,
|
217
|
+
preset_id: str
|
218
|
+
) -> Dict[int, CtxMeta]:
|
193
219
|
"""
|
194
220
|
Return dict with indexed CtxMeta objects, indexed by ID
|
195
221
|
|
@@ -212,7 +238,7 @@ class Storage:
|
|
212
238
|
items[meta.id] = meta
|
213
239
|
return items
|
214
240
|
|
215
|
-
def get_meta_by_id(self, id: int) -> CtxMeta
|
241
|
+
def get_meta_by_id(self, id: int) -> Optional[CtxMeta]:
|
216
242
|
"""
|
217
243
|
Return ctx meta by ID
|
218
244
|
|
@@ -248,7 +274,7 @@ class Storage:
|
|
248
274
|
return int(row.id)
|
249
275
|
return 0
|
250
276
|
|
251
|
-
def get_items(self, id: int) ->
|
277
|
+
def get_items(self, id: int) -> List[CtxItem]:
|
252
278
|
"""
|
253
279
|
Return ctx items list by ctx meta ID
|
254
280
|
|
@@ -407,7 +433,11 @@ class Storage:
|
|
407
433
|
conn.execute(stmt)
|
408
434
|
return True
|
409
435
|
|
410
|
-
def update_meta_all(
|
436
|
+
def update_meta_all(
|
437
|
+
self,
|
438
|
+
meta: CtxMeta,
|
439
|
+
items: List[CtxItem]
|
440
|
+
) -> bool:
|
411
441
|
"""
|
412
442
|
Update all, meta and items
|
413
443
|
|
@@ -870,12 +900,12 @@ class Storage:
|
|
870
900
|
def get_ctx_count_by_day(
|
871
901
|
self,
|
872
902
|
year: int,
|
873
|
-
month: int = None,
|
874
|
-
day: int = None,
|
875
|
-
search_string: str = None,
|
876
|
-
filters: dict = None,
|
903
|
+
month: Optional[int] = None,
|
904
|
+
day: Optional[int] = None,
|
905
|
+
search_string: Optional[str] = None,
|
906
|
+
filters: Optional[dict] = None,
|
877
907
|
search_content: bool = False,
|
878
|
-
) ->
|
908
|
+
) -> Dict[str, int]:
|
879
909
|
"""
|
880
910
|
Return ctx counters by day for given year and month
|
881
911
|
|
@@ -966,12 +996,12 @@ class Storage:
|
|
966
996
|
def get_ctx_labels_count_by_day(
|
967
997
|
self,
|
968
998
|
year: int,
|
969
|
-
month: int = None,
|
970
|
-
day: int = None,
|
971
|
-
search_string: str = None,
|
972
|
-
filters: dict = None,
|
999
|
+
month: Optional[int] = None,
|
1000
|
+
day: Optional[int] = None,
|
1001
|
+
search_string: Optional[str] = None,
|
1002
|
+
filters: Optional[dict] = None,
|
973
1003
|
search_content: bool = False,
|
974
|
-
) ->
|
1004
|
+
) -> Dict[str, Dict[int, int]]:
|
975
1005
|
"""
|
976
1006
|
Return ctx counters by day for given year and month
|
977
1007
|
|
@@ -1095,7 +1125,7 @@ class Storage:
|
|
1095
1125
|
|
1096
1126
|
return result_dict
|
1097
1127
|
|
1098
|
-
def get_groups(self) ->
|
1128
|
+
def get_groups(self) -> Dict[int, CtxGroup]:
|
1099
1129
|
"""
|
1100
1130
|
Return dict with CtxGroup objects, indexed by ID
|
1101
1131
|
|
@@ -1168,16 +1198,17 @@ class Storage:
|
|
1168
1198
|
conn.execute(text("DELETE FROM sqlite_sequence WHERE name='ctx_group'"))
|
1169
1199
|
return True
|
1170
1200
|
|
1171
|
-
def clear_meta(self, meta_id: int):
|
1201
|
+
def clear_meta(self, meta_id: int) -> bool:
|
1172
1202
|
"""
|
1173
1203
|
Delete all items with meta ID
|
1174
1204
|
|
1175
1205
|
:param meta_id: meta ID
|
1176
|
-
:return:
|
1206
|
+
:return: True if cleared
|
1177
1207
|
"""
|
1178
1208
|
db = self.window.core.db.get_db()
|
1179
1209
|
with db.begin() as conn:
|
1180
1210
|
conn.execute(text(f"DELETE FROM ctx_item WHERE meta_id = {meta_id}"))
|
1211
|
+
return True
|
1181
1212
|
|
1182
1213
|
def update_group(self, group: CtxGroup) -> bool:
|
1183
1214
|
"""
|
@@ -1237,12 +1268,13 @@ class Storage:
|
|
1237
1268
|
group.id = result.lastrowid
|
1238
1269
|
return group.id
|
1239
1270
|
|
1240
|
-
def update_meta_group_id(self, meta_id: int, group_id: int = None):
|
1271
|
+
def update_meta_group_id(self, meta_id: int, group_id: int = None) -> bool:
|
1241
1272
|
"""
|
1242
1273
|
Update meta group ID
|
1243
1274
|
|
1244
1275
|
:param meta_id: ctx meta ID
|
1245
1276
|
:param group_id: ctx group ID
|
1277
|
+
:return: True if updated
|
1246
1278
|
"""
|
1247
1279
|
db = self.window.core.db.get_db()
|
1248
1280
|
stmt = text("""
|
@@ -6,18 +6,20 @@
|
|
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
|
import json
|
13
13
|
import re
|
14
|
+
|
14
15
|
from datetime import datetime, timedelta
|
16
|
+
from typing import List, Tuple, Any, Dict
|
15
17
|
|
16
18
|
from pygpt_net.item.ctx import CtxMeta, CtxItem, CtxGroup
|
17
19
|
from pygpt_net.utils import unpack_var
|
18
20
|
|
19
21
|
|
20
|
-
def search_by_date_string(search_string: str) ->
|
22
|
+
def search_by_date_string(search_string: str) -> List[Tuple[Any, Any]]:
|
21
23
|
"""
|
22
24
|
Prepare date ranges from search string if @date() syntax is used
|
23
25
|
|
@@ -64,7 +66,7 @@ def search_by_date_string(search_string: str) -> list:
|
|
64
66
|
return date_ranges
|
65
67
|
|
66
68
|
|
67
|
-
def get_month_start_end_timestamps(year: int, month: int) ->
|
69
|
+
def get_month_start_end_timestamps(year: int, month: int) -> Tuple[int, int]:
|
68
70
|
"""
|
69
71
|
Get start and end timestamps for given month
|
70
72
|
|
@@ -82,7 +84,7 @@ def get_month_start_end_timestamps(year: int, month: int) -> (int, int):
|
|
82
84
|
return start_timestamp, end_timestamp
|
83
85
|
|
84
86
|
|
85
|
-
def get_year_start_end_timestamps(year: int) ->
|
87
|
+
def get_year_start_end_timestamps(year: int) -> Tuple[int, int]:
|
86
88
|
"""
|
87
89
|
Get start and end timestamps for given year
|
88
90
|
|
@@ -96,7 +98,7 @@ def get_year_start_end_timestamps(year: int) -> (int, int):
|
|
96
98
|
return start_timestamp, end_timestamp
|
97
99
|
|
98
100
|
|
99
|
-
def pack_item_value(value:
|
101
|
+
def pack_item_value(value: Any) -> str:
|
100
102
|
"""
|
101
103
|
Pack item value to JSON
|
102
104
|
|
@@ -108,7 +110,7 @@ def pack_item_value(value: any) -> str:
|
|
108
110
|
return value
|
109
111
|
|
110
112
|
|
111
|
-
def unpack_item_value(value:
|
113
|
+
def unpack_item_value(value: Any) -> Any:
|
112
114
|
"""
|
113
115
|
Unpack item value from JSON
|
114
116
|
|
@@ -123,7 +125,7 @@ def unpack_item_value(value: any) -> any:
|
|
123
125
|
return value
|
124
126
|
|
125
127
|
|
126
|
-
def unpack_item(item: CtxItem, row:
|
128
|
+
def unpack_item(item: CtxItem, row: Dict[str, Any]) -> CtxItem:
|
127
129
|
"""
|
128
130
|
Unpack context item from DB row
|
129
131
|
|
@@ -183,7 +185,7 @@ def unpack_item(item: CtxItem, row: dict) -> CtxItem:
|
|
183
185
|
return item
|
184
186
|
|
185
187
|
|
186
|
-
def unpack_meta(meta: CtxMeta, row:
|
188
|
+
def unpack_meta(meta: CtxMeta, row: Dict[str, Any]) -> CtxMeta:
|
187
189
|
"""
|
188
190
|
Unpack context meta data from DB row
|
189
191
|
|
@@ -222,7 +224,7 @@ def unpack_meta(meta: CtxMeta, row: dict) -> CtxMeta:
|
|
222
224
|
return meta
|
223
225
|
|
224
226
|
|
225
|
-
def unpack_group(group: CtxGroup, row:
|
227
|
+
def unpack_group(group: CtxGroup, row: Dict[str, Any]) -> CtxGroup:
|
226
228
|
"""
|
227
229
|
Unpack context group data from DB row
|
228
230
|
|