pygpt-net 2.4.41__py3-none-any.whl → 2.4.43__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. CHANGELOG.md +13 -0
  2. README.md +142 -70
  3. pygpt_net/CHANGELOG.txt +13 -0
  4. pygpt_net/__init__.py +3 -3
  5. pygpt_net/app.py +3 -1
  6. pygpt_net/controller/audio/__init__.py +2 -2
  7. pygpt_net/controller/camera.py +1 -10
  8. pygpt_net/controller/chat/attachment.py +36 -23
  9. pygpt_net/controller/chat/audio.py +2 -2
  10. pygpt_net/controller/config/placeholder.py +15 -1
  11. pygpt_net/controller/ui/mode.py +16 -21
  12. pygpt_net/core/attachments/__init__.py +1 -1
  13. pygpt_net/core/attachments/context.py +10 -8
  14. pygpt_net/core/audio/__init__.py +4 -1
  15. pygpt_net/core/audio/whisper.py +37 -0
  16. pygpt_net/core/bridge/worker.py +2 -2
  17. pygpt_net/core/db/__init__.py +2 -1
  18. pygpt_net/core/debug/events.py +22 -10
  19. pygpt_net/core/debug/tabs.py +6 -3
  20. pygpt_net/core/history.py +3 -2
  21. pygpt_net/core/idx/__init__.py +16 -4
  22. pygpt_net/core/idx/chat.py +15 -5
  23. pygpt_net/core/idx/indexing.py +24 -8
  24. pygpt_net/core/installer.py +2 -4
  25. pygpt_net/core/models.py +62 -17
  26. pygpt_net/core/modes.py +11 -13
  27. pygpt_net/core/notepad.py +4 -4
  28. pygpt_net/core/plugins.py +27 -16
  29. pygpt_net/core/presets.py +20 -9
  30. pygpt_net/core/profile.py +11 -3
  31. pygpt_net/core/render/web/parser.py +3 -1
  32. pygpt_net/core/settings.py +5 -5
  33. pygpt_net/core/tabs/tab.py +10 -2
  34. pygpt_net/core/tokens.py +8 -6
  35. pygpt_net/core/web/__init__.py +105 -0
  36. pygpt_net/core/{web.py → web/helpers.py} +93 -67
  37. pygpt_net/data/config/config.json +3 -3
  38. pygpt_net/data/config/models.json +3 -3
  39. pygpt_net/data/config/modes.json +3 -3
  40. pygpt_net/data/locale/locale.en.ini +1 -0
  41. pygpt_net/data/locale/plugin.cmd_web.en.ini +2 -0
  42. pygpt_net/data/locale/plugin.mailer.en.ini +21 -0
  43. pygpt_net/item/ctx.py +66 -3
  44. pygpt_net/migrations/Version20241215110000.py +25 -0
  45. pygpt_net/migrations/__init__.py +3 -1
  46. pygpt_net/plugin/agent/__init__.py +7 -2
  47. pygpt_net/plugin/audio_output/__init__.py +6 -1
  48. pygpt_net/plugin/base/plugin.py +58 -26
  49. pygpt_net/plugin/base/worker.py +20 -17
  50. pygpt_net/plugin/cmd_history/config.py +2 -2
  51. pygpt_net/plugin/cmd_web/__init__.py +3 -4
  52. pygpt_net/plugin/cmd_web/config.py +71 -3
  53. pygpt_net/plugin/cmd_web/websearch.py +20 -12
  54. pygpt_net/plugin/cmd_web/worker.py +67 -4
  55. pygpt_net/plugin/idx_llama_index/config.py +3 -3
  56. pygpt_net/plugin/mailer/__init__.py +123 -0
  57. pygpt_net/plugin/mailer/config.py +149 -0
  58. pygpt_net/plugin/mailer/runner.py +285 -0
  59. pygpt_net/plugin/mailer/worker.py +123 -0
  60. pygpt_net/provider/agents/base.py +5 -2
  61. pygpt_net/provider/agents/openai.py +4 -2
  62. pygpt_net/provider/agents/openai_assistant.py +4 -2
  63. pygpt_net/provider/agents/planner.py +4 -2
  64. pygpt_net/provider/agents/react.py +4 -2
  65. pygpt_net/provider/audio_output/openai_tts.py +5 -11
  66. pygpt_net/provider/core/assistant/base.py +5 -3
  67. pygpt_net/provider/core/assistant/json_file.py +8 -5
  68. pygpt_net/provider/core/assistant_file/base.py +4 -3
  69. pygpt_net/provider/core/assistant_file/db_sqlite/__init__.py +4 -3
  70. pygpt_net/provider/core/assistant_file/db_sqlite/storage.py +3 -2
  71. pygpt_net/provider/core/assistant_store/base.py +6 -4
  72. pygpt_net/provider/core/assistant_store/db_sqlite/__init__.py +5 -4
  73. pygpt_net/provider/core/assistant_store/db_sqlite/storage.py +5 -3
  74. pygpt_net/provider/core/attachment/base.py +5 -3
  75. pygpt_net/provider/core/attachment/json_file.py +4 -3
  76. pygpt_net/provider/core/calendar/base.py +5 -3
  77. pygpt_net/provider/core/calendar/db_sqlite/__init__.py +6 -5
  78. pygpt_net/provider/core/calendar/db_sqlite/storage.py +5 -4
  79. pygpt_net/provider/core/config/base.py +8 -6
  80. pygpt_net/provider/core/config/json_file.py +9 -7
  81. pygpt_net/provider/core/ctx/base.py +27 -25
  82. pygpt_net/provider/core/ctx/db_sqlite/__init__.py +51 -35
  83. pygpt_net/provider/core/ctx/db_sqlite/storage.py +92 -38
  84. pygpt_net/provider/core/ctx/db_sqlite/utils.py +37 -11
  85. pygpt_net/provider/core/index/base.py +129 -23
  86. pygpt_net/provider/core/index/db_sqlite/__init__.py +130 -23
  87. pygpt_net/provider/core/index/db_sqlite/storage.py +130 -23
  88. pygpt_net/provider/core/index/db_sqlite/utils.py +4 -2
  89. pygpt_net/provider/core/mode/base.py +5 -3
  90. pygpt_net/provider/core/mode/json_file.py +7 -6
  91. pygpt_net/provider/core/model/base.py +6 -4
  92. pygpt_net/provider/core/model/json_file.py +9 -7
  93. pygpt_net/provider/core/notepad/base.py +5 -3
  94. pygpt_net/provider/core/notepad/db_sqlite/__init__.py +5 -4
  95. pygpt_net/provider/core/notepad/db_sqlite/storage.py +4 -3
  96. pygpt_net/provider/core/plugin_preset/base.py +4 -2
  97. pygpt_net/provider/core/plugin_preset/json_file.py +5 -3
  98. pygpt_net/provider/core/preset/base.py +6 -4
  99. pygpt_net/provider/core/preset/json_file.py +9 -9
  100. pygpt_net/provider/core/prompt/base.py +6 -3
  101. pygpt_net/provider/core/prompt/json_file.py +11 -6
  102. pygpt_net/provider/gpt/assistants.py +15 -6
  103. pygpt_net/provider/gpt/audio.py +5 -5
  104. pygpt_net/provider/gpt/chat.py +7 -5
  105. pygpt_net/provider/gpt/completion.py +8 -4
  106. pygpt_net/provider/gpt/image.py +3 -3
  107. pygpt_net/provider/gpt/store.py +46 -12
  108. pygpt_net/provider/gpt/vision.py +16 -11
  109. pygpt_net/provider/llms/anthropic.py +7 -2
  110. pygpt_net/provider/llms/azure_openai.py +26 -5
  111. pygpt_net/provider/llms/base.py +47 -9
  112. pygpt_net/provider/llms/google.py +7 -2
  113. pygpt_net/provider/llms/hugging_face.py +13 -3
  114. pygpt_net/provider/llms/hugging_face_api.py +18 -4
  115. pygpt_net/provider/llms/local.py +7 -2
  116. pygpt_net/provider/llms/ollama.py +30 -6
  117. pygpt_net/provider/llms/openai.py +32 -6
  118. pygpt_net/provider/vector_stores/__init__.py +45 -14
  119. pygpt_net/provider/vector_stores/base.py +35 -8
  120. pygpt_net/provider/vector_stores/chroma.py +13 -3
  121. pygpt_net/provider/vector_stores/ctx_attachment.py +32 -13
  122. pygpt_net/provider/vector_stores/elasticsearch.py +12 -3
  123. pygpt_net/provider/vector_stores/pinecode.py +12 -3
  124. pygpt_net/provider/vector_stores/redis.py +12 -3
  125. pygpt_net/provider/vector_stores/simple.py +12 -3
  126. pygpt_net/provider/vector_stores/temp.py +16 -4
  127. pygpt_net/provider/web/base.py +10 -3
  128. pygpt_net/provider/web/google_custom_search.py +9 -3
  129. pygpt_net/provider/web/microsoft_bing.py +9 -3
  130. pygpt_net/tools/__init__.py +13 -5
  131. pygpt_net/tools/audio_transcriber/__init__.py +4 -3
  132. pygpt_net/tools/base.py +15 -8
  133. pygpt_net/tools/code_interpreter/__init__.py +4 -3
  134. pygpt_net/tools/html_canvas/__init__.py +4 -3
  135. pygpt_net/tools/image_viewer/__init__.py +10 -4
  136. pygpt_net/tools/indexer/__init__.py +8 -7
  137. pygpt_net/tools/media_player/__init__.py +4 -3
  138. pygpt_net/tools/text_editor/__init__.py +36 -10
  139. pygpt_net/ui/layout/chat/output.py +2 -2
  140. pygpt_net/ui/layout/ctx/ctx_list.py +1 -1
  141. pygpt_net/ui/menu/audio.py +12 -1
  142. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.43.dist-info}/METADATA +143 -71
  143. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.43.dist-info}/RECORD +146 -138
  144. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.43.dist-info}/LICENSE +0 -0
  145. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.43.dist-info}/WHEEL +0 -0
  146. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.43.dist-info}/entry_points.txt +0 -0
