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,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.12.09 00:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  from datetime import datetime
13
13
  import re
14
14
  import time
15
+ from typing import Dict, Optional, Tuple, List
15
16
 
16
17
  from sqlalchemy import text
17
18
 
@@ -46,11 +47,11 @@ class Storage:
46
47
 
47
48
  def prepare_query(
48
49
  self,
49
- search_string: str = None,
50
- filters: dict = None,
50
+ search_string: Optional[str] = None,
51
+ filters: Optional[dict] = None,
51
52
  search_content: bool = False,
52
53
  append_date_ranges: bool = True,
53
- ):
54
+ ) -> Tuple[str, str, dict]:
54
55
  """
55
56
  Prepare query for search_string and filters
56
57
 
@@ -67,6 +68,9 @@ class Storage:
67
68
  # only base by default
68
69
  where_clauses.append("(m.root_id IS NULL OR m.root_id = 0)")
69
70
 
71
+ # join group
72
+ join_clauses.append("LEFT JOIN ctx_group g ON m.group_id = g.id")
73
+
70
74
  # search_string
71
75
  if search_string:
72
76
  date_ranges = search_by_date_string(search_string)
@@ -105,15 +109,16 @@ class Storage:
105
109
  continue
106
110
  mode = filter.get('mode', '=')
107
111
  value = filter.get('value', '')
112
+ key_name = 'm.' + key
108
113
  if isinstance(value, int):
109
- where_clauses.append(f"{key} {mode} :{key}")
114
+ where_clauses.append(f"{key_name} {mode} :{key}")
110
115
  bind_params[key] = value
111
116
  elif isinstance(value, str):
112
- where_clauses.append(f"{key} {mode} :{key}")
117
+ where_clauses.append(f"{key_name} {mode} :{key}")
113
118
  bind_params[key] = f"%{value}%"
114
119
  elif isinstance(value, list):
115
120
  values = "(" + ",".join([str(x) for x in value]) + ")"
116
- where_clauses.append(f"{key} {mode} {values}")
121
+ where_clauses.append(f"{key_name} {mode} {values}")
117
122
 
118
123
  where_statement = " AND ".join(where_clauses) if where_clauses else "1"
119
124
  join_statement = " ".join(join_clauses) if join_clauses else ""
@@ -122,14 +127,14 @@ class Storage:
122
127
 
123
128
  def get_meta(
124
129
  self,
125
- search_string: str = None,
126
- order_by: str = None,
127
- order_direction: str = None,
128
- limit: int = None,
129
- offset: int = None,
130
- filters: dict = None,
130
+ search_string: Optional[str] = None,
131
+ order_by: Optional[str] = None,
132
+ order_direction: Optional[str] = None,
133
+ limit: Optional[int] = None,
134
+ offset: Optional[int] = None,
135
+ filters: Optional[dict] = None,
131
136
  search_content: bool = False,
132
- ) -> dict:
137
+ ) -> Dict[int, CtxMeta]:
133
138
  """
134
139
  Return dict with CtxMeta objects, indexed by ID
135
140
 
@@ -153,8 +158,18 @@ class Storage:
153
158
  append_date_ranges=True,
154
159
  )
155
160
  stmt_text = f"""
156
- SELECT m.* FROM ctx_meta m {join_statement} WHERE {where_statement}
157
- ORDER BY m.updated_ts DESC {limit_suffix}
161
+ SELECT
162
+ m.*,
163
+ g.name as group_name,
164
+ g.uuid as group_uuid,
165
+ g.additional_ctx_json as group_additional_ctx_json
166
+ FROM
167
+ ctx_meta m
168
+ {join_statement}
169
+ WHERE
170
+ {where_statement}
171
+ ORDER BY
172
+ m.updated_ts DESC {limit_suffix}
158
173
  """
159
174
  stmt = text(stmt_text).bindparams(**bind_params)
160
175
 
@@ -169,14 +184,24 @@ class Storage:
169
184
 
170
185
  return items
171
186
 
172
- def get_meta_indexed(self) -> dict:
187
+ def get_meta_indexed(self) -> Dict[int, CtxMeta]:
173
188
  """
174
189
  Return dict with indexed CtxMeta objects, indexed by ID
175
190
 
176
191
  :return: dict of CtxMeta
177
192
  """
