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
@@ -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.16 01:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import datetime
@@ -89,18 +89,35 @@ class Indexing:
89
89
  "key": key,
90
90
  "value": loader.init_args[key],
91
91
  "type": "str", # default = str
92
+ "label": key,
93
+ "description": None,
92
94
  }
93
95
  # from config
94
96
  if key in loader.args:
95
97
  self.external_config[loader.id][key]["value"] = loader.args[key]
96
98
  if key in loader.init_args_types:
97
99
  self.external_config[loader.id][key]["type"] = loader.init_args_types[key]
100
+ if key in loader.init_args_labels:
101
+ self.external_config[loader.id][key]["label"] = loader.init_args_labels[key]
102
+ if key in loader.init_args_desc:
103
+ self.external_config[loader.id][key]["description"] = loader.init_args_desc[key]
98
104
 
99
105
  except ImportError as e:
100
106
  msg = "Error while registering data loader: " + loader.id + " - " + str(e)
101
107
  self.window.core.debug.log(msg)
102
108
  self.window.core.debug.log(e)
103
109
 
110
+ def get_loader(self, loader: str) -> Optional[BaseLoader]:
111
+ """
112
+ Get data loader by id
113
+
114
+ :param loader: loader id
115
+ :return: data loader instance
116
+ """
117
+ if loader in self.data_providers:
118
+ return self.data_providers[loader]
119
+ return None
120
+
104
121
  def update_loader_args(
105
122
  self,
106
123
  loader: str,
@@ -344,13 +361,13 @@ class Indexing:
344
361
  self,
345
362
  path: str,
346
363
  loader_kwargs: Optional[Dict[str, Any]] = None
347
- ) -> str:
364
+ ) -> Tuple[str, List[Document]]:
348
365
  """
349
366
  Get content from file using loaders
350
367
 
351
368
  :param path: path to file
352
369
  :param loader_kwargs: additional keyword arguments for data loader
353
- :return: file content
370
+ :return: text content, list of documents
354
371
  """
355
372
  docs = self.get_documents(
356
373
  path,
@@ -361,27 +378,27 @@ class Indexing:
361
378
  data = []
362
379
  for doc in docs:
363
380
  data.append(doc.text)
364
- return "\n".join(data)
381
+ return "\n".join(data), docs
365
382
 
366
383
  def read_web_content(
367
384
  self,
368
385
  url: str,
369
386
  type: str = "webpage",
370
387
  extra_args: Optional[Dict[str, Any]] = None
371
- ) -> str:
388
+ ) -> Tuple[str, List[Document]]:
372
389
  """
373
390
  Get content from external resource
374
391
 
375
392
  :param url: external url to index
376
393
  :param type: type of URL (webpage, feed, etc.)
377
394
  :param extra_args: extra arguments for loader
378
- :return: file content
395
+ :return: text content, list of documents
379
396
  """
380
397
  docs = self.read_web(url, type, extra_args)
381
398
  data = []
382
399
  for doc in docs:
383
400
  data.append(doc.text)
384
- return "\n".join(data)
401
+ return "\n".join(data), docs
385
402
 
386
403
  def read_web(
387
404
  self,
@@ -600,7 +617,10 @@ class Indexing:
600
617
 
601
618
  return indexed, errors
602
619
 
603
- def get_db_data_from_ts(self, updated_ts: int = 0) -> list:
620
+ def get_db_data_from_ts(
621
+ self,
622
+ updated_ts: int = 0
623
+ ) -> List[Document]:
604
624
  """
605
625
  Get data from database from timestamp
606
626
 
@@ -640,7 +660,10 @@ class Indexing:
640
660
  documents.append(doc)
641
661
  return documents
642
662
 
643
- def get_db_meta_ids_from_ts(self, updated_ts: int = 0) -> list:
663
+ def get_db_meta_ids_from_ts(
664
+ self,
665
+ updated_ts: int = 0
666
+ ) -> List[int]:
644
667
  """
645
668
  Get IDs of meta from database from timestamp
646
669
 
@@ -664,7 +687,11 @@ class Indexing:
664
687
  ids.append(data["id"])
665
688
  return ids
666
689
 
667
- def get_db_data_by_id(self, id: int = 0, updated_ts: int = 0) -> list:
690
+ def get_db_data_by_id(
691
+ self,
692
+ id: int = 0,
693
+ updated_ts: int = 0
694
+ ) -> List[Document]:
668
695
  """
669
696
  Get data from database by meta id
670
697
 
@@ -726,7 +753,8 @@ class Indexing:
726
753
  self.window.core.idx.log("Indexing documents from database by meta id: {}".format(id))
727
754
  self.remove_old_meta_id(idx, id)
728
755
  elif from_ts > 0:
729
- self.window.core.idx.log("Indexing documents from database by meta id: {} from timestamp: {}".format(id, from_ts))
756
+ self.window.core.idx.log("Indexing documents from database by meta id: {} from timestamp: {}".
757
+ format(id, from_ts))
730
758
 
731
759
  # get items from database
732
760
  documents = self.get_db_data_by_id(id, from_ts)
@@ -736,7 +764,8 @@ class Indexing:
736
764
 
737
765
  self.index_document(index, d)
738
766
  doc_id = d.id_
739
- self.window.core.idx.log("Inserted ctx DB document: {} / {}, id: {}, metadata: {}".format(n+1, len(documents), d.id_, d.metadata))
767
+ self.window.core.idx.log("Inserted ctx DB document: {} / {}, id: {}, metadata: {}".
768
+ format(n+1, len(documents), d.id_, d.metadata))
740
769
  self.window.core.ctx.idx.set_meta_as_indexed(id, idx, doc_id) # update ctx
741
770
  n += 1
742
771
  except Exception as e:
@@ -850,7 +879,8 @@ class Indexing:
850
879
  idx=idx,
851
880
  doc_id=doc_id,
852
881
  ) # update external index
853
- self.window.core.idx.log("Inserted web document: {} / {}, id: {}, metadata: {}".format(n+1, len(documents), d.id_, d.metadata))
882
+ self.window.core.idx.log("Inserted web document: {} / {}, id: {}, metadata: {}".
883
+ format(n+1, len(documents), d.id_, d.metadata))
854
884
  n += 1
855
885
  except Exception as e:
856
886
  errors.append(str(e))
@@ -1044,7 +1074,10 @@ class Indexing:
1044
1074
  model = self.window.core.models.from_defaults()
1045
1075
 
1046
1076
  service_context = self.window.core.idx.llm.get_service_context(model=model)
1047
- index = self.window.core.idx.storage.get_ctx_idx(index_path, service_context=service_context) # get or create ctx index
1077
+ index = self.window.core.idx.storage.get_ctx_idx(
1078
+ index_path,
1079
+ service_context=service_context
1080
+ ) # get or create ctx index
1048
1081
 
1049
1082
  idx = "tmp:{}".format(index_path) # tmp index id
1050
1083
  self.window.core.idx.log("Indexing to context attachment index: {}...".format(idx))
@@ -0,0 +1,22 @@
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.16 01:00:00 #
10
+ # ================================================== #
11
+
12
+ from .loaders import Loaders
13
+
14
+ class UI:
15
+ def __init__(self, window=None):
16
+ """
17
+ UI components
18
+
19
+ :param window: Window instance
20
+ """
21
+ self.window = window
22
+ self.loaders = Loaders(window)
@@ -0,0 +1,217 @@
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.16 01:00:00 #
10
+ # ================================================== #
11
+
12
+ import json
13
+ from typing import Dict, Tuple, Any, Optional
14
+
15
+ from PySide6.QtCore import Qt
16
+ from PySide6.QtWidgets import QVBoxLayout, QLabel, QHBoxLayout, QWidget
17
+
18
+ from pygpt_net.ui.widget.element.labels import HelpLabel
19
+ from pygpt_net.ui.widget.option.input import OptionInput
20
+
21
+
22
+ class Loaders:
23
+ def __init__(self, window=None):
24
+ """
25
+ UI - loaders components
26
+
27
+ :param window: Window instance
28
+ """
29
+ self.window = window
30
+
31
+ def handle_options(
32
+ self,
33
+ select_loader,
34
+ prefix_options,
35
+ prefix_config
36
+ ) -> Tuple[bool, Optional[str], Dict[str, Any], Dict[str, Any]]:
37
+ """
38
+ Handle options
39
+
40
+ :param select_loader: loader selection
41
+ :param prefix_options: prefix for options
42
+ :param prefix_config: prefix for config
43
+ :return: bool, loader name, input_params, input_config
44
+ """
45
+ input_params = {}
46
+ input_config = {}
47
+ loader = select_loader.get_value()
48
+ if not loader:
49
+ return False, loader, input_params, input_config
50
+ loaders = self.window.core.idx.indexing.get_external_instructions()
51
+ if loader in loaders:
52
+ params = loaders[loader]
53
+ for k in params["args"]:
54
+ key_path = prefix_options + "." + loader + "." + k
55
+ if key_path in self.window.ui.nodes:
56
+ tmp_value = self.window.ui.nodes[key_path].text()
57
+ type = params["args"][k]["type"]
58
+ try:
59
+ if tmp_value:
60
+ if type == "int":
61
+ tmp_value = int(tmp_value)
62
+ elif type == "float":
63
+ tmp_value = float(tmp_value)
64
+ elif type == "bool":
65
+ if tmp_value.lower() in ["true", "1"]:
66
+ tmp_value = True
67
+ else:
68
+ tmp_value = False
69
+ elif type == "list":
70
+ tmp_value = tmp_value.split(",")
71
+ elif type == "dict":
72
+ tmp_value = json.loads(tmp_value)
73
+ input_params[k] = tmp_value
74
+ except Exception as e:
75
+ self.window.core.debug.log(e)
76
+ self.window.ui.dialogs.alert(e)
77
+
78
+ loaders = self.window.core.idx.indexing.get_external_config()
79
+ if loader in loaders:
80
+ params = loaders[loader]
81
+ for k in params:
82
+ key_path = prefix_config + "." + loader + "." + k
83
+ type = params[k]["type"]
84
+ if key_path in self.window.ui.nodes:
85
+ tmp_value = self.window.ui.nodes[key_path].text()
86
+ try:
87
+ if tmp_value:
88
+ if type == "int":
89
+ tmp_value = int(tmp_value)
90
+ elif type == "float":
91
+ tmp_value = float(tmp_value)
92
+ elif type == "bool":
93
+ if tmp_value.lower() in ["true", "1"]:
94
+ tmp_value = True
95
+ else:
96
+ tmp_value = False
97
+ elif type == "list":
98
+ tmp_value = tmp_value.split(",")
99
+ elif type == "dict":
100
+ tmp_value = json.loads(tmp_value)
101
+ input_config[k] = tmp_value
102
+ except Exception as e:
103
+ self.window.core.debug.log(e)
104
+ self.window.ui.dialogs.alert(e)
105
+
106
+ return True, loader, input_params, input_config
107
+
108
+ def setup_loader_options(self):
109
+ """Setup loader options"""
110
+ inputs = {}
111
+ groups = {}
112
+ loaders = self.window.core.idx.indexing.get_external_instructions()
113
+ for loader in loaders:
114
+ params = loaders[loader]
115
+ inputs[loader] = {}
116
+ group = QVBoxLayout()
117
+ for k in params["args"]:
118
+ label = k
119
+ description = None
120
+ is_label = False
121
+ if "label" in params["args"][k]:
122
+ label = params["args"][k]["label"]
123
+ is_label = True
124
+ if "description" in params["args"][k]:
125
+ description = params["args"][k]["description"]
126
+ option_id = "web.loader." + loader + ".option." + k
127
+ option_widget = OptionInput(self.window, "tool.indexer", option_id, {
128
+ "label": label,
129
+ "value": "",
130
+ })
131
+ option_widget.setPlaceholderText(params["args"][k]["type"])
132
+ inputs[loader][k] = option_widget
133
+
134
+ option_label = QLabel(label)
135
+ option_label.setToolTip(k)
136
+
137
+ row = QHBoxLayout() # cols
138
+ row.addWidget(option_label)
139
+ row.addWidget(option_widget)
140
+ row.setContentsMargins(5, 0, 5, 0)
141
+
142
+ option_layout = QVBoxLayout()
143
+ option_layout.addLayout(row)
144
+ if description:
145
+ option_layout.addWidget(HelpLabel(description))
146
+
147
+ option_layout.setContentsMargins(5, 0, 0, 0)
148
+
149
+ group.addLayout(option_layout)
150
+ group.setContentsMargins(0, 0, 0, 0)
151
+
152
+ group_widget = QWidget()
153
+ group_widget.setLayout(group)
154
+ groups[loader] = group_widget
155
+
156
+ return inputs, groups
157
+
158
+ def setup_loader_config(self):
159
+ """Setup loader config"""
160
+ inputs = {}
161
+ groups = {}
162
+ loaders = self.window.core.idx.indexing.get_external_config()
163
+ for loader in loaders:
164
+ params = loaders[loader]
165
+ inputs[loader] = {}
166
+ group = QVBoxLayout()
167
+ for k in params:
168
+ label = k
169
+ description = None
170
+ is_label = False
171
+ if "label" in params[k]:
172
+ label = params[k]["label"]
173
+ is_label = True
174
+ if "description" in params[k]:
175
+ description = params[k]["description"]
176
+ option_id = "web.loader." + loader + ".config." + k
177
+ option_widget = OptionInput(self.window, "tool.indexer", option_id, {
178
+ "label": label,
179
+ "value": params[k]["value"],
180
+ })
181
+ try:
182
+ if params[k]["value"] is not None:
183
+ if params[k]["type"] == "list" and isinstance(params[k]["value"], list):
184
+ option_widget.setText(", ".join(params[k]["value"]))
185
+ elif params[k]["type"] == "dict" and isinstance(params[k]["value"], dict):
186
+ option_widget.setText(json.dumps(params[k]["value"]))
187
+ else:
188
+ option_widget.setText(str(params[k]["value"]))
189
+ except Exception as e:
190
+ self.window.core.debug.log(e)
191
+
192
+ option_widget.setPlaceholderText(params[k]["type"])
193
+ inputs[loader][k] = option_widget
194
+
195
+ option_label = QLabel(label)
196
+ option_label.setToolTip(k)
197
+
198
+ row = QHBoxLayout() # cols
199
+ row.addWidget(option_label)
200
+ row.addWidget(option_widget)
201
+ row.setContentsMargins(5, 0, 5, 0)
202
+
203
+ option_layout = QVBoxLayout()
204
+ option_layout.addLayout(row)
205
+ if description:
206
+ option_layout.addWidget(HelpLabel(description))
207
+
208
+ option_layout.setContentsMargins(5, 0, 0, 0)
209
+
210
+ group.addLayout(option_layout)
211
+ group.setContentsMargins(0, 0, 0, 0)
212
+
213
+ group_widget = QWidget()
214
+ group_widget.setLayout(group)
215
+ groups[loader] = group_widget
216
+
217
+ return inputs, groups
@@ -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: 2023.12.31 04:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  from pathlib import Path
@@ -23,9 +23,7 @@ class Installer:
23
23
  self.window = window
24
24
 
25
25
  def install(self):
26
- """
27
- Install db, config data and directories
28
- """
26
+ """Install db, config data and directories"""
29
27
  try:
30
28
  # create user config directory
31
29
  path = Path(self.window.core.config.path)
pygpt_net/core/models.py CHANGED
@@ -6,11 +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.12.14 00:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import copy
13
- from typing import Optional
13
+ from typing import Optional, List, Dict
14
14
 
15
15
  from packaging.version import Version
16
16
 
@@ -92,7 +92,7 @@ class Models:
92
92
  if key in self.items:
93
93
  return self.items[key]
94
94
 
95
- def get_ids(self) -> list:
95
+ def get_ids(self) -> List[str]:
96
96
  """
97
97
  Return models ids
98
98
 
@@ -118,7 +118,11 @@ class Models:
118
118
  """
119
119
  return model in self.items
120
120
 
121
- def is_allowed(self, model: str, mode: str) -> bool:
121
+ def is_allowed(
122
+ self,
123
+ model: str,
124
+ mode: str
125
+ ) -> bool:
122
126
  """
123
127
  Check if model is allowed for mode
124
128
 
@@ -130,7 +134,10 @@ class Models:
130
134
  return mode in self.items[model].mode
131
135
  return False
132
136
 
133
- def get_id(self, key: str) -> str:
137
+ def get_id(
138
+ self,
139
+ key: str
140
+ ) -> str:
134
141
  """
135
142
  Return model internal ID
136
143
 
@@ -140,7 +147,11 @@ class Models:
140
147
  if key in self.items:
141
148
  return self.items[key].id
142
149
 
143
- def get_by_idx(self, idx: int, mode: str) -> str:
150
+ def get_by_idx(
151
+ self,
152
+ idx: int,
153
+ mode: str
154
+ ) -> str:
144
155
  """
145
156
  Return model by index
146
157
 
@@ -151,7 +162,10 @@ class Models:
151
162
  items = self.get_by_mode(mode)
152
163
  return list(items.keys())[idx]
153
164
 
154
- def get_by_mode(self, mode: str) -> dict:
165
+ def get_by_mode(
166
+ self,
167
+ mode: str
168
+ ) -> Dict[str, ModelItem]:
155
169
  """
156
170
  Return models for mode
157
171
 
@@ -164,7 +178,11 @@ class Models:
164
178
  items[key] = self.items[key]
165
179
  return items
166
180
 
167
- def get_next(self, model: str, mode: str) -> str:
181
+ def get_next(
182
+ self,
183
+ model: str,
184
+ mode: str
185
+ ) -> str:
168
186
  """
169
187
  Return next model
170
188
 
@@ -179,7 +197,11 @@ class Models:
179
197
  return keys[idx + 1]
180
198
  return keys[0]
181
199
 
182
- def get_prev(self, model: str, mode: str) -> str:
200
+ def get_prev(
201
+ self,
202
+ model: str,
203
+ mode: str
204
+ ) -> str:
183
205
  """
184
206
  Return previous model
185
207
 
@@ -218,7 +240,7 @@ class Models:
218
240
  self.items[id] = model
219
241
  return model
220
242
 
221
- def get_all(self) -> dict:
243
+ def get_all(self) -> Dict[str, ModelItem]:
222
244
  """
223
245
  Return all models
224
246
 
@@ -248,7 +270,11 @@ class Models:
248
270
  if model in self.items:
249
271
  del self.items[model]
250
272
 
251
- def has_model(self, mode: str, model: str) -> bool:
273
+ def has_model(
274
+ self,
275
+ mode: str,
276
+ model: str
277
+ ) -> bool:
252
278
  """
253
279
  Check if model exists for mode
254
280
 
@@ -296,8 +322,15 @@ class Models:
296
322
  return self.items[model].ctx
297
323
  return 4096
298
324
 
299
- def restore_default(self, model: Optional[str] = None):
300
- """Restore default models"""
325
+ def restore_default(
326
+ self,
327
+ model: Optional[str] = None
328
+ ):
329
+ """
330
+ Restore default models
331
+
332
+ :param model: model name
333
+ """
301
334
  # restore all models
302
335
  if model is None:
303
336
  self.load_base()
@@ -308,8 +341,12 @@ class Models:
308
341
  if model in items:
309
342
  self.items[model] = items[model]
310
343
 
311
- def get_base(self) -> dict:
312
- """Get base models"""
344
+ def get_base(self) -> Dict[str, ModelItem]:
345
+ """
346
+ Get base models
347
+
348
+ :return: base models
349
+ """
313
350
  return self.provider.load_base()
314
351
 
315
352
  def load_base(self):
@@ -330,7 +367,11 @@ class Models:
330
367
  """Save models"""
331
368
  self.provider.save(self.items)
332
369
 
333
- def get_supported_mode(self, model: ModelItem, mode: str) -> str:
370
+ def get_supported_mode(
371
+ self,
372
+ model: ModelItem,
373
+ mode: str
374
+ ) -> str:
334
375
  """
335
376
  Get supported mode
336
377
 
@@ -353,5 +394,9 @@ class Models:
353
394
  return mode
354
395
 
355
396
  def get_version(self) -> str:
356
- """Get config version"""
397
+ """
398
+ Get config version
399
+
400
+ :return: config version
401
+ """
357
402
  return self.provider.get_version()
pygpt_net/core/modes.py CHANGED
@@ -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.26 19:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
+ from typing import Dict, List
13
+
12
14
  from pygpt_net.provider.core.mode.json_file import JsonFileProvider
13
15
  from pygpt_net.core.types import (
14
16
  MODE_AGENT,
@@ -51,7 +53,7 @@ class Modes:
51
53
  ]
52
54
  self.items = {}
53
55
 
54
- def get_by_idx(self, idx):
56
+ def get_by_idx(self, idx) -> str:
55
57
  """
56
58
  Return mode by index
57
59
 
@@ -61,7 +63,7 @@ class Modes:
61
63
  modes = self.get_all()
62
64
  return list(modes.keys())[idx]
63
65
 
64
- def get_idx_by_name(self, name):
66
+ def get_idx_by_name(self, name) -> int:
65
67
  """
66
68
  Return mode index by name
67
69
 
@@ -71,7 +73,7 @@ class Modes:
71
73
  modes = self.get_all()
72
74
  return list(modes.keys()).index(name)
73
75
 
74
- def get_all(self):
76
+ def get_all(self) -> Dict[str, List[str]]:
75
77
  """
76
78
  Return modes
77
79
 
@@ -79,7 +81,7 @@ class Modes:
79
81
  """
80
82
  return self.items
81
83
 
82
- def get_default(self):
84
+ def get_default(self) -> str:
83
85
  """
84
86
  Return default mode name
85
87
 
@@ -89,7 +91,7 @@ class Modes:
89
91
  if self.items[id].default:
90
92
  return id
91
93
 
92
- def get_next(self, mode: str):
94
+ def get_next(self, mode: str) -> str:
93
95
  """
94
96
  Return next mode
95
97
 
@@ -103,7 +105,7 @@ class Modes:
103
105
  return keys[idx + 1]
104
106
  return keys[0]
105
107
 
106
- def get_prev(self, mode: str):
108
+ def get_prev(self, mode: str) -> str:
107
109
  """
108
110
  Return previous mode
109
111
 
@@ -118,13 +120,9 @@ class Modes:
118
120
  return keys[-1]
119
121
 
120
122
  def load(self):
121
- """
122
- Load modes
123
- """
123
+ """Load modes"""
124
124
  self.items = self.provider.load()
125
125
 
126
126
  def save(self):
127
- """
128
- Save modes
129
- """
127
+ """Save modes"""
130
128
  self.provider.save(self.items)