pygpt-net 2.4.41__py3-none-any.whl → 2.4.44__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 (183) hide show
  1. CHANGELOG.md +19 -0
  2. README.md +151 -71
  3. pygpt_net/CHANGELOG.txt +19 -0
  4. pygpt_net/__init__.py +3 -3
  5. pygpt_net/app.py +3 -1
  6. pygpt_net/controller/attachment.py +31 -3
  7. pygpt_net/controller/audio/__init__.py +2 -2
  8. pygpt_net/controller/camera.py +1 -10
  9. pygpt_net/controller/chat/attachment.py +37 -36
  10. pygpt_net/controller/chat/audio.py +2 -2
  11. pygpt_net/controller/config/placeholder.py +20 -4
  12. pygpt_net/controller/idx/common.py +7 -3
  13. pygpt_net/controller/ui/mode.py +16 -21
  14. pygpt_net/core/attachments/__init__.py +7 -2
  15. pygpt_net/core/attachments/context.py +52 -34
  16. pygpt_net/core/audio/__init__.py +4 -1
  17. pygpt_net/core/audio/whisper.py +37 -0
  18. pygpt_net/core/bridge/worker.py +2 -2
  19. pygpt_net/core/db/__init__.py +2 -1
  20. pygpt_net/core/debug/attachments.py +1 -0
  21. pygpt_net/core/debug/events.py +22 -10
  22. pygpt_net/core/debug/tabs.py +6 -3
  23. pygpt_net/core/history.py +3 -2
  24. pygpt_net/core/idx/__init__.py +23 -6
  25. pygpt_net/core/idx/chat.py +15 -5
  26. pygpt_net/core/idx/indexing.py +47 -14
  27. pygpt_net/core/idx/ui/__init__.py +22 -0
  28. pygpt_net/core/idx/ui/loaders.py +217 -0
  29. pygpt_net/core/installer.py +2 -4
  30. pygpt_net/core/models.py +62 -17
  31. pygpt_net/core/modes.py +11 -13
  32. pygpt_net/core/notepad.py +4 -4
  33. pygpt_net/core/plugins.py +27 -16
  34. pygpt_net/core/presets.py +20 -9
  35. pygpt_net/core/profile.py +11 -3
  36. pygpt_net/core/render/web/parser.py +3 -1
  37. pygpt_net/core/settings.py +5 -5
  38. pygpt_net/core/tabs/tab.py +10 -2
  39. pygpt_net/core/tokens.py +8 -6
  40. pygpt_net/core/web/__init__.py +105 -0
  41. pygpt_net/core/{web.py → web/helpers.py} +93 -67
  42. pygpt_net/data/config/config.json +4 -4
  43. pygpt_net/data/config/models.json +3 -3
  44. pygpt_net/data/config/modes.json +3 -3
  45. pygpt_net/data/config/settings.json +5 -5
  46. pygpt_net/data/locale/locale.de.ini +3 -3
  47. pygpt_net/data/locale/locale.en.ini +12 -9
  48. pygpt_net/data/locale/locale.es.ini +3 -3
  49. pygpt_net/data/locale/locale.fr.ini +3 -3
  50. pygpt_net/data/locale/locale.it.ini +3 -3
  51. pygpt_net/data/locale/locale.pl.ini +3 -3
  52. pygpt_net/data/locale/locale.uk.ini +3 -3
  53. pygpt_net/data/locale/locale.zh.ini +3 -3
  54. pygpt_net/data/locale/plugin.cmd_web.en.ini +2 -0
  55. pygpt_net/data/locale/plugin.mailer.en.ini +21 -0
  56. pygpt_net/item/attachment.py +5 -1
  57. pygpt_net/item/ctx.py +111 -3
  58. pygpt_net/migrations/Version20241215110000.py +25 -0
  59. pygpt_net/migrations/__init__.py +3 -1
  60. pygpt_net/plugin/agent/__init__.py +7 -2
  61. pygpt_net/plugin/audio_output/__init__.py +6 -1
  62. pygpt_net/plugin/base/plugin.py +58 -26
  63. pygpt_net/plugin/base/worker.py +20 -17
  64. pygpt_net/plugin/cmd_files/__init__.py +3 -2
  65. pygpt_net/plugin/cmd_history/config.py +2 -2
  66. pygpt_net/plugin/cmd_web/__init__.py +3 -4
  67. pygpt_net/plugin/cmd_web/config.py +71 -3
  68. pygpt_net/plugin/cmd_web/websearch.py +20 -12
  69. pygpt_net/plugin/cmd_web/worker.py +67 -4
  70. pygpt_net/plugin/idx_llama_index/config.py +3 -3
  71. pygpt_net/plugin/mailer/__init__.py +123 -0
  72. pygpt_net/plugin/mailer/config.py +149 -0
  73. pygpt_net/plugin/mailer/runner.py +285 -0
  74. pygpt_net/plugin/mailer/worker.py +123 -0
  75. pygpt_net/provider/agents/base.py +5 -2
  76. pygpt_net/provider/agents/openai.py +4 -2
  77. pygpt_net/provider/agents/openai_assistant.py +4 -2
  78. pygpt_net/provider/agents/planner.py +4 -2
  79. pygpt_net/provider/agents/react.py +4 -2
  80. pygpt_net/provider/audio_output/openai_tts.py +5 -11
  81. pygpt_net/provider/core/assistant/base.py +5 -3
  82. pygpt_net/provider/core/assistant/json_file.py +8 -5
  83. pygpt_net/provider/core/assistant_file/base.py +4 -3
  84. pygpt_net/provider/core/assistant_file/db_sqlite/__init__.py +4 -3
  85. pygpt_net/provider/core/assistant_file/db_sqlite/storage.py +3 -2
  86. pygpt_net/provider/core/assistant_store/base.py +6 -4
  87. pygpt_net/provider/core/assistant_store/db_sqlite/__init__.py +5 -4
  88. pygpt_net/provider/core/assistant_store/db_sqlite/storage.py +5 -3
  89. pygpt_net/provider/core/attachment/base.py +5 -3
  90. pygpt_net/provider/core/attachment/json_file.py +7 -3
  91. pygpt_net/provider/core/calendar/base.py +5 -3
  92. pygpt_net/provider/core/calendar/db_sqlite/__init__.py +6 -5
  93. pygpt_net/provider/core/calendar/db_sqlite/storage.py +5 -4
  94. pygpt_net/provider/core/config/base.py +8 -6
  95. pygpt_net/provider/core/config/json_file.py +9 -7
  96. pygpt_net/provider/core/config/patch.py +6 -0
  97. pygpt_net/provider/core/ctx/base.py +27 -25
  98. pygpt_net/provider/core/ctx/db_sqlite/__init__.py +51 -35
  99. pygpt_net/provider/core/ctx/db_sqlite/storage.py +92 -38
  100. pygpt_net/provider/core/ctx/db_sqlite/utils.py +37 -11
  101. pygpt_net/provider/core/index/base.py +129 -23
  102. pygpt_net/provider/core/index/db_sqlite/__init__.py +130 -23
  103. pygpt_net/provider/core/index/db_sqlite/storage.py +130 -23
  104. pygpt_net/provider/core/index/db_sqlite/utils.py +4 -2
  105. pygpt_net/provider/core/mode/base.py +5 -3
  106. pygpt_net/provider/core/mode/json_file.py +7 -6
  107. pygpt_net/provider/core/model/base.py +6 -4
  108. pygpt_net/provider/core/model/json_file.py +9 -7
  109. pygpt_net/provider/core/notepad/base.py +5 -3
  110. pygpt_net/provider/core/notepad/db_sqlite/__init__.py +5 -4
  111. pygpt_net/provider/core/notepad/db_sqlite/storage.py +4 -3
  112. pygpt_net/provider/core/plugin_preset/base.py +4 -2
  113. pygpt_net/provider/core/plugin_preset/json_file.py +5 -3
  114. pygpt_net/provider/core/preset/base.py +6 -4
  115. pygpt_net/provider/core/preset/json_file.py +9 -9
  116. pygpt_net/provider/core/prompt/base.py +6 -3
  117. pygpt_net/provider/core/prompt/json_file.py +11 -6
  118. pygpt_net/provider/gpt/assistants.py +15 -6
  119. pygpt_net/provider/gpt/audio.py +5 -5
  120. pygpt_net/provider/gpt/chat.py +7 -5
  121. pygpt_net/provider/gpt/completion.py +8 -4
  122. pygpt_net/provider/gpt/image.py +3 -3
  123. pygpt_net/provider/gpt/store.py +46 -12
  124. pygpt_net/provider/gpt/vision.py +16 -11
  125. pygpt_net/provider/llms/anthropic.py +7 -2
  126. pygpt_net/provider/llms/azure_openai.py +26 -5
  127. pygpt_net/provider/llms/base.py +47 -9
  128. pygpt_net/provider/llms/google.py +7 -2
  129. pygpt_net/provider/llms/hugging_face.py +13 -3
  130. pygpt_net/provider/llms/hugging_face_api.py +18 -4
  131. pygpt_net/provider/llms/local.py +7 -2
  132. pygpt_net/provider/llms/ollama.py +30 -6
  133. pygpt_net/provider/llms/openai.py +32 -6
  134. pygpt_net/provider/loaders/base.py +14 -0
  135. pygpt_net/provider/loaders/hub/yt/base.py +5 -0
  136. pygpt_net/provider/loaders/web_database.py +13 -5
  137. pygpt_net/provider/loaders/web_github_issues.py +5 -1
  138. pygpt_net/provider/loaders/web_google_calendar.py +9 -1
  139. pygpt_net/provider/loaders/web_google_docs.py +6 -1
  140. pygpt_net/provider/loaders/web_google_drive.py +10 -1
  141. pygpt_net/provider/loaders/web_google_gmail.py +2 -1
  142. pygpt_net/provider/loaders/web_google_keep.py +5 -1
  143. pygpt_net/provider/loaders/web_google_sheets.py +5 -1
  144. pygpt_net/provider/loaders/web_microsoft_onedrive.py +15 -1
  145. pygpt_net/provider/loaders/web_page.py +4 -2
  146. pygpt_net/provider/loaders/web_rss.py +2 -1
  147. pygpt_net/provider/loaders/web_sitemap.py +2 -1
  148. pygpt_net/provider/loaders/web_twitter.py +4 -2
  149. pygpt_net/provider/loaders/web_yt.py +17 -2
  150. pygpt_net/provider/vector_stores/__init__.py +45 -14
  151. pygpt_net/provider/vector_stores/base.py +35 -8
  152. pygpt_net/provider/vector_stores/chroma.py +13 -3
  153. pygpt_net/provider/vector_stores/ctx_attachment.py +32 -13
  154. pygpt_net/provider/vector_stores/elasticsearch.py +12 -3
  155. pygpt_net/provider/vector_stores/pinecode.py +12 -3
  156. pygpt_net/provider/vector_stores/redis.py +12 -3
  157. pygpt_net/provider/vector_stores/simple.py +12 -3
  158. pygpt_net/provider/vector_stores/temp.py +16 -4
  159. pygpt_net/provider/web/base.py +10 -3
  160. pygpt_net/provider/web/google_custom_search.py +9 -3
  161. pygpt_net/provider/web/microsoft_bing.py +9 -3
  162. pygpt_net/tools/__init__.py +13 -5
  163. pygpt_net/tools/audio_transcriber/__init__.py +4 -3
  164. pygpt_net/tools/base.py +15 -8
  165. pygpt_net/tools/code_interpreter/__init__.py +4 -3
  166. pygpt_net/tools/html_canvas/__init__.py +4 -3
  167. pygpt_net/tools/image_viewer/__init__.py +10 -4
  168. pygpt_net/tools/indexer/__init__.py +15 -46
  169. pygpt_net/tools/indexer/ui/web.py +20 -78
  170. pygpt_net/tools/media_player/__init__.py +4 -3
  171. pygpt_net/tools/text_editor/__init__.py +36 -10
  172. pygpt_net/ui/layout/chat/output.py +2 -2
  173. pygpt_net/ui/layout/ctx/ctx_list.py +86 -18
  174. pygpt_net/ui/menu/audio.py +12 -1
  175. pygpt_net/ui/widget/dialog/url.py +151 -14
  176. pygpt_net/ui/widget/element/group.py +15 -2
  177. pygpt_net/ui/widget/lists/context.py +23 -9
  178. pygpt_net/utils.py +1 -1
  179. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.44.dist-info}/METADATA +152 -72
  180. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.44.dist-info}/RECORD +183 -173
  181. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.44.dist-info}/LICENSE +0 -0
  182. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.44.dist-info}/WHEEL +0 -0
  183. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.44.dist-info}/entry_points.txt +0 -0