178
193
  stmt_text = f"""
179
- SELECT * FROM ctx_meta WHERE indexed_ts > 0
194
+ SELECT
195
+ m.*,
196
+ g.name as group_name,
197
+ g.uuid as group_uuid,
198
+ g.additional_ctx_json as group_additional_ctx_json
199
+ FROM
200
+ ctx_meta m
201
+ LEFT JOIN
202
+ ctx_group g ON m.group_id = g.id
203
+ WHERE
204
+ indexed_ts > 0
180
205
  """
181
206
  stmt = text(stmt_text)
182
207
  items = {}
@@ -189,7 +214,7 @@ class Storage:
189
214
  items[meta.id] = meta
190
215
  return items
191
216
 
192
- def get_item_by_id(self, id: int) -> CtxItem:
217
+ def get_item_by_id(self, id: int) -> Optional[CtxItem]:
193
218
  """
194
219
  Return ctx item by ID
195
220
 
@@ -210,7 +235,11 @@ class Storage:
210
235
  return item
211
236
  return None
212
237
 
213
- def get_meta_by_root_id_and_preset_id(self, root_id: int, preset_id: str) -> dict:
238
+ def get_meta_by_root_id_and_preset_id(
239
+ self,
240
+ root_id: int,
241
+ preset_id: str
242
+ ) -> Dict[int, CtxMeta]:
214
243
  """
215
244
  Return dict with indexed CtxMeta objects, indexed by ID
216
245
 
@@ -233,7 +262,7 @@ class Storage:
233
262
  items[meta.id] = meta
234
263
  return items
235
264
 
236
- def get_meta_by_id(self, id: int) -> CtxMeta or None:
265
+ def get_meta_by_id(self, id: int) -> Optional[CtxMeta]:
237
266
  """
238
267
  Return ctx meta by ID
239
268
 
@@ -269,7 +298,7 @@ class Storage:
269
298
  return int(row.id)
270
299
  return 0
271
300
 
272
- def get_items(self, id: int) -> list:
301
+ def get_items(self, id: int) -> List[CtxItem]:
273
302
  """
274
303
  Return ctx items list by ctx meta ID
275
304
 
@@ -426,9 +455,32 @@ class Storage:
426
455
  )
427
456
  with db.begin() as conn:
428
457
  conn.execute(stmt)
429
- return True
430
458
 
431
- def update_meta_all(self, meta: CtxMeta, items: list) -> bool:
459
+ # update group
460
+ if meta.group:
461
+ stmt = text("""
462
+ UPDATE ctx_group
463
+ SET
464
+ name = :name,
465
+ additional_ctx_json = :additional_ctx_json,
466
+ updated_ts = :updated_ts
467
+ WHERE id = :id
468
+ """).bindparams(
469
+ id=meta.group.id,
470
+ name=meta.group.name,
471
+ additional_ctx_json=pack_item_value(meta.group.additional_ctx),
472
+ updated_ts=int(time.time()),
473
+ )
474
+ with db.begin() as conn:
475
+ conn.execute(stmt)
476
+
477
+ return True
478
+
479
+ def update_meta_all(
480
+ self,
481
+ meta: CtxMeta,
482
+ items: List[CtxItem]
483
+ ) -> bool:
432
484
  """
433
485
  Update all, meta and items
434
486
 
@@ -891,12 +943,12 @@ class Storage:
891
943
  def get_ctx_count_by_day(
892
944
  self,
893
945
  year: int,
894
- month: int = None,
895
- day: int = None,
896
- search_string: str = None,
897
- filters: dict = None,
946
+ month: Optional[int] = None,
947
+ day: Optional[int] = None,
948
+ search_string: Optional[str] = None,
949
+ filters: Optional[dict] = None,
898
950
  search_content: bool = False,
899
- ) -> dict:
951
+ ) -> Dict[str, int]:
900
952
  """
901
953
  Return ctx counters by day for given year and month
902
954
 
@@ -987,12 +1039,12 @@ class Storage:
987
1039
  def get_ctx_labels_count_by_day(
988
1040
  self,
989
1041
  year: int,
990
- month: int = None,
991
- day: int = None,
992
- search_string: str = None,
993
- filters: dict = None,
1042
+ month: Optional[int] = None,
1043
+ day: Optional[int] = None,
1044
+ search_string: Optional[str] = None,
1045
+ filters: Optional[dict] = None,
994
1046
  search_content: bool = False,
995
- ) -> dict:
1047
+ ) -> Dict[str, Dict[int, int]]:
996
1048
  """
997
1049
  Return ctx counters by day for given year and month
998
1050
 
@@ -1116,7 +1168,7 @@ class Storage:
1116
1168
 
1117
1169
  return result_dict
1118
1170
 
1119
- def get_groups(self) -> dict:
1171
+ def get_groups(self) -> Dict[int, CtxGroup]:
1120
1172
  """
