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/idx/chat.py
CHANGED
@@ -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 json
|
13
|
+
from typing import Optional, Dict, Any, List
|
13
14
|
|
14
15
|
from llama_index.core.llms import ChatMessage, MessageRole
|
15
16
|
from llama_index.core.prompts import ChatPromptTemplate
|
@@ -37,7 +38,11 @@ class Chat:
|
|
37
38
|
self.storage = storage
|
38
39
|
self.context = Context(window)
|
39
40
|
|
40
|
-
def call(
|
41
|
+
def call(
|
42
|
+
self,
|
43
|
+
context: BridgeContext,
|
44
|
+
extra: Optional[Dict[str, Any]] = None
|
45
|
+
) -> bool:
|
41
46
|
"""
|
42
47
|
Call chat, complete or query mode
|
43
48
|
|
@@ -69,7 +74,11 @@ class Chat:
|
|
69
74
|
extra=extra,
|
70
75
|
) # if not, use query mode
|
71
76
|
|
72
|
-
def raw_query(
|
77
|
+
def raw_query(
|
78
|
+
self,
|
79
|
+
context: BridgeContext,
|
80
|
+
extra: Optional[Dict[str, Any]] = None
|
81
|
+
) -> bool:
|
73
82
|
"""
|
74
83
|
Raw query mode
|
75
84
|
|
@@ -82,7 +91,11 @@ class Chat:
|
|
82
91
|
extra=extra,
|
83
92
|
)
|
84
93
|
|
85
|
-
def query(
|
94
|
+
def query(
|
95
|
+
self,
|
96
|
+
context: BridgeContext,
|
97
|
+
extra: Optional[Dict[str, Any]] = None
|
98
|
+
) -> bool:
|
86
99
|
"""
|
87
100
|
Query index mode (no chat, only single query) and append results to context
|
88
101
|
|
@@ -150,7 +163,11 @@ class Chat:
|
|
150
163
|
return True
|
151
164
|
return False
|
152
165
|
|
153
|
-
def chat(
|
166
|
+
def chat(
|
167
|
+
self,
|
168
|
+
context: BridgeContext,
|
169
|
+
extra: Optional[Dict[str, Any]] = None
|
170
|
+
) -> bool:
|
154
171
|
"""
|
155
172
|
Chat mode (conversation, using context from index) and append result to the context
|
156
173
|
|
@@ -291,7 +308,7 @@ class Chat:
|
|
291
308
|
ctx: CtxItem,
|
292
309
|
path: str,
|
293
310
|
query: str,
|
294
|
-
model: ModelItem = None
|
311
|
+
model: Optional[ModelItem] = None
|
295
312
|
) -> str:
|
296
313
|
"""
|
297
314
|
Query file using temp index (created on the fly)
|
@@ -343,9 +360,9 @@ class Chat:
|
|
343
360
|
ctx: CtxItem,
|
344
361
|
type: str,
|
345
362
|
url: str,
|
346
|
-
args:
|
363
|
+
args: Dict[str, Any],
|
347
364
|
query: str,
|
348
|
-
model: ModelItem = None
|
365
|
+
model: Optional[ModelItem] = None
|
349
366
|
) -> str:
|
350
367
|
"""
|
351
368
|
Query web using temp index (created on the fly)
|
@@ -405,8 +422,8 @@ class Chat:
|
|
405
422
|
self,
|
406
423
|
query: str,
|
407
424
|
path: str,
|
408
|
-
model: ModelItem = None,
|
409
|
-
history:
|
425
|
+
model: Optional[ModelItem] = None,
|
426
|
+
history: Optional[List[CtxItem]] = None,
|
410
427
|
verbose: bool = False,
|
411
428
|
) -> str:
|
412
429
|
"""
|
@@ -461,7 +478,7 @@ class Chat:
|
|
461
478
|
self,
|
462
479
|
query: str,
|
463
480
|
idx: str,
|
464
|
-
model: ModelItem = None
|
481
|
+
model: Optional[ModelItem] = None
|
465
482
|
) -> str:
|
466
483
|
"""
|
467
484
|
Query attachment
|
@@ -486,7 +503,11 @@ class Chat:
|
|
486
503
|
output = str(response)
|
487
504
|
return output
|
488
505
|
|
489
|
-
def get_memory_buffer(
|
506
|
+
def get_memory_buffer(
|
507
|
+
self,
|
508
|
+
history: List[ChatMessage],
|
509
|
+
llm = None
|
510
|
+
) -> ChatMemoryBuffer:
|
490
511
|
"""
|
491
512
|
Get memory buffer
|
492
513
|
|
@@ -499,7 +520,10 @@ class Chat:
|
|
499
520
|
llm=llm,
|
500
521
|
)
|
501
522
|
|
502
|
-
def get_custom_prompt(
|
523
|
+
def get_custom_prompt(
|
524
|
+
self,
|
525
|
+
prompt: Optional[str] = None
|
526
|
+
) -> Optional[ChatPromptTemplate]:
|
503
527
|
"""
|
504
528
|
Get custom prompt template if sys prompt is not empty
|
505
529
|
|
@@ -528,12 +552,16 @@ class Chat:
|
|
528
552
|
]
|
529
553
|
return ChatPromptTemplate(qa_msgs)
|
530
554
|
|
531
|
-
def get_index(
|
555
|
+
def get_index(
|
556
|
+
self,
|
557
|
+
idx: str,
|
558
|
+
model: ModelItem
|
559
|
+
):
|
532
560
|
"""
|
533
561
|
Get index instance
|
534
562
|
|
535
563
|
:param idx: idx name (id)
|
536
|
-
:param model: model
|
564
|
+
:param model: model instance
|
537
565
|
:return:
|
538
566
|
"""
|
539
567
|
# check if index exists
|
@@ -549,7 +577,10 @@ class Chat:
|
|
549
577
|
index = self.storage.get(idx, service_context=service_context) # get index
|
550
578
|
return index, service_context
|
551
579
|
|
552
|
-
def get_metadata(
|
580
|
+
def get_metadata(
|
581
|
+
self,
|
582
|
+
source_nodes: Optional[list]
|
583
|
+
) -> Dict[str, Any]:
|
553
584
|
"""
|
554
585
|
Get metadata from source nodes
|
555
586
|
|
@@ -577,7 +608,10 @@ class Chat:
|
|
577
608
|
break
|
578
609
|
return metadata
|
579
610
|
|
580
|
-
def parse_metadata(
|
611
|
+
def parse_metadata(
|
612
|
+
self,
|
613
|
+
metadata: Optional[Dict]
|
614
|
+
) -> Dict[str, Any]:
|
581
615
|
"""
|
582
616
|
Parse metadata
|
583
617
|
|
pygpt_net/core/idx/context.py
CHANGED
@@ -6,11 +6,15 @@
|
|
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 Optional, List
|
13
|
+
|
12
14
|
from llama_index.core.llms import ChatMessage, MessageRole
|
13
15
|
|
16
|
+
from pygpt_net.item.ctx import CtxItem
|
17
|
+
|
14
18
|
|
15
19
|
class Context:
|
16
20
|
def __init__(self, window=None):
|
@@ -25,7 +29,7 @@ class Context:
|
|
25
29
|
self,
|
26
30
|
input_prompt: str,
|
27
31
|
system_prompt: str,
|
28
|
-
history:
|
32
|
+
history: Optional[List[CtxItem]] = None,
|
29
33
|
multimodal: bool = False
|
30
34
|
):
|
31
35
|
"""
|
pygpt_net/core/idx/indexing.py
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# GitHub: https://github.com/szczyglis-dev/py-gpt #
|
7
7
|
# MIT License #
|
8
8
|
# Created By : Marcin Szczygliński #
|
9
|
-
# Updated Date: 2024.
|
9
|
+
# Updated Date: 2024.12.14 22:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
import datetime
|
@@ -14,6 +14,8 @@ import os.path
|
|
14
14
|
import time
|
15
15
|
|
16
16
|
from pathlib import Path
|
17
|
+
from typing import Optional, Tuple, List, Dict, Any
|
18
|
+
|
17
19
|
from sqlalchemy import text
|
18
20
|
|
19
21
|
from llama_index.core.indices.base import BaseIndex
|
@@ -99,7 +101,11 @@ class Indexing:
|
|
99
101
|
self.window.core.debug.log(msg)
|
100
102
|
self.window.core.debug.log(e)
|
101
103
|
|
102
|
-
def update_loader_args(
|
104
|
+
def update_loader_args(
|
105
|
+
self,
|
106
|
+
loader: str,
|
107
|
+
args: Dict[str, Any]
|
108
|
+
):
|
103
109
|
"""
|
104
110
|
Update loader arguments
|
105
111
|
|
@@ -142,7 +148,7 @@ class Indexing:
|
|
142
148
|
self.register_loader(loader)
|
143
149
|
self.window.core.idx.log("Data loaders reloaded.")
|
144
150
|
|
145
|
-
def get_external_instructions(self) ->
|
151
|
+
def get_external_instructions(self) -> Dict[str, Any]:
|
146
152
|
"""
|
147
153
|
Get external instructions
|
148
154
|
|
@@ -150,7 +156,7 @@ class Indexing:
|
|
150
156
|
"""
|
151
157
|
return self.external_instructions
|
152
158
|
|
153
|
-
def get_external_config(self) ->
|
159
|
+
def get_external_config(self) -> Dict[str, Any]:
|
154
160
|
"""
|
155
161
|
Get external config
|
156
162
|
|
@@ -177,7 +183,7 @@ class Indexing:
|
|
177
183
|
if ext in extensions:
|
178
184
|
return loader["loader"]
|
179
185
|
|
180
|
-
def get_data_providers(self) ->
|
186
|
+
def get_data_providers(self) -> Dict[str, BaseLoader]:
|
181
187
|
"""
|
182
188
|
Get data providers
|
183
189
|
|
@@ -185,7 +191,11 @@ class Indexing:
|
|
185
191
|
"""
|
186
192
|
return self.data_providers
|
187
193
|
|
188
|
-
def get_loader_arguments(
|
194
|
+
def get_loader_arguments(
|
195
|
+
self,
|
196
|
+
id: str,
|
197
|
+
type: str = "file"
|
198
|
+
) -> Dict[str, Any]:
|
189
199
|
"""
|
190
200
|
Get keyword arguments for loader
|
191
201
|
|
@@ -267,8 +277,8 @@ class Indexing:
|
|
267
277
|
path: str,
|
268
278
|
force: bool = False,
|
269
279
|
silent: bool = False,
|
270
|
-
loader_kwargs:
|
271
|
-
) ->
|
280
|
+
loader_kwargs: Optional[Dict[str, Any]] = None,
|
281
|
+
) -> List[Document]:
|
272
282
|
"""
|
273
283
|
Get documents from path using data loaders
|
274
284
|
|
@@ -330,7 +340,11 @@ class Indexing:
|
|
330
340
|
self.window.core.idx.metadata.append_file_metadata(documents, path)
|
331
341
|
return documents
|
332
342
|
|
333
|
-
def read_text_content(
|
343
|
+
def read_text_content(
|
344
|
+
self,
|
345
|
+
path: str,
|
346
|
+
loader_kwargs: Optional[Dict[str, Any]] = None
|
347
|
+
) -> str:
|
334
348
|
"""
|
335
349
|
Get content from file using loaders
|
336
350
|
|
@@ -353,7 +367,7 @@ class Indexing:
|
|
353
367
|
self,
|
354
368
|
url: str,
|
355
369
|
type: str = "webpage",
|
356
|
-
extra_args:
|
370
|
+
extra_args: Optional[Dict[str, Any]] = None
|
357
371
|
) -> str:
|
358
372
|
"""
|
359
373
|
Get content from external resource
|
@@ -373,8 +387,8 @@ class Indexing:
|
|
373
387
|
self,
|
374
388
|
url: str,
|
375
389
|
type: str = "webpage",
|
376
|
-
extra_args:
|
377
|
-
) ->
|
390
|
+
extra_args: Optional[Dict[str, Any]] = None,
|
391
|
+
) -> List[Document]:
|
378
392
|
"""
|
379
393
|
Read data from external resource
|
380
394
|
|
@@ -423,11 +437,11 @@ class Indexing:
|
|
423
437
|
self,
|
424
438
|
idx: str,
|
425
439
|
index: BaseIndex,
|
426
|
-
path: str = None,
|
440
|
+
path: Optional[str] = None,
|
427
441
|
is_tmp: bool = False,
|
428
|
-
replace: bool = None,
|
429
|
-
recursive: bool = None
|
430
|
-
) ->
|
442
|
+
replace: Optional[bool] = None,
|
443
|
+
recursive: Optional[bool] = None
|
444
|
+
) -> Tuple[dict, list]:
|
431
445
|
"""
|
432
446
|
Index all files in directory
|
433
447
|
|
@@ -494,10 +508,10 @@ class Indexing:
|
|
494
508
|
self,
|
495
509
|
idx: str,
|
496
510
|
index: BaseIndex,
|
497
|
-
path: str = None,
|
511
|
+
path: Optional[str] = None,
|
498
512
|
is_tmp: bool = False,
|
499
|
-
replace: bool = None
|
500
|
-
) ->
|
513
|
+
replace: Optional[bool] = None
|
514
|
+
) -> Tuple[dict, list]:
|
501
515
|
"""
|
502
516
|
Index all files in directory and subdirectories recursively.
|
503
517
|
|
@@ -586,7 +600,10 @@ class Indexing:
|
|
586
600
|
|
587
601
|
return indexed, errors
|
588
602
|
|
589
|
-
def get_db_data_from_ts(
|
603
|
+
def get_db_data_from_ts(
|
604
|
+
self,
|
605
|
+
updated_ts: int = 0
|
606
|
+
) -> List[Document]:
|
590
607
|
"""
|
591
608
|
Get data from database from timestamp
|
592
609
|
|
@@ -626,7 +643,10 @@ class Indexing:
|
|
626
643
|
documents.append(doc)
|
627
644
|
return documents
|
628
645
|
|
629
|
-
def get_db_meta_ids_from_ts(
|
646
|
+
def get_db_meta_ids_from_ts(
|
647
|
+
self,
|
648
|
+
updated_ts: int = 0
|
649
|
+
) -> List[int]:
|
630
650
|
"""
|
631
651
|
Get IDs of meta from database from timestamp
|
632
652
|
|
@@ -650,7 +670,11 @@ class Indexing:
|
|
650
670
|
ids.append(data["id"])
|
651
671
|
return ids
|
652
672
|
|
653
|
-
def get_db_data_by_id(
|
673
|
+
def get_db_data_by_id(
|
674
|
+
self,
|
675
|
+
id: int = 0,
|
676
|
+
updated_ts: int = 0
|
677
|
+
) -> List[Document]:
|
654
678
|
"""
|
655
679
|
Get data from database by meta id
|
656
680
|
|
@@ -688,7 +712,13 @@ class Indexing:
|
|
688
712
|
documents.append(doc)
|
689
713
|
return documents
|
690
714
|
|
691
|
-
def index_db_by_meta_id(
|
715
|
+
def index_db_by_meta_id(
|
716
|
+
self,
|
717
|
+
idx: str,
|
718
|
+
index: BaseIndex,
|
719
|
+
id: int = 0,
|
720
|
+
from_ts: int = 0
|
721
|
+
) -> Tuple[int, List[str]]:
|
692
722
|
"""
|
693
723
|
Index data from database by meta id
|
694
724
|
|
@@ -706,7 +736,8 @@ class Indexing:
|
|
706
736
|
self.window.core.idx.log("Indexing documents from database by meta id: {}".format(id))
|
707
737
|
self.remove_old_meta_id(idx, id)
|
708
738
|
elif from_ts > 0:
|
709
|
-
self.window.core.idx.log("Indexing documents from database by meta id: {} from timestamp: {}".
|
739
|
+
self.window.core.idx.log("Indexing documents from database by meta id: {} from timestamp: {}".
|
740
|
+
format(id, from_ts))
|
710
741
|
|
711
742
|
# get items from database
|
712
743
|
documents = self.get_db_data_by_id(id, from_ts)
|
@@ -716,7 +747,8 @@ class Indexing:
|
|
716
747
|
|
717
748
|
self.index_document(index, d)
|
718
749
|
doc_id = d.id_
|
719
|
-
self.window.core.idx.log("Inserted ctx DB document: {} / {}, id: {}, metadata: {}".
|
750
|
+
self.window.core.idx.log("Inserted ctx DB document: {} / {}, id: {}, metadata: {}".
|
751
|
+
format(n+1, len(documents), d.id_, d.metadata))
|
720
752
|
self.window.core.ctx.idx.set_meta_as_indexed(id, idx, doc_id) # update ctx
|
721
753
|
n += 1
|
722
754
|
except Exception as e:
|
@@ -724,7 +756,12 @@ class Indexing:
|
|
724
756
|
self.window.core.debug.log(e)
|
725
757
|
return n, errors
|
726
758
|
|
727
|
-
def index_db_from_updated_ts(
|
759
|
+
def index_db_from_updated_ts(
|
760
|
+
self,
|
761
|
+
idx: str,
|
762
|
+
index: BaseIndex,
|
763
|
+
from_ts: int = 0
|
764
|
+
) -> Tuple[int, List[str]]:
|
728
765
|
"""
|
729
766
|
Index data from database from timestamp
|
730
767
|
|
@@ -752,10 +789,10 @@ class Indexing:
|
|
752
789
|
index: BaseIndex,
|
753
790
|
url: str,
|
754
791
|
type="webpage",
|
755
|
-
extra_args:
|
792
|
+
extra_args: Optional[Dict[str, Any]] = None,
|
756
793
|
is_tmp: bool = False,
|
757
|
-
replace: bool = None
|
758
|
-
) ->
|
794
|
+
replace: Optional[bool] = None
|
795
|
+
) -> Tuple[int, List[str]]:
|
759
796
|
"""
|
760
797
|
Index data from external (remote) resource
|
761
798
|
|
@@ -825,7 +862,8 @@ class Indexing:
|
|
825
862
|
idx=idx,
|
826
863
|
doc_id=doc_id,
|
827
864
|
) # update external index
|
828
|
-
self.window.core.idx.log("Inserted web document: {} / {}, id: {}, metadata: {}".
|
865
|
+
self.window.core.idx.log("Inserted web document: {} / {}, id: {}, metadata: {}".
|
866
|
+
format(n+1, len(documents), d.id_, d.metadata))
|
829
867
|
n += 1
|
830
868
|
except Exception as e:
|
831
869
|
errors.append(str(e))
|
@@ -838,9 +876,9 @@ class Indexing:
|
|
838
876
|
index: BaseIndex,
|
839
877
|
urls: list,
|
840
878
|
type="webpage",
|
841
|
-
extra_args:
|
879
|
+
extra_args: Optional[Dict[str, Any]] = None,
|
842
880
|
is_tmp: bool = False
|
843
|
-
) ->
|
881
|
+
) -> Tuple[int, List[str]]:
|
844
882
|
"""
|
845
883
|
Index data from URLs
|
846
884
|
|
@@ -878,7 +916,12 @@ class Indexing:
|
|
878
916
|
errors.extend(errs)
|
879
917
|
return n, errors
|
880
918
|
|
881
|
-
def remove_old_meta_id(
|
919
|
+
def remove_old_meta_id(
|
920
|
+
self,
|
921
|
+
idx: str,
|
922
|
+
id: int = 0,
|
923
|
+
force: bool = False
|
924
|
+
) -> bool:
|
882
925
|
"""
|
883
926
|
Remove old meta id from index
|
884
927
|
|
@@ -906,7 +949,12 @@ class Indexing:
|
|
906
949
|
return True
|
907
950
|
return False
|
908
951
|
|
909
|
-
def remove_old_file(
|
952
|
+
def remove_old_file(
|
953
|
+
self,
|
954
|
+
idx: str,
|
955
|
+
file_id: str,
|
956
|
+
force: bool = False
|
957
|
+
) -> bool:
|
910
958
|
"""
|
911
959
|
Remove old file from index
|
912
960
|
|
@@ -934,7 +982,13 @@ class Indexing:
|
|
934
982
|
return True
|
935
983
|
return False
|
936
984
|
|
937
|
-
def remove_old_external(
|
985
|
+
def remove_old_external(
|
986
|
+
self,
|
987
|
+
idx: str,
|
988
|
+
content: str,
|
989
|
+
type: str,
|
990
|
+
force: bool = False
|
991
|
+
) -> bool:
|
938
992
|
"""
|
939
993
|
Remove old file from index
|
940
994
|
|
@@ -963,7 +1017,11 @@ class Indexing:
|
|
963
1017
|
return True
|
964
1018
|
return False
|
965
1019
|
|
966
|
-
def index_document(
|
1020
|
+
def index_document(
|
1021
|
+
self,
|
1022
|
+
index: BaseIndex,
|
1023
|
+
doc: Document
|
1024
|
+
):
|
967
1025
|
"""
|
968
1026
|
Index document
|
969
1027
|
|
@@ -983,8 +1041,8 @@ class Indexing:
|
|
983
1041
|
self,
|
984
1042
|
file_path: str,
|
985
1043
|
index_path: str,
|
986
|
-
model: ModelItem = None,
|
987
|
-
documents:
|
1044
|
+
model: Optional[ModelItem] = None,
|
1045
|
+
documents: Optional[List[Document]] = None,
|
988
1046
|
) -> list:
|
989
1047
|
"""
|
990
1048
|
Index context attachment
|
@@ -999,7 +1057,10 @@ class Indexing:
|
|
999
1057
|
model = self.window.core.models.from_defaults()
|
1000
1058
|
|
1001
1059
|
service_context = self.window.core.idx.llm.get_service_context(model=model)
|
1002
|
-
index = self.window.core.idx.storage.get_ctx_idx(
|
1060
|
+
index = self.window.core.idx.storage.get_ctx_idx(
|
1061
|
+
index_path,
|
1062
|
+
service_context=service_context
|
1063
|
+
) # get or create ctx index
|
1003
1064
|
|
1004
1065
|
idx = "tmp:{}".format(index_path) # tmp index id
|
1005
1066
|
self.window.core.idx.log("Indexing to context attachment index: {}...".format(idx))
|
@@ -1021,8 +1082,8 @@ class Indexing:
|
|
1021
1082
|
self,
|
1022
1083
|
url: str,
|
1023
1084
|
index_path: str,
|
1024
|
-
model: ModelItem = None,
|
1025
|
-
documents:
|
1085
|
+
model: Optional[ModelItem] = None,
|
1086
|
+
documents: Optional[List[Document]] = None,
|
1026
1087
|
) -> list:
|
1027
1088
|
"""
|
1028
1089
|
Index context attachment
|
@@ -1077,7 +1138,11 @@ class Indexing:
|
|
1077
1138
|
print("Selected web data loader: {}".format(type))
|
1078
1139
|
return type
|
1079
1140
|
|
1080
|
-
def remove_attachment(
|
1141
|
+
def remove_attachment(
|
1142
|
+
self,
|
1143
|
+
index_path: str,
|
1144
|
+
doc_id: str
|
1145
|
+
) -> bool:
|
1081
1146
|
"""
|
1082
1147
|
Remove document from index
|
1083
1148
|
|
pygpt_net/core/idx/llm.py
CHANGED
@@ -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 08:00:00 #
|
10
10
|
# ================================================== #
|
11
11
|
|
12
12
|
import os.path
|
13
|
+
from typing import Optional, Union
|
13
14
|
|
14
15
|
from llama_index.core.llms.llm import BaseLLM
|
15
16
|
from llama_index.core.multi_modal_llms import MultiModalLLM
|
@@ -41,7 +42,11 @@ class Llm:
|
|
41
42
|
os.environ['OPENAI_API_BASE'] = str(self.window.core.config.get('api_endpoint'))
|
42
43
|
os.environ['OPENAI_ORGANIZATION'] = str(self.window.core.config.get('organization_key'))
|
43
44
|
|
44
|
-
def get(
|
45
|
+
def get(
|
46
|
+
self,
|
47
|
+
model: Optional[ModelItem] = None,
|
48
|
+
multimodal: bool = False
|
49
|
+
) -> Union[BaseLLM, MultiModalLLM]:
|
45
50
|
"""
|
46
51
|
Get LLM provider
|
47
52
|
|
@@ -117,7 +122,10 @@ class Llm:
|
|
117
122
|
config=args,
|
118
123
|
)
|
119
124
|
|
120
|
-
def get_service_context(
|
125
|
+
def get_service_context(
|
126
|
+
self,
|
127
|
+
model: Optional[ModelItem] = None
|
128
|
+
) -> ServiceContext:
|
121
129
|
"""
|
122
130
|
Get service context + embeddings provider
|
123
131
|
|
pygpt_net/core/idx/metadata.py
CHANGED
@@ -6,11 +6,12 @@
|
|
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 datetime
|
13
13
|
import os.path
|
14
|
+
from typing import List, Dict, Any
|
14
15
|
|
15
16
|
from llama_index.core.schema import Document
|
16
17
|
|
@@ -24,7 +25,11 @@ class Metadata:
|
|
24
25
|
"""
|
25
26
|
self.window = window
|
26
27
|
|
27
|
-
def append_file_metadata(
|
28
|
+
def append_file_metadata(
|
29
|
+
self,
|
30
|
+
docs: List[Document],
|
31
|
+
path: str
|
32
|
+
):
|
28
33
|
"""
|
29
34
|
Append custom meta to documents (file)
|
30
35
|
|
@@ -81,7 +86,12 @@ class Metadata:
|
|
81
86
|
self.window.core.debug.log(e)
|
82
87
|
doc.metadata = meta
|
83
88
|
|
84
|
-
def append_web_metadata(
|
89
|
+
def append_web_metadata(
|
90
|
+
self,
|
91
|
+
docs: List[Document],
|
92
|
+
type: str,
|
93
|
+
args: Dict[str, Any]
|
94
|
+
):
|
85
95
|
"""
|
86
96
|
Append custom meta to documents (web)
|
87
97
|
|