@@ -6,11 +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.03.06 02:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
+ from typing import Dict, Any, Optional
13
+
12
14
  from packaging.version import Version
13
15
 
16
+ from pygpt_net.item.index import IndexItem
14
17
  from pygpt_net.provider.core.index.base import BaseProvider
15
18
  from .patch import Patch
16
19
  from .storage import Storage
@@ -42,7 +45,10 @@ class DbSqliteProvider(BaseProvider):
42
45
  """
43
46
  return self.patcher.execute(version)
44
47
 
45
- def load(self, store_id: str) -> dict:
48
+ def load(
49
+ self,
50
+ store_id: str
51
+ ) -> Dict[str, IndexItem]:
46
52
  """
47
53
  Load items for index provider
48
54
 
@@ -51,7 +57,12 @@ class DbSqliteProvider(BaseProvider):
51
57
  """
52
58
  return self.storage.get_items(store_id)
53
59
 
54
- def append_file(self, store_id: str, idx: str, data: dict) -> int:
60
+ def append_file(
61
+ self,
62
+ store_id: str,
63
+ idx: str,
64
+ data: Dict[str, Any]
65
+ ) -> int:
55
66
  """
56
67
  Append file to index
57
68
 
@@ -62,7 +73,13 @@ class DbSqliteProvider(BaseProvider):
62
73
  """
63
74
  return self.storage.insert_file(store_id, idx, data)
64
75
 
65
- def append_ctx_meta(self, store_id: str, idx: str, meta_id: int, doc_id: str) -> int:
76
+ def append_ctx_meta(
77
+ self,
78
+ store_id: str,
79
+ idx: str,
80
+ meta_id: int,
81
+ doc_id: str
82
+ ) -> int:
66
83
  """
67
84
  Append context meta to index
68
85
 
@@ -74,7 +91,12 @@ class DbSqliteProvider(BaseProvider):
74
91
  """
75
92
  return self.storage.insert_ctx_meta(store_id, idx, meta_id, doc_id)
76
93
 
77
- def append_external(self, store_id: str, idx: str, data: dict) -> int:
94
+ def append_external(
95
+ self,
96
+ store_id: str,
97
+ idx: str,
98
+ data: Dict[str, Any]
99
+ ) -> int:
78
100
  """
79
101
  Append external data to index
80
102
 
@@ -85,7 +107,12 @@ class DbSqliteProvider(BaseProvider):
85
107
  """
86
108
  return self.storage.insert_external(store_id, idx, data)
87
109
 
88
- def is_meta_indexed(self, store_id: str, idx: str, meta_id: int) -> bool:
110
+ def is_meta_indexed(
111
+ self,
112
+ store_id: str,
113
+ idx: str,
114
+ meta_id: int
115
+ ) -> bool:
89
116
  """
90
117
  Check if context meta is indexed
91
118
 
@@ -96,7 +123,12 @@ class DbSqliteProvider(BaseProvider):
96
123
  """
97
124
  return self.storage.is_meta_indexed(store_id, idx, meta_id)
98
125
 
99
- def is_file_indexed(self, store_id: str, idx: str, file_id: str) -> bool:
126
+ def is_file_indexed(
127
+ self,
128
+ store_id: str,
129
+ idx: str,
130
+ file_id: str
131
+ ) -> bool:
100
132
  """
101
133
  Check if file is indexed
102
134
 
@@ -107,7 +139,13 @@ class DbSqliteProvider(BaseProvider):
107
139
  """
108
140
  return self.storage.is_file_indexed(store_id, idx, file_id)
109
141
 
110
- def is_external_indexed(self, store_id: str, idx: str, content: str, type: str) -> bool:
142
+ def is_external_indexed(
143
+ self,
144
+ store_id: str,
145
+ idx: str,
146
+ content: str,
147
+ type: str
148
+ ) -> bool:
111
149
  """
112
150
  Check if external data is indexed
113
151
 
@@ -119,7 +157,12 @@ class DbSqliteProvider(BaseProvider):
119
157
  """
120
158
  return self.storage.is_external_indexed(store_id, idx, content, type)
121
159
 
122
- def get_meta_doc_id(self, store_id: str, idx: str, meta_id: int) -> str:
160
+ def get_meta_doc_id(
161
+ self,
162
+ store_id: str,
163
+ idx: str,
164
+ meta_id: int
165
+ ) -> str:
123
166
  """
124
167
  Get indexed document id by meta id
125
168
 
@@ -130,7 +173,12 @@ class DbSqliteProvider(BaseProvider):
130
173
  """
131
174
  return self.storage.get_meta_doc_id(store_id, idx, meta_id)
132
175
 
133
- def get_file_doc_id(self, store_id: str, idx: str, file_id: str) -> str:
176
+ def get_file_doc_id(
177
+ self,
178
+ store_id: str,
179
+ idx: str,
180
+ file_id: str
181
+ ) -> str:
134
182
  """
135
183
  Get indexed document id by file id
136
184
 
@@ -141,7 +189,13 @@ class DbSqliteProvider(BaseProvider):
141
189
  """
142
190
  return self.storage.get_file_doc_id(store_id, idx, file_id)
143
191
 
144
- def get_external_doc_id(self, store_id: str, idx: str, content: str, type: str) -> str:
192
+ def get_external_doc_id(
193
+ self,
194
+ store_id: str,
195
+ idx: str,
196
+ content: str,
197
+ type: str
198
+ ) -> str:
145
199
  """
146
200
  Get indexed document id by file id
147
201
 
@@ -153,7 +207,12 @@ class DbSqliteProvider(BaseProvider):
153
207
  """
154
208
  return self.storage.get_external_doc_id(store_id, idx, content, type)
155
209
 
156
- def update_file(self, id: int, doc_id: str, ts: int) -> bool:
210
+ def update_file(
211
+ self,
212
+ id: int,
213
+ doc_id: str,
214
+ ts: int
215
+ ) -> bool:
157
216
  """
158
217
  Update indexed timestamp of indexed file
159
218
 
@@ -163,7 +222,11 @@ class DbSqliteProvider(BaseProvider):
163
222
  """
164
223
  return self.storage.update_file(id, doc_id, ts)
165
224
 
166
- def update_ctx_meta(self, meta_id: int, doc_id: str) -> bool:
225
+ def update_ctx_meta(
226
+ self,
227
+ meta_id: int,
228
+ doc_id: str
229
+ ) -> bool:
167
230
  """