1121
1173
  Return dict with CtxGroup objects, indexed by ID
1122
1174
 
@@ -1189,16 +1241,17 @@ class Storage:
1189
1241
  conn.execute(text("DELETE FROM sqlite_sequence WHERE name='ctx_group'"))
1190
1242
  return True
1191
1243
 
1192
- def clear_meta(self, meta_id: int):
1244
+ def clear_meta(self, meta_id: int) -> bool:
1193
1245
  """
1194
1246
  Delete all items with meta ID
1195
1247
 
1196
1248
  :param meta_id: meta ID
1197
- :return:
1249
+ :return: True if cleared
1198
1250
  """
1199
1251
  db = self.window.core.db.get_db()
1200
1252
  with db.begin() as conn:
1201
1253
  conn.execute(text(f"DELETE FROM ctx_item WHERE meta_id = {meta_id}"))
1254
+ return True
1202
1255
 
1203
1256
  def update_group(self, group: CtxGroup) -> bool:
1204
1257
  """
@@ -1258,12 +1311,13 @@ class Storage:
1258
1311
  group.id = result.lastrowid
1259
1312
  return group.id
1260
1313
 
1261
- def update_meta_group_id(self, meta_id: int, group_id: int = None):
1314
+ def update_meta_group_id(self, meta_id: int, group_id: int = None) -> bool:
1262
1315
  """
1263
1316
  Update meta group ID
1264
1317
 
1265
1318
  :param meta_id: ctx meta ID
1266
1319
  :param group_id: ctx group ID
1320
+ :return: True if updated
1267
1321
  """
1268
1322
  db = self.window.core.db.get_db()
1269
1323
  stmt = text("""
@@ -6,18 +6,20 @@
6
6
  # GitHub: https://github.com/szczyglis-dev/py-gpt #
7
7
  # MIT License #
8
8
  # Created By : Marcin Szczygliński #
9
- # Updated Date: 2024.11.26 19:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import json
13
13
  import re
14
+
14
15
  from datetime import datetime, timedelta
16
+ from typing import List, Tuple, Any, Dict
15
17
 
16
18
  from pygpt_net.item.ctx import CtxMeta, CtxItem, CtxGroup
17
19
  from pygpt_net.utils import unpack_var
18
20
 
19
21
 
20
- def search_by_date_string(search_string: str) -> list:
22
+ def search_by_date_string(search_string: str) -> List[Tuple[Any, Any]]:
21
23
  """
22
24
  Prepare date ranges from search string if @date() syntax is used
23
25
 
@@ -64,7 +66,7 @@ def search_by_date_string(search_string: str) -> list:
64
66
  return date_ranges
65
67
 
66
68
 
67
- def get_month_start_end_timestamps(year: int, month: int) -> (int, int):
69
+ def get_month_start_end_timestamps(year: int, month: int) -> Tuple[int, int]:
68
70
  """
69
71
  Get start and end timestamps for given month
70
72
 
@@ -82,7 +84,7 @@ def get_month_start_end_timestamps(year: int, month: int) -> (int, int):
82
84
  return start_timestamp, end_timestamp
83
85
 
84
86
 
85
- def get_year_start_end_timestamps(year: int) -> (int, int):
87
+ def get_year_start_end_timestamps(year: int) -> Tuple[int, int]:
86
88
  """
87
89
  Get start and end timestamps for given year
88
90
 
@@ -96,7 +98,7 @@ def get_year_start_end_timestamps(year: int) -> (int, int):
96
98
  return start_timestamp, end_timestamp
97
99
 
98
100
 
99
- def pack_item_value(value: any) -> str:
101
+ def pack_item_value(value: Any) -> str:
100
102
  """
101
103
  Pack item value to JSON
102
104
 
@@ -108,7 +110,7 @@ def pack_item_value(value: any) -> str:
108
110
  return value
109
111
 
110
112
 
111
- def unpack_item_value(value: any) -> any:
113
+ def unpack_item_value(value: Any) -> Any:
112
114
  """
113
115
  Unpack item value from JSON
114
116
 
@@ -123,7 +125,10 @@ def unpack_item_value(value: any) -> any:
123
125
  return value
124
126
 
125
127
 
126
- def unpack_item(item: CtxItem, row: dict) -> CtxItem:
128
+ def unpack_item(
129
+ item: CtxItem,
130
+ row: Dict[str, Any]
131
+ ) -> CtxItem:
127
132
  """