pygpt_net/core/notepad.py CHANGED
@@ -6,12 +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.12.14 00:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import datetime
13
13
  import uuid
14
- from typing import Optional
14
+ from typing import Optional, Dict
15
15
 
16
16
  from packaging.version import Version
17
17
 
@@ -61,7 +61,7 @@ class Notepad:
61
61
  return self.items[idx]
62
62
  return None
63
63
 
64
- def get_all(self) -> dict:
64
+ def get_all(self) -> Dict[int, NotepadItem]:
65
65
  """
66
66
  Get all notepads
67
67
 
@@ -137,7 +137,7 @@ class Notepad:
137
137
  """Save all notepads"""
138
138
  self.provider.save_all(self.items)
139
139
 
140
- def import_from_db(self) -> Optional[dict]:
140
+ def import_from_db(self) -> Optional[Dict[int, dict]]:
141
141
  """
142
142
  Import notepad tabs from database
143
143
 
pygpt_net/core/plugins.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.12.14 08:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import copy
@@ -49,7 +49,7 @@ class Plugins:
49
49
  """
50
50
  return id in self.plugins
51
51
 
52
- def all(self) -> dict:
52
+ def all(self) -> Dict[str, BasePlugin]:
53
53
  """
54
54
  Get all plugins
55
55
 
@@ -57,7 +57,7 @@ class Plugins:
57
57
  """
58
58
  return self.plugins
59
59
 
60
- def get_ids(self) -> list:
60
+ def get_ids(self) -> List[str]:
61
61
  """
62
62
  Get all plugins ids
63
63
 
@@ -76,7 +76,7 @@ class Plugins:
76
76
  return self.plugins[id]
77
77
  return None
78
78
 
79
- def get_option(self, id: str, key: str) -> any:
79
+ def get_option(self, id: str, key: str) -> Any:
80
80
  """
81
81
  Get plugin option
82
82
 
@@ -172,7 +172,7 @@ class Plugins:
172
172
 
173
173
  def enable(self, id: str):
174
174
  """
175
- Enable plugin
175
+ Enable plugin by ID
176
176
 
177
177
  :param id: plugin id
178
178
  """
@@ -183,7 +183,7 @@ class Plugins:
183
183
 
184
184
  def disable(self, id: str):
185
185
  """
186
- Disable plugin
186
+ Disable plugin by ID
187
187
 
188
188
  :param id: plugin id
189
189
  """
@@ -318,7 +318,7 @@ class Plugins:
318
318
  """
319
319
  return id in self.presets
320
320
 
321
- def get_preset(self, id: str) -> dict:
321
+ def get_preset(self, id: str) -> Dict[str, Any]:
322
322
  """
323
323
  Get preset by id
324
324
 
@@ -328,7 +328,7 @@ class Plugins:
328
328
  if self.has_preset(id):
329
329
  return self.presets[id]
330
330
 
331
- def set_preset(self, id: str, preset: dict):
331
+ def set_preset(self, id: str, preset: Dict[str, Any]):
332
332
  """