168
231
  Update indexed timestamp of indexed context meta
169
232
 
@@ -172,7 +235,13 @@ class DbSqliteProvider(BaseProvider):
172
235
  """
173
236
  return self.storage.update_ctx_meta(meta_id, doc_id)
174
237
 
175
- def update_external(self, content: str, type: str, doc_id: str, ts: int) -> bool:
238
+ def update_external(
239
+ self,
240
+ content: str,
241
+ type: str,
242
+ doc_id: str,
243
+ ts: int
244
+ ) -> bool:
176
245
  """
177
246
  Update indexed timestamp of indexed external
178
247
 
@@ -183,7 +252,12 @@ class DbSqliteProvider(BaseProvider):
183
252
  """
184
253
  return self.storage.update_external(content, type, doc_id, ts)
185
254
 
186
- def remove_file(self, store_id: str, idx: str, doc_id: str):
255
+ def remove_file(
256
+ self,
257
+ store_id: str,
258
+ idx: str,
259
+ doc_id: str
260
+ ):
187
261
  """
188
262
  Remove file from index
189
263
 
@@ -193,7 +267,12 @@ class DbSqliteProvider(BaseProvider):
193
267
  """
194
268
  self.storage.remove_file(store_id, idx, doc_id)
195
269
 
196
- def remove_ctx_meta(self, store_id: str, idx: str, meta_id: str):
270
+ def remove_ctx_meta(
271
+ self,
272
+ store_id: str,
273
+ idx: str,
274
+ meta_id: str
275
+ ):
197
276
  """
198
277
  Remove file from index
199
278
 
@@ -203,7 +282,12 @@ class DbSqliteProvider(BaseProvider):
203
282
  """
204
283
  self.storage.remove_ctx_meta(store_id, idx, meta_id)
205
284
 
206
- def remove_external(self, store_id: str, idx: str, doc_id: str):
285
+ def remove_external(
286
+ self,
287
+ store_id: str,
288
+ idx: str,
289
+ doc_id: str
290
+ ):
207
291
  """
208
292
  Remove external from index
209
293
 
@@ -213,7 +297,11 @@ class DbSqliteProvider(BaseProvider):
213
297
  """
214
298
  self.storage.remove_external(store_id, idx, doc_id)
215
299
 
216
- def truncate(self, store_id: str, idx: str) -> bool:
300
+ def truncate(
301
+ self,
302
+ store_id: str,
303
+ idx: str
304
+ ) -> bool:
217
305
  """
218
306
  Truncate idx (remove all items)
219
307
 
@@ -223,7 +311,11 @@ class DbSqliteProvider(BaseProvider):
223
311
  """
224
312
  return self.storage.truncate_all(store_id, idx)
225
313
 
226
- def truncate_all(self, store_id: str = None, idx: str = None) -> bool:
314
+ def truncate_all(
315
+ self,
316
+ store_id: Optional[str] = None,
317
+ idx: Optional[str] = None
318
+ ) -> bool:
227
319
  """
228
320
  Truncate idx (remove all items) - all store and indexes
229
321
 
@@ -233,7 +325,11 @@ class DbSqliteProvider(BaseProvider):
233
325
  """
234
326
  return self.storage.truncate_all(store_id, idx)
235
327
 
236
- def truncate_files(self, store_id: str = None, idx: str = None) -> bool:
328
+ def truncate_files(
329
+ self,
330
+ store_id: Optional[str] = None,
331
+ idx: Optional[str] = None
332
+ ) -> bool:
237
333
  """
238
334
  Truncate files idx (remove all items) - all store and indexes
239
335
 
@@ -243,7 +339,11 @@ class DbSqliteProvider(BaseProvider):
243
339
  """
244
340
  return self.storage.truncate_files(store_id, idx)
245
341
 
246
- def truncate_ctx(self, store_id: str = None, idx: str = None) -> bool:
342
+ def truncate_ctx(
343
+ self,
344
+ store_id: Optional[str] = None,
345
+ idx: Optional[str] = None
346
+ ) -> bool:
247
347
  """
248
348
  Truncate context meta idx (remove all items) - all store and indexes
249
349
 