128
133
  Unpack context item from DB row
129
134
 
@@ -183,9 +188,12 @@ def unpack_item(item: CtxItem, row: dict) -> CtxItem:
183
188
  return item
184
189
 
185
190
 
186
- def unpack_meta(meta: CtxMeta, row: dict) -> CtxMeta:
191
+ def unpack_meta(
192
+ meta: CtxMeta,
193
+ row: Dict[str, Any]
194
+ ) -> CtxMeta:
187
195
  """
188
- Unpack context meta data from DB row
196
+ Unpack context meta-data from DB row
189
197
 
190
198
  :param meta: Context meta (CtxMeta)
191
199
  :param row: DB row
@@ -219,20 +227,38 @@ def unpack_meta(meta: CtxMeta, row: dict) -> CtxMeta:
219
227
 
220
228
  if meta.additional_ctx is None:
221
229
  meta.additional_ctx = []
230
+
231
+ # add group if exists
232
+ if meta.group_id:
233
+ group = CtxGroup()
234
+ group.id = meta.group_id
235
+ group.uuid = row['group_uuid']
236
+ group.name = row['group_name']
237
+ group.additional_ctx = unpack_item_value(row['group_additional_ctx_json'])
238
+ if group.additional_ctx is None:
239
+ group.additional_ctx = []
240
+ meta.group = group
241
+
222
242
  return meta
223
243
 
224
244
 
225
- def unpack_group(group: CtxGroup, row: dict) -> CtxGroup:
245
+ def unpack_group(
246
+ group: CtxGroup,
247
+ row: Dict[str, Any]
248
+ ) -> CtxGroup:
226
249
  """
227
250
  Unpack context group data from DB row
228
251
 
229
252
  :param group: Context group (CtxGroup)
230
253
  :param row: DB row
