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
pygpt_net/core/ctx/__init__.py
CHANGED
@@ -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 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
|
-
|
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(
|
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(
|
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(
|
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(
|
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(
|
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
|
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
|
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
|
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(
|
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(
|
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(
|
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
|
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
|
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
|
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:
|
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
|
-
) ->
|
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:
|
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
|
-
) ->
|
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(
|
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) ->
|
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) ->
|
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
|
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(
|
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) ->
|
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(
|
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.
|
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.
|
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)
|