@@ -253,7 +353,11 @@ class DbSqliteProvider(BaseProvider):
253
353
  """
254
354
  return self.storage.truncate_ctx(store_id, idx)
255
355
 
256
- def truncate_external(self, store_id: str = None, idx: str = None) -> bool:
356
+ def truncate_external(
357
+ self,
358
+ store_id: Optional[str] = None,
359
+ idx: Optional[str] = None
360
+ ) -> bool:
257
361
  """
258
362
  Truncate external idx (remove all items) - all store and indexes
259
363
 
@@ -263,7 +367,10 @@ class DbSqliteProvider(BaseProvider):
263
367
  """
264
368
  return self.storage.truncate_external(store_id, idx)
265
369
 
266
- def get_counters(self, type: str) -> dict:
370
+ def get_counters(
371
+ self,
372
+ type: str
373
+ ) -> Dict[str, Dict[str, int]]:
267
374
  """
268
375
  Get counters (stats, count items by type [file, ctx, external])
269
376
 
@@ -6,13 +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.03.06 02:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import uuid
13
13
  import time
14
+ from typing import Dict, Optional
14
15
 
15
16
  from sqlalchemy import text
17
+ from traitlets import Any
16
18
 
17
19
  from pygpt_net.item.index import IndexItem
18
20
  from .utils import unpack_file_item
@@ -35,7 +37,10 @@ class Storage:
35
37
  """
36
38
  self.window = window
37
39
 
38
- def get_items(self, store_id: str) -> dict:
40
+ def get_items(
41
+ self,
42
+ store_id: str
43
+ ) -> Dict[str, IndexItem]:
39
44
  """
40
45
  Return idx items by store ID
41
46
 
@@ -65,7 +70,12 @@ class Storage:
65
70
 
66
71
  return indexes
67
72
 
68
- def insert_file(self, store_id: str, idx: str, data: dict) -> int:
73
+ def insert_file(
74
+ self,
75
+ store_id: str,
76
+ idx: str,
77
+ data: Dict[str, Any]
78
+ ) -> int:
69
79
  """
70
80
  Insert file to index
71
81
 
@@ -114,7 +124,13 @@ class Storage:
114
124
 
115
125
  return id
116
126
 
117
- def insert_ctx_meta(self, store_id: str, idx: str, meta_id: int, doc_id: str) -> int:
127
+ def insert_ctx_meta(
128
+ self,
129
+ store_id: str,
130
+ idx: str,
131
+ meta_id: int,
132
+ doc_id: str
133
+ ) -> int:
118
134
  """
119
135
  Insert ctx meta to index
120
136
 
@@ -162,7 +178,12 @@ class Storage:
162
178
 
163
179
  return id
164
180
 
165
- def insert_external(self, store_id: str, idx: str, data: dict) -> int:
181
+ def insert_external(
182
+ self,
183
+ store_id: str,
184
+ idx: str,
185
+ data: Dict[str, Any]
186
+ ) -> int:
166
187
  """
167
188
  Insert external data to index
168
189
 
@@ -211,7 +232,12 @@ class Storage:
211
232
 
212
233
  return id
213
234
 
214
- def is_meta_indexed(self, store_id: str, idx: str, meta_id: int) -> bool:
235
+ def is_meta_indexed(
236
+ self,
237
+ store_id: str,
238
+ idx: str,
239
+ meta_id: int
240
+ ) -> bool:
215
241
  """
216
242
  Check if context meta is indexed
217
243
 
@@ -238,7 +264,12 @@ class Storage:
238
264
  data = row._asdict()
239
265
  return int(data['count']) > 0
240
266
 
241
- def is_file_indexed(self, store_id: str, idx: str, file_id: str) -> bool:
267
+ def is_file_indexed(
268
+ self,
269
+ store_id: str,
270
+ idx: str,
271
+ file_id: str
272
+ ) -> bool:
242
273
  """
243
274
  Check if file is indexed
244
275
 
@@ -265,7 +296,13 @@ class Storage:
265
296
  data = row._asdict()
266
297
  return int(data['count']) > 0
267
298
 
268
- def is_external_indexed(self, store_id: str, idx: str, content: str, type: str) -> bool:
299
+ def is_external_indexed(
300
+ self,
301
+ store_id: str,
302
+ idx: str,
303
+ content: str,
304
+ type: str
305
+ ) -> bool:
269
306
  """
270
307
  Check if external is indexed
271
308
 
@@ -295,7 +332,12 @@ class Storage:
295
332
  data = row._asdict()
296
333
  return int(data['count']) > 0
297
334
 
298
- def get_meta_doc_id(self, store_id: str, idx: str, meta_id: int) -> str:
335
+ def get_meta_doc_id(
336
+ self,
337
+ store_id: str,
338
+ idx: str,
339
+ meta_id: int
340
+ ) -> str:
299
341
  """
300
342
  Get indexed document id by meta id
301
343
 
@@ -322,7 +364,12 @@ class Storage:
322
364
  data = row._asdict()
323
365
  return data['doc_id']
324
366
 
325
- def get_file_doc_id(self, store_id: str, idx: str, file_id: str) -> str:
367
+ def get_file_doc_id(
368
+ self,
369
+ store_id: str,
370
+ idx: str,
371
+ file_id: str
372
+ ) -> str:
326
373
  """
327
374
  Get indexed document id by file id
328
375
 
@@ -349,7 +396,13 @@ class Storage:
349
396
  data = row._asdict()
350
397
  return data['doc_id']
351
398
 
352
- def get_external_doc_id(self, store_id: str, idx: str, content: str, type: str) -> str:
399
+ def get_external_doc_id(
400
+ self,
401
+ store_id: str,
402
+ idx: str,
403
+ content: str,
404
+ type: str
405
+ ) -> str:
353
406
  """
354
407
  Get indexed document id by external
355
408
 
@@ -379,7 +432,12 @@ class Storage:
379
432
  data = row._asdict()
380
433
  return data['doc_id']
381
434
 
382
- def update_file(self, id: int, doc_id: str, ts: int) -> bool:
435
+ def update_file(
436
+ self,
437
+ id: int,
438
+ doc_id: str,
439
+ ts: int
440
+ ) -> bool:
383
441
  """
384
442
  Update timestamp of file in index
385
443
 
@@ -403,7 +461,11 @@ class Storage:
403
461
  conn.execute(stmt)
404
462
  return True
405
463
 
406
- def update_ctx_meta(self, meta_id: int, doc_id: str) -> bool:
464
+ def update_ctx_meta(
465
+ self,
466
+ meta_id: int,
467
+ doc_id: str
468
+ ) -> bool:
407
469
  """
408
470
  Update timestamp of ctx meta in index
409
471
 
@@ -427,7 +489,13 @@ class Storage:
427
489
  conn.execute(stmt)
428
490
  return True
429
491
 
430
- def update_external(self, content: str, type: str, doc_id: str, ts: int) -> bool:
492
+ def update_external(
493
+ self,
494
+ content: str,
495
+ type: str,
496
+ doc_id: str,
497
+ ts: int
498
+ ) -> bool:
431
499
  """
432
500
  Update timestamp of external data in index
433
501
 
@@ -454,7 +522,12 @@ class Storage:
454
522
  conn.execute(stmt)
455
523
  return True
456
524
 
457
- def remove_file(self, store_id: str, idx: str, doc_id: str):
525
+ def remove_file(
526
+ self,
527
+ store_id: str,
528
+ idx: str,
529
+ doc_id: str
530
+ ):
458
531
  """
459
532
  Remove file from index
460
533
 
@@ -471,7 +544,12 @@ class Storage:
471
544
  doc_id=doc_id,
472
545
  ))
473
546
 
474
- def remove_ctx_meta(self, store_id: str, idx: str, meta_id: str):
547
+ def remove_ctx_meta(
548
+ self,
549
+ store_id: str,
550
+ idx: str,
551
+ meta_id: str
552
+ ):
475
553
  """
476
554
  Remove file from index
477
555
 
@@ -488,7 +566,12 @@ class Storage:
488
566
  meta_id=meta_id,
489
567
  ))
490
568
 