231
- :return: context meta
254
+ :return: context group
232
255
  """
233
256
  group.id = unpack_var(row['id'], 'int')
234
257
  group.uuid = row['uuid']
235
258
  group.created = unpack_var(row['created_ts'], 'int')
236
259
  group.updated = unpack_var(row['updated_ts'], 'int')
237
260
  group.name = row['name']
261
+ group.additional_ctx = unpack_item_value(row['additional_ctx_json'])
262
+ if group.additional_ctx is None:
263
+ group.additional_ctx = []
238
264
  return group
@@ -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: 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
 
14
16
  from pygpt_net.item.index import IndexItem
@@ -29,70 +31,174 @@ class BaseProvider:
29
31
  def patch(self, version: Version) -> bool:
30
32
  pass
31
33
 
32
- def load(self, store_id: str) -> dict:
34
+ def load(
35
+ self,
36
+ store_id: str
37
+ ) -> Dict[str, IndexItem]:
33
38
  pass
34
39
 
35
- def append_file(self, store_id: str, idx: str, data: dict) -> int:
40
+ def append_file(
41
+ self,
42
+ store_id: str,
43
+ idx: str,
44
+ data: Dict[str, Any]
45
+ ) -> int:
36
46
  pass
37
47
 
38
- def append_ctx_meta(self, store_id: str, idx: str, meta_id: int, doc_id: str) -> int:
48
+ def append_ctx_meta(
49
+ self,
50
+ store_id: str,
51
+ idx: str,
52
+ meta_id: int,
53
+ doc_id: str
54
+ ) -> int:
39
55
  pass
40
56
 
41
- def append_external(self, store_id: str, idx: str, data: dict) -> int:
57
+ def append_external(
58
+ self,
59
+ store_id: str,
60
+ idx: str,
61
+ data: Dict[str, Any]
62
+ ) -> int:
42
63
  pass
43
64
 
44
- def update_file(self, id: int, doc_id: str, ts: int) -> bool:
65
+ def update_file(
66
+ self,
67
+ id: int,
68
+ doc_id: str,
69
+ ts: int
70
+ ) -> bool:
45
71
  pass
46
72
 
47
- def update_ctx_meta(self, id: int, doc_id: str) -> bool:
73
+ def update_ctx_meta(
74
+ self,
75
+ id: int,
76
+ doc_id: str
77
+ ) -> bool:
48
78
  pass
49
79
 
50
- def update_external(self, content: str, type: str, doc_id: str, ts: int) -> bool:
80
+ def update_external(
81
+ self,
82
+ content: str,
83
+ type: str,
84
+ doc_id: str,
85
+ ts: int
86
+ ) -> bool:
51
87
  pass
52
88
 
53
- def is_meta_indexed(self, store_id: str, idx: str, meta_id: int) -> bool:
89
+ def is_meta_indexed(
90
+ self,
91
+ store_id: str,
92
+ idx: str,
93
+ meta_id: int
94
+ ) -> bool:
54
95
  pass
55
96
 
56
- def is_file_indexed(self, store_id: str, idx: str, file_id: str) -> bool:
97
+ def is_file_indexed(
98
+ self,
99
+ store_id: str,
100
+ idx: str,
101
+ file_id: str
102
+ ) -> bool:
57
103
  pass
58
104
 
59
- def is_external_indexed(self, store_id: str, idx: str, content: str, type: str) -> bool:
105
+ def is_external_indexed(
106
+ self,
107
+ store_id: str,
108
+ idx: str,
109
+ content: str,
110
+ type: str
111
+ ) -> bool:
60
112
  pass
61
113
 
62
- def get_meta_doc_id(self, store_id: str, idx: str, meta_id: int) -> str:
114
+ def get_meta_doc_id(
115
+ self,
116
+ store_id: str,
117
+ idx: str,
118
+ meta_id: int
119
+ ) -> str:
63
120
  pass
64
121
 
65
- def get_file_doc_id(self, store_id: str, idx: str, file_id: str) -> str:
122
+ def get_file_doc_id(
123
+ self,
124
+ store_id: str,
125
+ idx: str,
126
+ file_id: str
127
+ ) -> str:
66
128
  pass
67
129
 
68
- def get_external_doc_id(self, store_id: str, idx: str, content: str, type: str) -> str:
130
+ def get_external_doc_id(
131
+ self,
132
+ store_id: str,
133
+ idx: str,
134
+ content: str,
135
+ type: str
136
+ ) -> str:
69
137
  pass
70
138
 
71
- def remove_file(self, store_id: str, idx: str, doc_id: str):
139
+ def remove_file(
140
+ self,
141
+ store_id: str,
142
+ idx: str,
143
+ doc_id: str
144
+ ):
72
145
  pass
73
146
 
74
- def remove_external(self, store_id: str, idx: str, doc_id: str):
147
+ def remove_external(
148
+ self,
149
+ store_id: str,
150
+ idx: str,
151
+ doc_id: str
152
+ ):
75
153
  pass
76
154
 
77
- def remove_ctx_meta(self, store_id: str, idx: str, meta_id: str):
155
+ def remove_ctx_meta(
156
+ self,
157
+ store_id: str,
158
+ idx: str,
159
+ meta_id: str
160
+ ):
78
161
  pass
79
162
 
80
- def truncate(self, store_id: str, idx: str):
163
+ def truncate(
164
+ self,
165
+ store_id: str,
166
+ idx: str
167
+ ):
81
168
  pass
82
169
 
83
- def truncate_all(self, store_id: str = None, idx: str = None) -> bool:
170
+ def truncate_all(
171
+ self,
172
+ store_id: Optional[str] = None,
173
+ idx: Optional[str] = None
174
+ ) -> bool:
84
175
  pass
85
176
 
86
- def truncate_files(self, store_id: str = None, idx: str = None) -> bool:
177
+ def truncate_files(
178
+ self,
179
+ store_id: Optional[str] = None,
180
+ idx: Optional[str] = None
181
+ ) -> bool:
87
182
  pass
88
183
 
89
- def truncate_ctx(self, store_id: str = None, idx: str = None) -> bool:
184
+ def truncate_ctx(
185
+ self,
186
+ store_id: Optional[str] = None,
187
+ idx: Optional[str] = None
188
+ ) -> bool:
90
189
  pass
91
190
 
92
- def truncate_external(self, store_id: str = None, idx: str = None) -> bool:
191
+ def truncate_external(
192
+ self,
193
+ store_id: Optional[str] = None,
194
+ idx: Optional[str] = None
195
+ ) -> bool:
93
196
  pass
94
197
 
95
- def get_counters(self, type: str) -> dict:
198
+ def get_counters(
199
+ self,
200
+ type: str
201
+ ) -> Dict[str, Dict[str, int]]:
96
202
  pass
97
203
 
98
204
  def dump(self, index: IndexItem) -> str: