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,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.11.21 20:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
+ from typing import Optional, List, Dict
13
+
12
14
  from langchain_openai import OpenAI
13
15
  from langchain_openai import ChatOpenAI
14
16
 
@@ -33,7 +35,12 @@ class OpenAILLM(BaseLLM):
33
35
  self.id = "openai"
34
36
  self.type = [MODE_LANGCHAIN, MODE_LLAMA_INDEX, "embeddings"]
35
37
 
36
- def completion(self, window, model: ModelItem, stream: bool = False):
38
+ def completion(
39
+ self,
40
+ window,
41
+ model: ModelItem,
42
+ stream: bool = False
43
+ ):
37
44
  """
38
45
  Return LLM provider instance for completion
39
46
 
@@ -45,7 +52,12 @@ class OpenAILLM(BaseLLM):
45
52
  args = self.parse_args(model.langchain)
46
53
  return OpenAI(**args)
47
54
 
48
- def chat(self, window, model: ModelItem, stream: bool = False):
55
+ def chat(
56
+ self,
57
+ window,
58
+ model: ModelItem,
59
+ stream: bool = False
60
+ ):
49
61
  """
50
62
  Return LLM provider instance for chat
51
63
 
@@ -57,7 +69,12 @@ class OpenAILLM(BaseLLM):
57
69
  args = self.parse_args(model.langchain)
58
70
  return ChatOpenAI(**args)
59
71
 
60
- def llama(self, window, model: ModelItem, stream: bool = False) -> LlamaBaseLLM:
72
+ def llama(
73
+ self,
74
+ window,
75
+ model: ModelItem,
76
+ stream: bool = False
77
+ ) -> LlamaBaseLLM:
61
78
  """
62
79
  Return LLM provider instance for llama
63
80
 
@@ -69,7 +86,12 @@ class OpenAILLM(BaseLLM):
69
86
  args = self.parse_args(model.llama_index)
70
87
  return LlamaOpenAI(**args)
71
88
 
72
- def llama_multimodal(self, window, model: ModelItem, stream: bool = False) -> LlamaMultiModalLLM:
89
+ def llama_multimodal(
90
+ self,
91
+ window,
92
+ model: ModelItem,
93
+ stream: bool = False
94
+ ) -> LlamaMultiModalLLM:
73
95
  """
74
96
  Return multimodal LLM provider instance for llama
75
97
 
@@ -81,7 +103,11 @@ class OpenAILLM(BaseLLM):
81
103
  args = self.parse_args(model.llama_index)
82
104
  return LlamaOpenAIMultiModal(**args)
83
105
 
84
- def get_embeddings_model(self, window, config: list = None) -> BaseEmbedding:
106
+ def get_embeddings_model(
107
+ self,
108
+ window,
109
+ config: Optional[List[Dict]] = None
110
+ ) -> BaseEmbedding:
85
111
  """
86
112
  Return provider instance for embeddings
87
113
 
@@ -6,11 +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.11.23 00:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import hashlib
13
+ from typing import Optional, Tuple, List
13
14
 
15
+ from llama_index.core.indices.service_context import ServiceContext
14
16
  from llama_index.core.indices.base import BaseIndex
15
17
  from llama_index.core.indices.vector_store.base import VectorStoreIndex
16
18
 
@@ -31,7 +33,7 @@ class Storage:
31
33
  self.indexes = {}
32
34
  self.tmp_storage = TempProvider(window=window)
33
35
 
34
- def get_storage(self) -> BaseStore or None:
36
+ def get_storage(self) -> Optional[BaseStore]:
35
37
  """
36
38
  Get current vector store provider
37
39
 
@@ -44,7 +46,7 @@ class Storage:
44
46
  return None
45
47
  return self.storages[current]
46
48
 
47
- def get_tmp_storage(self) -> BaseStore or None:
49
+ def get_tmp_storage(self) -> Optional[TempProvider]:
48
50
  """
49
51
  Get temp vector store provider
50
52
 
@@ -52,16 +54,19 @@ class Storage:
52
54
  """
53
55
  return self.tmp_storage