491
- def remove_external(self, store_id: str, idx: str, doc_id: str):
569
+ def remove_external(
570
+ self,
571
+ store_id: str,
572
+ idx: str,
573
+ doc_id: str
574
+ ):
492
575
  """
493
576
  Remove file from index
494
577
 
@@ -505,7 +588,11 @@ class Storage:
505
588
  doc_id=doc_id,
506
589
  ))
507
590
 
508
- def truncate_all(self, store_id: str = None, idx: str = None) -> bool:
591
+ def truncate_all(
592
+ self,
593
+ store_id: Optional[str] = None,
594
+ idx: Optional[str] = None
595
+ ) -> bool:
509
596
  """
510
597
  Truncate all idx tables in database (all stores)
511
598
 
@@ -518,7 +605,11 @@ class Storage:
518
605
  self.truncate_external(store_id, idx)
519
606
  return True
520
607
 
521
- def truncate_files(self, store_id: str = None, idx: str = None) -> bool:
608
+ def truncate_files(
609
+ self,
610
+ store_id: Optional[str] = None,
611
+ idx: Optional[str] = None
612
+ ) -> bool:
522
613
  """
523
614
  Truncate files table in database
524
615
 
@@ -528,7 +619,11 @@ class Storage:
528
619
  """
529
620
  return self.truncate_by_db_table("idx_file", store_id, idx)
530
621
 
531
- def truncate_ctx(self, store_id: str = None, idx: str = None) -> bool:
622
+ def truncate_ctx(
623
+ self,
624
+ store_id: Optional[str] = None,
625
+ idx: Optional[str] = None
626
+ ) -> bool:
532
627
  """
533
628
  Truncate context table in database
534
629
 
@@ -538,7 +633,11 @@ class Storage:
538
633
  """
539
634
  return self.truncate_by_db_table("idx_ctx", store_id, idx)
540
635
 
541
- def truncate_external(self, store_id: str = None, idx: str = None) -> bool:
636
+ def truncate_external(
637
+ self,
638
+ store_id: Optional[str] = None,
639
+ idx: Optional[str] = None
640
+ ) -> bool:
542
641
  """
543
642
  Truncate external table in database
544
643
 
@@ -548,7 +647,12 @@ class Storage:
548
647
  """
549
648
  return self.truncate_by_db_table("idx_external", store_id, idx)
550
649
 
551
- def truncate_by_db_table(self, tbl: str, store_id: str = None, idx: str = None) -> bool:
650
+ def truncate_by_db_table(
651
+ self,
652
+ tbl: str,
653
+ store_id: Optional[str] = None,
654
+ idx: Optional[str] = None
655
+ ) -> bool:
552
656
  """
553
657
  Truncate external table in database
554
658
 
@@ -574,7 +678,10 @@ class Storage:
574
678
  text(query).bindparams(**params))
575
679
  return True
576
680
 
577
- def get_counters(self, type: str) -> dict:
681
+ def get_counters(
682
+ self,
683
+ type: str
684
+ ) -> Dict[str, Dict[str, int]]:
578
685
  """
579
686
  Get counters (stats, count items by type [file, ctx, external])
580
687
 
@@ -6,13 +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.03.06 02:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
+ from typing import Tuple, Dict, Any
13
+
12
14
  from pygpt_net.utils import unpack_var
13
15
 
14
16
 
15
- def unpack_file_item(row: dict) -> (str, dict):
17
+ def unpack_file_item(row: Dict[str, Any]) -> Tuple[str, dict]:
16
18
  """
17
19
  Unpack item from DB row
18
20
 
@@ -6,9 +6,11 @@
6
6
  # GitHub: https://github.com/szczyglis-dev/py-gpt #
7
7
  # MIT License #
8
8
  # Created By : Marcin Szczygliński #
9
- # Updated Date: 2023.12.31 04:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
+ from typing import Dict
13
+
12
14
  from pygpt_net.item.mode import ModeItem
13
15
 
14
16
 
@@ -24,10 +26,10 @@ class BaseProvider:
24
26
  def create(self, mode: ModeItem) -> str:
25
27
  pass
26
28
 
27
- def load(self) -> dict:
29
+ def load(self) -> Dict[str, str]:
28
30
  pass
29
31
 
30
- def save(self, items: dict):
32
+ def save(self, items: Dict[str, str]):
31
33
  pass
32
34
 
33
35
  def remove(self, id: str):