333
333
  Set config value
334
334
 
@@ -337,7 +337,7 @@ class Plugins:
337
337
  """
338
338
  self.presets[id] = preset
339
339
 
340
- def replace_presets(self, presets: dict):
340
+ def replace_presets(self, presets: Dict[str, Any]):
341
341
  """
342
342
  Replace presets
343
343
 
@@ -349,7 +349,7 @@ class Plugins:
349
349
  """Load presets"""
350
350
  self.presets = self.provider.load()
351
351
 
352
- def get_presets(self) -> dict:
352
+ def get_presets(self) -> Dict[str, Any]:
353
353
  """
354
354
  Return all presets
355
355
 
@@ -357,7 +357,11 @@ class Plugins:
357
357
  """
358
358
  return self.presets
359
359
 
360
- def reset_options(self, plugin_id: str, keys: List[str]):
360
+ def reset_options(
361
+ self,
362
+ plugin_id: str,
363
+ keys: List[str]
364
+ ):
361
365
  """
362
366
  Reset plugin options
363
367
 
@@ -408,7 +412,11 @@ class Plugins:
408
412
  self.save_presets()
409
413
  print("[FIX] Removed invalid keys from plugin presets.")
410
414
 
411
- def remove_preset_values(self, plugin_id:str, key: str):
415
+ def remove_preset_values(
416
+ self,
417
+ plugin_id: str,
418
+ key: str
419
+ ):
412
420
  """