54
56
 
55
- def get_ctx_idx_storage(self, path: str) -> BaseStore or None:
57
+ def get_ctx_idx_storage(self, path: str) -> CtxAttachmentProvider:
56
58
  """
57
59
  Get temp vector store provider
58
60
 
59
61
  :param path: Path to index on disk
60
62
  :return: vector store provider instance
61
63
  """
62
- return CtxAttachmentProvider(window=self.window, path=path)
64
+ return CtxAttachmentProvider(
65
+ window=self.window,
66
+ path=path
67
+ )
63
68
 
64
- def register(self, name: str, storage=None):
69
+ def register(self, name: str, storage: BaseStore):
65
70
  """
66
71
  Register vector store provider
67
72
 
@@ -71,7 +76,7 @@ class Storage:
71
76
  storage.attach(window=self.window)
72
77
  self.storages[name] = storage
73
78
 
74
- def get_ids(self) -> list:
79
+ def get_ids(self) -> List[str]:
75
80
  """
76
81
  Return all vector store providers IDs
77
82
 
@@ -79,7 +84,7 @@ class Storage:
79
84
  """
80
85
  return list(self.storages.keys())
81
86
 
82
- def exists(self, id: str = None) -> bool:
87
+ def exists(self, id: Optional[str] = None) -> bool:
83
88
  """
84
89
  Check if index exists
85
90
 
@@ -102,7 +107,11 @@ class Storage:
102
107
  raise Exception('Storage engine not found!')
103
108
  storage.create(id)
104
109
 
105
- def get(self, id: str, service_context=None) -> BaseIndex:
110
+ def get(
111
+ self,
112
+ id: str,
113
+ service_context: Optional[ServiceContext]
114
+ ) -> BaseIndex:
106
115
  """
107
116
  Get index instance
108
117
 
@@ -118,7 +127,11 @@ class Storage:
118
127
  service_context=service_context,
119
128
  )
120
129
 
121
- def store(self, id: str, index: BaseIndex = None):
130
+ def store(
131
+ self,
132
+ id: str,
133
+ index: Optional[BaseIndex] = None
134
+ ):
122
135
  """
123
136
  Store index
124
137
 
@@ -173,7 +186,11 @@ class Storage:
173
186
  doc_id=doc_id,
174
187
  )
175
188
 
176
- def get_tmp(self, identifier: str, service_context=None) -> (str, BaseIndex):
189
+ def get_tmp(
190
+ self,
191
+ identifier: str,
192
+ service_context: Optional[ServiceContext] = None
193
+ ) -> Tuple[str, BaseIndex]:
177
194
  """
178
195
  Get tmp index instance
179
196
 
@@ -191,7 +208,11 @@ class Storage:
191
208
  service_context=service_context,
192
209
  )
193
210
 
194
- def store_tmp(self, id: str, index: BaseIndex = None):
211
+ def store_tmp(
212
+ self,
213
+ id: str,
214
+ index: Optional[BaseIndex] = None
215
+ ):
195
216
  """
196
217
  Store index
197
218
 
@@ -228,7 +249,11 @@ class Storage:
228
249
  raise Exception('Storage engine not found!')
229
250
  storage.clean(id)
230
251
 
231
- def get_ctx_idx(self, path: str, service_context=None) -> (str, BaseIndex):
252
+ def get_ctx_idx(
253
+ self,
254
+ path: str,
255
+ service_context: Optional[ServiceContext] = None
256
+ ) -> BaseIndex:
232
257
  """
233
258
  Get context index instance
234
259
 
@@ -241,10 +266,15 @@ class Storage:
241
266
  if storage is None:
242
267
  raise Exception('Storage engine not found!')
243
268
  return storage.get(
269
+ id="",
244
270
  service_context=service_context,
245
271
  )
246
272
 
247
- def store_ctx_idx(self, path: str, index: BaseIndex = None):
273
+ def store_ctx_idx(
274
+ self,
275
+ path: str,
276
+ index: Optional[BaseIndex] = None
277
+ ):
248
278
  """
249
279
  Store context index
250
280
 
@@ -255,6 +285,7 @@ class Storage:
255
285
  if storage is None:
256
286
  raise Exception('Storage engine not found!')
257
287
  storage.store(
288
+ id="",
258
289
  index=index,
259
290
  )
260
291
 
@@ -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.08.20 19:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import os
13
13
  import shutil
14
+ from typing import Optional
14
15
 
15
16
  from llama_index.core.indices.base import BaseIndex
16
17
  from llama_index.core.indices.service_context import ServiceContext
@@ -31,7 +32,12 @@ class BaseStore:
31
32
  self.prefix = "" # prefix for index directory
32
33
  self.indexes = {}
33
34
 
34
- def index_from_store(self, vector_store, storage_context: StorageContext, service_context: ServiceContext = None):
35
+ def index_from_store(
36
+ self,
37
+ vector_store,
38
+ storage_context: StorageContext,
39
+ service_context: Optional[ServiceContext] = None
40
+ ):
35
41
  """
36
42
  Get index instance
37
43
 
@@ -74,7 +80,10 @@ class BaseStore:
74
80
  self.prefix + id,
75
81
  )
76
82
 
77
- def exists(self, id: str = None) -> bool:
83
+ def exists(
84
+ self,
85
+ id: Optional[str] = None
86
+ ) -> bool:
78
87
  """
79
88
  Check if index with id exists
80
89
 
@@ -94,7 +103,11 @@ class BaseStore:
94
103
  """
95
104
  pass
96
105
 
97
- def get(self, id: str, service_context: ServiceContext = None) -> BaseIndex:
106
+ def get(
107
+ self,
108
+ id: str,
109
+ service_context: Optional[ServiceContext] = None
110
+ ) -> BaseIndex:
98
111
  """
99
112
  Get index instance
100
113
 
@@ -104,7 +117,11 @@ class BaseStore:
104
117
  """
105
118
  pass
106
119
 
107
- def store(self, id: str, index: BaseIndex = None):
120
+ def store(
121
+ self,
122
+ id: str,
123
+ index: Optional[BaseIndex] = None
124
+ ):
108
125
  """
109
126
  Store/persist index
110
127
 
@@ -113,7 +130,10 @@ class BaseStore:
113
130
  """
114
131
  pass
115
132
 
116
- def remove(self, id: str) -> bool:
133
+ def remove(
134
+ self,
135
+ id: str
136
+ ) -> bool:
117
137
  """
118
138
  Clear index
119
139
 
@@ -127,7 +147,10 @@ class BaseStore:
127
147
  shutil.rmtree(path)
128
148
  return True
129
149
 
130
- def truncate(self, id: str) -> bool:
150
+ def truncate(
151
+ self,
152
+ id: str
153
+ ) -> bool:
131
154
  """
132
155
  Truncate index
133
156
 
@@ -136,7 +159,11 @@ class BaseStore:
136
159
  """
137
160
  return self.remove(id)
138
161
 
139
- def remove_document(self, id: str, doc_id: str) -> bool:
162
+ def remove_document(
163
+ self,
164
+ id: str,
165
+ doc_id: str
166
+ ) -> bool:
140
167
  """
141
168
  Remove document from index
142
169
 
@@ -6,10 +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.11.14 05:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import os.path
13
+ from typing import Optional
14
+
13
15
  import chromadb
14
16
  from chromadb.config import Settings
15
17
 
@@ -64,7 +66,11 @@ class ChromaProvider(BaseStore):
64
66
  index=index,
65
67
  )
66
68
 
67
- def get(self, id: str, service_context: ServiceContext = None) -> BaseIndex:
69
+ def get(
70
+ self,
71
+ id: str,
72
+ service_context: Optional[ServiceContext] = None
73
+ ) -> BaseIndex:
68
74
  """
69
75
  Get index
70
76
 
@@ -86,7 +92,11 @@ class ChromaProvider(BaseStore):
86
92
  self.indexes[id] = self.index_from_store(vector_store, storage_context, service_context)
87
93
  return self.indexes[id]
88
94
 
89
- def store(self, id: str, index: BaseIndex = None):
95
+ def store(
96
+ self,
97
+ id: str,
98
+ index: Optional[BaseIndex] = None
99
+ ):
90
100
  """
91
101
  Store index
92
102
 
@@ -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.11.23 00:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import os.path
13
+ from typing import Optional
13
14
 
14
15
  from llama_index.core import StorageContext, load_index_from_storage
15
16
  from llama_index.core.indices.base import BaseIndex
@@ -32,7 +33,7 @@ class CtxAttachmentProvider(BaseStore):
32
33
  self.id = "CtxAttachmentVectorStore"
33
34
  self.index = None
34
35
 
35
- def get_path(self) -> str:
36
+ def get_path(self, id: str) -> str:
36
37
  """
37
38
  Get database path
38
39
 
@@ -40,40 +41,53 @@ class CtxAttachmentProvider(BaseStore):
40
41
  """
41
42
  return self.path
42
43
 
43
- def exists(self) -> bool:
44
+ def exists(
45
+ self,
46
+ id: Optional[str] = None
47
+ ) -> bool:
44
48
  """
45
49
  Check if index exists
46
50
 
47
51
  :return: True if exists
48
52
  """
49
- path = self.get_path()
53
+ path = self.get_path("")
50
54
  if os.path.exists(path):
51
55
  store = os.path.join(path, "docstore.json")
52
56
  if os.path.exists(store):
53
57
  return True
54
58
  return False
55
59
 
56
- def create(self):
57
- """Create empty index"""
58
- path = self.get_path()
60
+ def create(self, id: str):
61
+ """
62
+ Create empty index
63
+
64
+ :param id: index name (not used)
65
+ """
66
+ path = self.get_path(id)
59
67
  if not os.path.exists(path):
60
68
  index = self.index_from_empty() # create empty index
61
69
  self.store(
70
+ id=id,
62
71
  index=index,
63
72
  )
64
73
  else:
65
74
  self.index = self.index_from_empty()
66
75
 
67
- def get(self, service_context: ServiceContext = None) -> BaseIndex:
76
+ def get(
77
+ self,
78
+ id: str,
79
+ service_context: Optional[ServiceContext] = None
80
+ ) -> BaseIndex:
68
81
  """
69
82
  Get index
70
83
 
84
+ :param id: index name (not used)
71
85
  :param service_context: Service context
72
86
  :return: index instance
73
87
  """
74
88
  if not self.exists():
75
- self.create()
76
- path = self.get_path()
89
+ self.create(id)
90
+ path = self.get_path(id)
77
91
  storage_context = StorageContext.from_defaults(
78
92
  persist_dir=path,
79
93
  )
@@ -84,13 +98,18 @@ class CtxAttachmentProvider(BaseStore):
84
98
 
85
99
  return self.index
86
100
 
87
- def store(self, index: BaseIndex = None):
101
+ def store(
102
+ self,
103
+ id: str,
104
+ index: Optional[BaseIndex] = None
105
+ ):
88
106
  """
89
107
  Store index
90
108
 
109
+ :param id: index name (not used)
91
110
  :param index: index instance
92
111
  """
93
- path = self.get_path()
112
+ path = self.get_path(id)
94
113
  index.storage_context.persist(
95
114
  persist_dir=path,
96
115
  )
@@ -99,6 +118,6 @@ class CtxAttachmentProvider(BaseStore):
99
118
  def clean(self):
100
119
  """Clean index"""
101
120
  self.index = None
102
- path = self.get_path()
121
+ path = self.get_path("")
103
122
  if os.path.exists(path):
104
123
  os.remove(path)
@@ -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.11.14 05:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import datetime
13
13
  import os.path
14
+ from typing import Optional
14
15
 
15
16
  from llama_index.core.indices.base import BaseIndex
16
17
  from llama_index.core.indices.service_context import ServiceContext
@@ -67,7 +68,11 @@ class ElasticsearchProvider(BaseStore):
67
68
  **additional_args
68
69
  )
69
70
 
70
- def get(self, id: str, service_context: ServiceContext = None) -> BaseIndex:
71
+ def get(
72
+ self,
73
+ id: str,
74
+ service_context: Optional[ServiceContext] = None
75
+ ) -> BaseIndex:
71
76
  """
72
77
  Get index
73
78
 
@@ -84,7 +89,11 @@ class ElasticsearchProvider(BaseStore):
84
89
  self.indexes[id] = self.index_from_store(vector_store, storage_context, service_context)
85
90
  return self.indexes[id]
86
91
 
87
- def store(self, id: str, index: BaseIndex = None):
92
+ def store(
93
+ self,
94
+ id: str,
95
+ index: Optional[BaseIndex] = None
96
+ ):
88
97
  """
89
98
  Store index
90
99
 
@@ -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.11.14 05:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import datetime
13
13
  import os.path
14
+ from typing import Optional
14
15
 
15
16
  from pinecone import Pinecone, ServerlessSpec
16
17
 
@@ -122,7 +123,11 @@ class PinecodeProvider(BaseStore):
122
123
  pinecone_index=pinecone_index,
123
124
  )
124
125
 
125
- def get(self, id: str, service_context: ServiceContext = None) -> BaseIndex:
126
+ def get(
127
+ self,
128
+ id: str,
129
+ service_context: Optional[ServiceContext] = None
130
+ ) -> BaseIndex:
126
131
  """
127
132
  Get index
128
133
 
@@ -139,7 +144,11 @@ class PinecodeProvider(BaseStore):
139
144
  self.indexes[id] = self.index_from_store(vector_store, storage_context, service_context)
140
145
  return self.indexes[id]
141
146
 
142
- def store(self, id: str, index: BaseIndex = None):
147
+ def store(
148
+ self,
149
+ id: str,
150
+ index: Optional[BaseIndex] = None
151
+ ):
143
152
  """
144
153
  Store index
145
154
 
@@ -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.11.14 05:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import datetime
13
13
  import os.path
14
+ from typing import Optional
14
15
 
15
16
  from llama_index.core import StorageContext
16
17
  from llama_index.core.indices.base import BaseIndex
@@ -67,7 +68,11 @@ class RedisProvider(BaseStore):
67
68
  **additional_args
68
69
  )
69
70
 
70
- def get(self, id: str, service_context: ServiceContext = None) -> BaseIndex:
71
+ def get(
72
+ self,
73
+ id: str,
74
+ service_context: Optional[ServiceContext] = None
75
+ ) -> BaseIndex:
71
76
  """
72
77
  Get index
73
78
 
@@ -84,7 +89,11 @@ class RedisProvider(BaseStore):
84
89
  self.indexes[id] = self.index_from_store(vector_store, storage_context, service_context)
85
90
  return self.indexes[id]
86
91
 
87
- def store(self, id: str, index: BaseIndex = None):
92
+ def store(
93
+ self,
94
+ id: str,
95
+ index: Optional[BaseIndex] = None
96
+ ):
88
97
  """
89
98
  Store index
90
99
 
@@ -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.11.14 05:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import os.path
13
+ from typing import Optional
13
14
 
14
15
  from llama_index.core import StorageContext, load_index_from_storage
15
16
  from llama_index.core.indices.base import BaseIndex
@@ -46,7 +47,11 @@ class SimpleProvider(BaseStore):
46
47
  index=index,
47
48
  )
48
49
 
49
- def get(self, id: str, service_context: ServiceContext = None) -> BaseIndex:
50
+ def get(
51
+ self,
52
+ id: str,
53
+ service_context: Optional[ServiceContext] = None
54
+ ) -> BaseIndex:
50
55
  """
51
56
  Get index
52
57
 
@@ -66,7 +71,11 @@ class SimpleProvider(BaseStore):
66
71
  )
67
72
  return self.indexes[id]
68
73
 
69
- def store(self, id: str, index: BaseIndex = None):
74
+ def store(
75
+ self,
76
+ id: str,
77
+ index: Optional[BaseIndex] = None
78
+ ):
70
79
  """
71
80
  Store index
72
81