413
421
  Update preset value
414
422
 
@@ -431,7 +439,12 @@ class Plugins:
431
439
  if updated:
432
440
  self.save_presets()
433
441
 
434
- def update_preset_values(self, plugin_id: str, key: str, value: Any):
442
+ def update_preset_values(
443
+ self,
444
+ plugin_id: str,
445
+ key: str,
446
+ value: Any
447
+ ):
435
448
  """
436
449
  Update preset value
437
450
 
@@ -471,9 +484,7 @@ class Plugins:
471
484
  self.dump_locale(self.plugins[id], path)
472
485
 
473
486
  def dump_locales(self):
474
- """
475
- Dump all locales
476
- """
487
+ """Dump all locales"""
477
488
  langs = ['en', 'pl']
478
489
  for id in self.plugins:
479
490
  domain = 'plugin.' + id
pygpt_net/core/presets.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.12.14 08:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import copy
@@ -193,6 +193,7 @@ class Presets:
193
193
  """
194
194
  if id in self.items:
195
195
  self.items[id].enabled = True
196
+
196
197
  def disable(self, id: str):
197
198
  """
198
199
  Disable preset
@@ -366,7 +367,11 @@ class Presets:
366
367
  self.sort_by_name()
367
368
  return id
368
369
 
369
- def remove(self, id: str, remove_file: bool = True):
370
+ def remove(
371
+ self,
372
+ id: str,
373
+ remove_file: bool = True
374
+ ):
370
375
  """
371
376
  Delete preset
372
377
 
@@ -381,9 +386,7 @@ class Presets:
381
386
  # self.load_presets()
382
387
 
383
388
  def sort_by_name(self):
384
- """
385
- Sort presets by name
386
- """
389
+ """Sort presets by name"""
387
390
  self.items = dict(
388
391
  sorted(
389
392
  self.items.items(),
@@ -408,7 +411,7 @@ class Presets:
408
411
  self.items[preset.filename] = preset
409
412
  self.save(preset.filename)
410
413
 
411
- def get_all(self) -> dict:
414
+ def get_all(self) -> Dict[str, PresetItem]:
412
415
  """
413
416
  Return all presets
414
417
 
@@ -428,7 +431,7 @@ class Presets:
428
431
  self.items[id] = base[id]
429
432
  self.save(id)
430
433
 
431
- def load_base(self) -> dict:
434
+ def load_base(self) -> Dict[str, PresetItem]:
432
435
  """
433
436
  Load base presets
434
437
 
@@ -460,7 +463,11 @@ class Presets:
460
463
  """Save all presets"""
461
464
  self.provider.save_all(self.items)
462
465
 
463
- def add_expert(self, agent_uuid: str, expert_uuid: str):
466
+ def add_expert(
467
+ self,
468
+ agent_uuid: str,
469
+ expert_uuid: str
470
+ ):
464
471
  """
465
472
  Add expert to agent
466
473
 
@@ -474,7 +481,11 @@ class Presets:
474
481
  agent.experts.append(expert_uuid)
475
482
  self.save(agent.filename)
476
483
 
477
- def remove_expert(self, agent_uuid: str, expert_uuid: str):
484
+ def remove_expert(
485
+ self,
486
+ agent_uuid: str,
487
+ expert_uuid: str
488
+ ):
478
489
  """
479
490
  Remove expert from agent
480
491
  :param agent_uuid: agent uuid
pygpt_net/core/profile.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.12.14 08:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import json
@@ -120,7 +120,11 @@ class Profile:
120
120
  with open(f, 'w', encoding='utf-8') as f:
121
121
  f.write(json_data)
122
122
 
123
- def add(self, name: str, workdir: str) -> str:
123
+ def add(
124
+ self,
125
+ name: str,
126
+ workdir: str
127
+ ) -> str:
124
128
  """
125
129
  Add new profile
126
130
 
@@ -228,7 +232,11 @@ class Profile:
228
232
  return tmp_dir
229
233
  return self.base_workdir
230
234
 
231
- def append(self, uuid: str, profile: Dict):
235
+ def append(
236
+ self,
237
+ uuid: str,
238
+ profile: Dict
239
+ ):
232
240
  """
233
241
  Append profile
234
242
 
@@ -37,7 +37,9 @@ class Parser:
37
37
  """
38
38
  if self.md is None:
39
39
  self.md = markdown.Markdown(extensions=[
40
- 'fenced_code', # code blocks
40
+ 'fenced_code',
41
+ 'tables',
42
+ 'sane_lists',
41
43
  MathExtension(enable_dollar_delimiter=True) # math formulas
42
44
  ])
43
45
 
@@ -6,14 +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.12.14 00:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import copy
13
13
  import json
14
14
  import os
15
15
  import shutil
16
- from typing import Optional
16
+ from typing import Optional, Dict, Any, List
17
17
 
18
18
  from pygpt_net.core.events import RenderEvent
19
19
 
@@ -38,7 +38,7 @@ class Settings:
38
38
  for id in self.ids:
39
39
  self.active[id] = False
40
40
 
41
- def get_options(self, id: Optional[str] = None) -> dict:
41
+ def get_options(self, id: Optional[str] = None) -> Dict[str, Any]:
42
42
  """
43
43
  Return options for given id
44
44
 
@@ -52,7 +52,7 @@ class Settings:
52
52
  if id in self.options:
53
53
  return self.options[id]
54
54
 
55
- def get_sections(self, id: Optional[str] = None) -> dict:
55
+ def get_sections(self, id: Optional[str] = None) -> Dict[str, Any]:
56
56
  """
57
57
  Return sections for given id
58
58
 
@@ -66,7 +66,7 @@ class Settings:
66
66
  if id in self.sections:
67
67
  return self.sections[id]
68
68
 
69
- def get_persist_options(self) -> list:
69
+ def get_persist_options(self) -> List[str]:
70
70
  """
71
71
  Return persist options keys (options that should be persisted when loading defaults)
72
72
 
@@ -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.12.14 08:00:00 #
9
+ # Updated Date: 2024.12.14 17:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  from datetime import datetime
@@ -70,4 +70,12 @@ class Tab:
70
70
  "updated_at": str(self.updated_at),
71
71
  "column_idx": self.column_idx,
72
72
  "tool_id": self.tool_id,
73
- }
73
+ }
74
+
75
+ def __str__(self) -> str:
76
+ """
77
+ String representation
78
+
79
+ :return: str
80
+ """
81
+ return str(self.to_dict())
pygpt_net/core/tokens.py CHANGED
@@ -6,13 +6,16 @@
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.14 08:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
- from typing import Tuple
12
+ from typing import Tuple, List
13
13
 
14
14
  import tiktoken
15
15
 
16
+ from langchain_core.messages import ChatMessage as ChatMessageLangchain
17
+ from llama_index.core.base.llms.types import ChatMessage as ChatMessageLlama
18
+
16
19
  from pygpt_net.core.types import (
17
20
  MODE_AGENT,
18
21
  MODE_AGENT_LLAMA,
@@ -39,7 +42,6 @@ CHAT_MODES = [
39
42
  MODE_AUDIO,
40
43
  ]
41
44
 
42
-
43
45
  class Tokens:
44
46
  def __init__(self, window=None):
45
47
  """
@@ -151,7 +153,7 @@ class Tokens:
151
153
 
152
154
  @staticmethod
153
155
  def from_messages(
154
- messages: list,
156
+ messages: List[dict],
155
157
  model: str = "gpt-4"
156
158
  ) -> int:
157
159
  """
@@ -182,7 +184,7 @@ class Tokens:
182
184
 
183
185
  @staticmethod
184
186
  def from_langchain_messages(
185
- messages: list,
187
+ messages: List[ChatMessageLangchain],
186
188
  model: str = "gpt-4"
187
189
  ) -> int:
188
190
  """
@@ -203,7 +205,7 @@ class Tokens:
203
205
  @staticmethod
204
206
  def from_llama_messages(
205
207
  query: str,
206
- messages: list,
208
+ messages: List[ChatMessageLlama],
207
209
  model: str = "gpt-4"
208
210
  ) -> int:
209
211
  """
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # ================================================== #
4
+ # This file is a part of PYGPT package #
5
+ # Website: https://pygpt.net #
6
+ # GitHub: https://github.com/szczyglis-dev/py-gpt #
7
+ # MIT License #
8
+ # Created By : Marcin Szczygliński #
9
+ # Updated Date: 2024.12.14 19:00:00 #
10
+ # ================================================== #
11
+
12
+ from typing import Optional, List, Dict
13
+
14
+ from pygpt_net.provider.web.base import BaseProvider
15
+
16
+ from .helpers import Helpers
17
+
18
+
19
+ class Web:
20
+
21
+ PROVIDER_SEARCH_ENGINE = "search_engine"
22
+
23
+ def __init__(self, window=None):
24
+ """
25
+ Web core
26
+
27
+ :param window: Window instance
28
+ """
29
+ self.window = window
30
+ self.helpers = Helpers(window)
31
+ self.providers = {
32
+ self.PROVIDER_SEARCH_ENGINE: {},
33
+ }
34
+
35
+ def is_registered(
36
+ self,
37
+ id: str,
38
+ type: str = PROVIDER_SEARCH_ENGINE
39
+ ) -> bool:
40
+ """
41
+ Check if provider is registered
42
+
43
+ :param id: provider id
44
+ :param type: provider type
45
+ :return: True if registered
46
+ """
47
+ if type in self.providers:
48
+ return id in self.providers[type]
49
+ return False
50
+
51
+ def get_providers(
52
+ self,
53
+ type: str = PROVIDER_SEARCH_ENGINE
54
+ ) -> Dict[str, BaseProvider]:
55
+ """
56
+ Get all providers
57
+
58
+ :param type: provider type
59
+ :return: providers dict
60
+ """
61
+ if type in self.providers:
62
+ return self.providers[type]
63
+ return {}
64
+
65
+ def get_ids(
66
+ self,
67
+ type: str = PROVIDER_SEARCH_ENGINE
68
+ ) -> List[str]:
69
+ """
70
+ Get all providers ids
71
+
72
+ :param type: provider type
73
+ :return: providers ids list
74
+ """
75
+ if type in self.providers:
76
+ return list(self.providers[type].keys())
77
+ return []
78
+
79
+ def get(
80
+ self,
81
+ id: str,
82
+ type: str = PROVIDER_SEARCH_ENGINE
83
+ ) -> Optional[BaseProvider]:
84
+ """
85
+ Get provider instance
86
+
87
+ :param id: provider id
88
+ :param type: provider type
89
+ :return: provider instance
90
+ """
91
+ if self.is_registered(id, type):
92
+ return self.providers[type][id]
93
+ return None
94
+
95
+ def register(self, provider: BaseProvider):
96
+ """
97
+ Register provider
98
+
99
+ :param provider: provider instance
100
+ """
101
+ id = provider.id
102
+ type = provider.type
103
+ for t in type:
104
+ if t in self.providers:
105
+ self.providers[t][id] = provider