pygpt-net 2.4.41__py3-none-any.whl → 2.4.42__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 (139) hide show
  1. CHANGELOG.md +8 -0
  2. README.md +135 -70
  3. pygpt_net/CHANGELOG.txt +8 -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/audio.py +2 -2
  9. pygpt_net/controller/config/placeholder.py +15 -1
  10. pygpt_net/controller/ui/mode.py +16 -21
  11. pygpt_net/core/audio/__init__.py +4 -1
  12. pygpt_net/core/audio/whisper.py +37 -0
  13. pygpt_net/core/bridge/worker.py +2 -2
  14. pygpt_net/core/debug/events.py +22 -10
  15. pygpt_net/core/debug/tabs.py +6 -3
  16. pygpt_net/core/history.py +3 -2
  17. pygpt_net/core/idx/__init__.py +16 -4
  18. pygpt_net/core/idx/chat.py +15 -5
  19. pygpt_net/core/idx/indexing.py +24 -8
  20. pygpt_net/core/installer.py +2 -4
  21. pygpt_net/core/models.py +62 -17
  22. pygpt_net/core/modes.py +11 -13
  23. pygpt_net/core/notepad.py +4 -4
  24. pygpt_net/core/plugins.py +27 -16
  25. pygpt_net/core/presets.py +20 -9
  26. pygpt_net/core/profile.py +11 -3
  27. pygpt_net/core/render/web/parser.py +3 -1
  28. pygpt_net/core/settings.py +5 -5
  29. pygpt_net/core/tabs/tab.py +10 -2
  30. pygpt_net/core/tokens.py +8 -6
  31. pygpt_net/core/web/__init__.py +105 -0
  32. pygpt_net/core/{web.py → web/helpers.py} +93 -67
  33. pygpt_net/data/config/config.json +3 -3
  34. pygpt_net/data/config/models.json +3 -3
  35. pygpt_net/data/config/modes.json +3 -3
  36. pygpt_net/data/locale/locale.en.ini +1 -0
  37. pygpt_net/data/locale/plugin.cmd_web.en.ini +2 -0
  38. pygpt_net/data/locale/plugin.mailer.en.ini +21 -0
  39. pygpt_net/item/ctx.py +13 -2
  40. pygpt_net/plugin/agent/__init__.py +7 -2
  41. pygpt_net/plugin/audio_output/__init__.py +6 -1
  42. pygpt_net/plugin/base/plugin.py +58 -26
  43. pygpt_net/plugin/base/worker.py +20 -17
  44. pygpt_net/plugin/cmd_history/config.py +2 -2
  45. pygpt_net/plugin/cmd_web/__init__.py +3 -4
  46. pygpt_net/plugin/cmd_web/config.py +71 -3
  47. pygpt_net/plugin/cmd_web/websearch.py +20 -12
  48. pygpt_net/plugin/cmd_web/worker.py +67 -4
  49. pygpt_net/plugin/idx_llama_index/config.py +3 -3
  50. pygpt_net/plugin/mailer/__init__.py +123 -0
  51. pygpt_net/plugin/mailer/config.py +149 -0
  52. pygpt_net/plugin/mailer/runner.py +285 -0
  53. pygpt_net/plugin/mailer/worker.py +123 -0
  54. pygpt_net/provider/agents/base.py +5 -2
  55. pygpt_net/provider/agents/openai.py +4 -2
  56. pygpt_net/provider/agents/openai_assistant.py +4 -2
  57. pygpt_net/provider/agents/planner.py +4 -2
  58. pygpt_net/provider/agents/react.py +4 -2
  59. pygpt_net/provider/audio_output/openai_tts.py +5 -11
  60. pygpt_net/provider/core/assistant/base.py +5 -3
  61. pygpt_net/provider/core/assistant/json_file.py +8 -5
  62. pygpt_net/provider/core/assistant_file/base.py +4 -3
  63. pygpt_net/provider/core/assistant_file/db_sqlite/__init__.py +4 -3
  64. pygpt_net/provider/core/assistant_file/db_sqlite/storage.py +3 -2
  65. pygpt_net/provider/core/assistant_store/base.py +6 -4
  66. pygpt_net/provider/core/assistant_store/db_sqlite/__init__.py +5 -4
  67. pygpt_net/provider/core/assistant_store/db_sqlite/storage.py +5 -3
  68. pygpt_net/provider/core/attachment/base.py +5 -3
  69. pygpt_net/provider/core/attachment/json_file.py +4 -3
  70. pygpt_net/provider/core/calendar/base.py +5 -3
  71. pygpt_net/provider/core/calendar/db_sqlite/__init__.py +6 -5
  72. pygpt_net/provider/core/calendar/db_sqlite/storage.py +5 -4
  73. pygpt_net/provider/core/config/base.py +8 -6
  74. pygpt_net/provider/core/config/json_file.py +9 -7
  75. pygpt_net/provider/core/ctx/base.py +27 -25
  76. pygpt_net/provider/core/ctx/db_sqlite/__init__.py +51 -35
  77. pygpt_net/provider/core/ctx/db_sqlite/storage.py +42 -31
  78. pygpt_net/provider/core/ctx/db_sqlite/utils.py +11 -9
  79. pygpt_net/provider/core/index/base.py +129 -23
  80. pygpt_net/provider/core/index/db_sqlite/__init__.py +130 -23
  81. pygpt_net/provider/core/index/db_sqlite/storage.py +130 -23
  82. pygpt_net/provider/core/index/db_sqlite/utils.py +4 -2
  83. pygpt_net/provider/core/mode/base.py +5 -3
  84. pygpt_net/provider/core/mode/json_file.py +7 -6
  85. pygpt_net/provider/core/model/base.py +6 -4
  86. pygpt_net/provider/core/model/json_file.py +9 -7
  87. pygpt_net/provider/core/notepad/base.py +5 -3
  88. pygpt_net/provider/core/notepad/db_sqlite/__init__.py +5 -4
  89. pygpt_net/provider/core/notepad/db_sqlite/storage.py +4 -3
  90. pygpt_net/provider/core/plugin_preset/base.py +4 -2
  91. pygpt_net/provider/core/plugin_preset/json_file.py +5 -3
  92. pygpt_net/provider/core/preset/base.py +6 -4
  93. pygpt_net/provider/core/preset/json_file.py +9 -9
  94. pygpt_net/provider/core/prompt/base.py +6 -3
  95. pygpt_net/provider/core/prompt/json_file.py +11 -6
  96. pygpt_net/provider/gpt/assistants.py +15 -6
  97. pygpt_net/provider/gpt/audio.py +5 -5
  98. pygpt_net/provider/gpt/chat.py +7 -5
  99. pygpt_net/provider/gpt/completion.py +8 -4
  100. pygpt_net/provider/gpt/image.py +3 -3
  101. pygpt_net/provider/gpt/store.py +46 -12
  102. pygpt_net/provider/gpt/vision.py +16 -11
  103. pygpt_net/provider/llms/anthropic.py +7 -2
  104. pygpt_net/provider/llms/azure_openai.py +26 -5
  105. pygpt_net/provider/llms/base.py +47 -9
  106. pygpt_net/provider/llms/google.py +7 -2
  107. pygpt_net/provider/llms/hugging_face.py +13 -3
  108. pygpt_net/provider/llms/hugging_face_api.py +18 -4
  109. pygpt_net/provider/llms/local.py +7 -2
  110. pygpt_net/provider/llms/ollama.py +30 -6
  111. pygpt_net/provider/llms/openai.py +32 -6
  112. pygpt_net/provider/vector_stores/__init__.py +45 -14
  113. pygpt_net/provider/vector_stores/base.py +35 -8
  114. pygpt_net/provider/vector_stores/chroma.py +13 -3
  115. pygpt_net/provider/vector_stores/ctx_attachment.py +31 -12
  116. pygpt_net/provider/vector_stores/elasticsearch.py +12 -3
  117. pygpt_net/provider/vector_stores/pinecode.py +12 -3
  118. pygpt_net/provider/vector_stores/redis.py +12 -3
  119. pygpt_net/provider/vector_stores/simple.py +12 -3
  120. pygpt_net/provider/vector_stores/temp.py +16 -4
  121. pygpt_net/provider/web/base.py +10 -3
  122. pygpt_net/provider/web/google_custom_search.py +9 -3
  123. pygpt_net/provider/web/microsoft_bing.py +9 -3
  124. pygpt_net/tools/__init__.py +13 -5
  125. pygpt_net/tools/audio_transcriber/__init__.py +4 -3
  126. pygpt_net/tools/base.py +15 -8
  127. pygpt_net/tools/code_interpreter/__init__.py +4 -3
  128. pygpt_net/tools/html_canvas/__init__.py +4 -3
  129. pygpt_net/tools/image_viewer/__init__.py +10 -4
  130. pygpt_net/tools/indexer/__init__.py +8 -7
  131. pygpt_net/tools/media_player/__init__.py +4 -3
  132. pygpt_net/tools/text_editor/__init__.py +36 -10
  133. pygpt_net/ui/layout/chat/output.py +2 -2
  134. pygpt_net/ui/menu/audio.py +12 -1
  135. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/METADATA +136 -71
  136. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/RECORD +139 -132
  137. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/LICENSE +0 -0
  138. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/WHEEL +0 -0
  139. {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.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.11.23 00:00:00 #
9
+ # Updated Date: 2024.12.14 19:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  from pygpt_net.core.types import (
@@ -189,8 +189,12 @@ class Mode:
189
189
  self.window.ui.tabs['input'].setTabVisible(2, False)
190
190
  self.window.ui.tabs['input'].setTabVisible(3, False)
191
191
 
192
- # toggle chat footer
193
- if not self.is_chat_tab():
192
+ # chat footer
193
+ self.toggle_chat_footer()
194
+
195
+ def toggle_chat_footer(self):
196
+ """Toggle chat footer"""
197
+ if self.window.controller.ui.tabs.get_current_type() != Tab.TAB_CHAT:
194
198
  self.hide_chat_footer()
195
199
  else:
196
200
  self.show_chat_footer()
@@ -200,18 +204,12 @@ class Mode:
200
204
  Check if vision is allowed
201
205
 
202
206
  :param mode: current mode
207
+ :return: True if vision is allowed
203
208
  """
204
- if mode == MODE_VISION:
205
- return True
206
-
207
- allowed = self.window.controller.painter.is_active()
208
- if allowed:
209
+ if self.window.controller.ui.vision.has_vision():
209
210
  return True
210
211
 
211
- if mode in [MODE_IMAGE, MODE_ASSISTANT]:
212
- return False
213
-
214
- if self.window.controller.ui.vision.is_vision_model():
212
+ if self.window.controller.painter.is_active():
215
213
  return True
216
214
 
217
215
  # event: UI: vision
@@ -224,7 +222,12 @@ class Mode:
224
222
  return event.data['value']
225
223
 
226
224
  def are_attachments(self, mode: str) -> bool:
227
- """Check if attachments are allowed"""
225
+ """
226
+ Check if attachments are allowed
227
+
228
+ :param mode: current mode
229
+ :return: True if attachments are allowed
230
+ """
228
231
  if mode in [MODE_VISION, MODE_ASSISTANT]:
229
232
  return True
230
233
 
@@ -243,14 +246,6 @@ class Mode:
243
246
  self.window.dispatch(event)
244
247
  return event.data['value']
245
248
 
246
- def is_chat_tab(self) -> bool:
247
- """
248
- Check if current tab is chat
249
-
250
- :return: True if chat tab
251
- """
252
- return self.window.controller.ui.tabs.get_current_type() == Tab.TAB_CHAT
253
-
254
249
  def show_chat_footer(self):
255
250
  """Show chat footer"""
256
251
  self.window.ui.nodes['chat.footer'].setVisible(True)
@@ -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 18:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import re
@@ -17,6 +17,8 @@ from bs4 import UnicodeDammit
17
17
  from pygpt_net.provider.audio_input.base import BaseProvider as InputBaseProvider
18
18
  from pygpt_net.provider.audio_output.base import BaseProvider as OutputBaseProvider
19
19
 
20
+ from .whisper import Whisper
21
+
20
22
 
21
23
  class Audio:
22
24
  def __init__(self, window=None):
@@ -26,6 +28,7 @@ class Audio:
26
28
  :param window: Window instance
27
29
  """
28
30
  self.window = window
31
+ self.whisper = Whisper(window)
29
32
  self.providers = {
30
33
  "input": {},
31
34
  "output": {},
@@ -0,0 +1,37 @@
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 18:00:00 #
10
+ # ================================================== #
11
+
12
+ from typing import List
13
+
14
+ class Whisper:
15
+ def __init__(self, window=None):
16
+ """
17
+ Whisper core
18
+
19
+ :param window: Window instance
20
+ """
21
+ self.window = window
22
+ self.voices = [
23
+ "alloy",
24
+ "echo",
25
+ "fable",
26
+ "onyx",
27
+ "nova",
28
+ "shimmer",
29
+ ]
30
+
31
+ def get_voices(self) -> List[str]:
32
+ """
33
+ Get whisper voices
34
+
35
+ :return: whisper voice name
36
+ """
37
+ return self.voices
@@ -60,14 +60,14 @@ class BridgeWorker(QObject, QRunnable):
60
60
  extra=self.extra,
61
61
  )
62
62
 
63
- # Llama-index: chat with files
63
+ # LlamaIndex: chat with files
64
64
  elif self.mode == MODE_LLAMA_INDEX:
65
65
  result = self.window.core.idx.chat.call(
66
66
  context=self.context,
67
67
  extra=self.extra,
68
68
  )
69
69
 
70
- # Llama-index: agents
70
+ # LlamaIndex: agents
71
71
  elif self.mode == MODE_AGENT_LLAMA:
72
72
  result = self.window.core.agents.runner.call(
73
73
  context=self.context,
@@ -6,10 +6,17 @@
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.20 03:00:00 #
9
+ # Updated Date: 2024.12.14 19:00:00 #
10
10
  # ================================================== #
11
11
 
12
- from pygpt_net.core.events import ControlEvent, AppEvent, Event, KernelEvent, RenderEvent
12
+ from pygpt_net.core.events import (
13
+ ControlEvent,
14
+ AppEvent,
15
+ Event,
16
+ KernelEvent,
17
+ RenderEvent,
18
+ BaseEvent
19
+ )
13
20
 
14
21
 
15
22
  class EventsDebug:
@@ -25,19 +32,24 @@ class EventsDebug:
25
32
  def update(self):
26
33
  """Update debug window."""
27
34
  self.window.core.debug.begin(self.id)
28
- self.window.core.debug.add(self.id, 'App Events:', str(AppEvent.__dict__))
29
- self.window.core.debug.add(self.id, 'Control Events:', str(ControlEvent.__dict__))
30
- self.window.core.debug.add(self.id, 'Kernel Events:', str(KernelEvent.__dict__))
31
- self.window.core.debug.add(self.id, 'Render Events:', str(RenderEvent.__dict__))
32
- self.window.core.debug.add(self.id, 'Plugin Events:', str(self.extract_plugins()))
35
+ self.window.core.debug.add(self.id, 'App Events:', str(self.extract_events(AppEvent)))
36
+ self.window.core.debug.add(self.id, 'Control Events:', str(self.extract_events(ControlEvent)))
37
+ self.window.core.debug.add(self.id, 'Kernel Events:', str(self.extract_events(KernelEvent)))
38
+ self.window.core.debug.add(self.id, 'Render Events:', str(self.extract_events(RenderEvent)))
39
+ self.window.core.debug.add(self.id, 'Plugin Events:', str(self.extract_events(Event)))
40
+ self.window.core.debug.add(self.id, '----', '')
33
41
  self.window.core.debug.add(self.id, 'Voice Cmds (all):', str(self.window.core.access.voice.commands))
34
42
  self.window.core.debug.add(self.id, 'Voice Cmds (allowed):', str(self.window.core.access.voice.get_commands()))
35
43
  self.window.core.debug.end(self.id)
36
44
 
37
- def extract_plugins(self) -> dict:
38
- """Extract plugin events"""
45
+ def extract_events(self, events: BaseEvent) -> dict:
46
+ """
47
+ Extract events
48
+
49
+ :param events: Events class
50
+ """
39
51
  result = {}
40
- for property, value in vars(Event).items():
52
+ for property, value in vars(events).items():
41
53
  if (isinstance(value, str)
42
54
  or isinstance(value, int)
43
55
  or isinstance(value, float)
@@ -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.12 01:00:00 #
9
+ # Updated Date: 2024.12.14 17:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  class TabsDebug:
@@ -22,10 +22,12 @@ class TabsDebug:
22
22
  def update(self):
23
23
  """Update debug window."""
24
24
  self.window.core.debug.begin(self.id)
25
- self.window.core.debug.add(self.id, 'current PID', str(self.window.controller.ui.tabs.get_current_pid()))
25
+ self.window.core.debug.add(self.id, 'current Col', str(self.window.controller.ui.tabs.get_current_column_idx()))
26
26
  self.window.core.debug.add(self.id, 'current IDX', str(self.window.controller.ui.tabs.get_current_idx()))
27
+ self.window.core.debug.add(self.id, 'current Tab', str(self.window.controller.ui.tabs.get_current_tab()))
28
+ self.window.core.debug.add(self.id, 'current PID', str(self.window.controller.ui.tabs.get_current_pid()))
27
29
  self.window.core.debug.add(self.id, 'current Type', str(self.window.controller.ui.tabs.get_current_type()))
28
- self.window.core.debug.add(self.id, 'current Column', str(self.window.controller.ui.tabs.get_current_column_idx()))
30
+ self.window.core.debug.add(self.id, '----', '')
29
31
  self.window.core.debug.add(self.id, 'last_pid', str(self.window.core.tabs.last_pid))
30
32
  self.window.core.debug.add(self.id, 'locked', str(self.window.controller.ui.tabs.locked))
31
33
  self.window.core.debug.add(self.id, 'col', str(self.window.controller.ui.tabs.col))
@@ -40,6 +42,7 @@ class TabsDebug:
40
42
  self.window.core.debug.add(self.id, "PID ["+str(pid)+"]", str(data))
41
43
 
42
44
  # mapping PID => meta.id
45
+ self.window.core.debug.add(self.id, '----', '')
43
46
  self.window.core.debug.add(self.id, 'PID => meta.id', str(self.window.core.ctx.output.mapping))
44
47
  self.window.core.debug.add(self.id, '(last) meta.id => PID', str(self.window.core.ctx.output.last_pids))
45
48
  self.window.core.debug.add(self.id, '(last) PID', str(self.window.core.ctx.output.last_pid))
pygpt_net/core/history.py CHANGED
@@ -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.01.19 05:00:00 #
9
+ # Updated Date: 2024.12.14 22:00:00 #
10
10
  # ================================================== #
11
11
 
12
12
  import datetime
13
13
  import os
14
+ from typing import List
14
15
 
15
16
  from pygpt_net.item.ctx import CtxItem
16
17
  from pygpt_net.provider.core.history.txt_file import TxtFileProvider
@@ -46,7 +47,7 @@ class History:
46
47
  # delete all txt history files from history dir
47
48
  self.provider.truncate()
48
49
 
49
- def remove_items(self, items: list):
50
+ def remove_items(self, items: List[CtxItem]):
50
51
  """
51
52
  Remove items from history (txt files)
52
53
 
@@ -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 datetime
@@ -406,7 +406,11 @@ class Idx:
406
406
  return self.items[store_id]
407
407
  return {}
408
408
 
409
- def append(self, idx: str, files: Dict[str, str]):
409
+ def append(
410
+ self,
411
+ idx: str,
412
+ files: Dict[str, str]
413
+ ):
410
414
  """
411
415
  Append indexed files to index
412
416
 
@@ -454,7 +458,11 @@ class Idx:
454
458
  self.items[store_id][idx].items[file_id]["id"] = doc_id
455
459
  self.items[store_id][idx].items[file_id]["indexed_ts"] = ts
456
460
 
457
- def remove_doc(self, idx: str, doc_id: str):
461
+ def remove_doc(
462
+ self,
463
+ idx: str,
464
+ doc_id: str
465
+ ):
458
466
  """
459
467
  Remove document from index
460
468
 
@@ -465,7 +473,11 @@ class Idx:
465
473
  if self.storage.remove_document(idx, doc_id):
466
474
  self.log("Removed document from index: " + idx + " - " + doc_id)
467
475
 
468
- def remove_file(self, idx: str, file: str):
476
+ def remove_file(
477
+ self,
478
+ idx: str,
479
+ file: str
480
+ ):
469
481
  """
470
482
  Remove file from index
471
483
 
@@ -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
@@ -360,7 +360,7 @@ class Chat:
360
360
  ctx: CtxItem,
361
361
  type: str,
362
362
  url: str,
363
- args: dict,
363
+ args: Dict[str, Any],
364
364
  query: str,
365
365
  model: Optional[ModelItem] = None
366
366
  ) -> str:
@@ -552,7 +552,11 @@ class Chat:
552
552
  ]
553
553
  return ChatPromptTemplate(qa_msgs)
554
554
 
555
- def get_index(self, idx: str, model: ModelItem):
555
+ def get_index(
556
+ self,
557
+ idx: str,
558
+ model: ModelItem
559
+ ):
556
560
  """
557
561
  Get index instance
558
562
 
@@ -573,7 +577,10 @@ class Chat:
573
577
  index = self.storage.get(idx, service_context=service_context) # get index
574
578
  return index, service_context
575
579
 
576
- def get_metadata(self, source_nodes: Optional[list]) -> Dict[str, Any]:
580
+ def get_metadata(
581
+ self,
582
+ source_nodes: Optional[list]
583
+ ) -> Dict[str, Any]:
577
584
  """
578
585
  Get metadata from source nodes
579
586
 
@@ -601,7 +608,10 @@ class Chat:
601
608
  break
602
609
  return metadata
603
610
 
604
- def parse_metadata(self, metadata: Optional[Dict]) -> Dict[str, Any]:
611
+ def parse_metadata(
612
+ self,
613
+ metadata: Optional[Dict]
614
+ ) -> Dict[str, Any]:
605
615
  """
606
616
  Parse metadata
607
617
 
@@ -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 datetime
@@ -600,7 +600,10 @@ class Indexing:
600
600
 
601
601
  return indexed, errors
602
602
 
603
- def get_db_data_from_ts(self, updated_ts: int = 0) -> list:
603
+ def get_db_data_from_ts(
604
+ self,
605
+ updated_ts: int = 0
606
+ ) -> List[Document]:
604
607
  """
605
608
  Get data from database from timestamp
606
609
 
@@ -640,7 +643,10 @@ class Indexing:
640
643
  documents.append(doc)
641
644
  return documents
642
645
 
643
- def get_db_meta_ids_from_ts(self, updated_ts: int = 0) -> list:
646
+ def get_db_meta_ids_from_ts(
647
+ self,
648
+ updated_ts: int = 0
649
+ ) -> List[int]:
644
650
  """
645
651
  Get IDs of meta from database from timestamp
646
652
 
@@ -664,7 +670,11 @@ class Indexing:
664
670
  ids.append(data["id"])
665
671
  return ids
666
672
 
667
- def get_db_data_by_id(self, id: int = 0, updated_ts: int = 0) -> list:
673
+ def get_db_data_by_id(
674
+ self,
675
+ id: int = 0,
676
+ updated_ts: int = 0
677
+ ) -> List[Document]:
668
678
  """
669
679
  Get data from database by meta id
670
680
 
@@ -726,7 +736,8 @@ class Indexing:
726
736
  self.window.core.idx.log("Indexing documents from database by meta id: {}".format(id))
727
737
  self.remove_old_meta_id(idx, id)
728
738
  elif from_ts > 0:
729
- self.window.core.idx.log("Indexing documents from database by meta id: {} from timestamp: {}".format(id, from_ts))
739
+ self.window.core.idx.log("Indexing documents from database by meta id: {} from timestamp: {}".
740
+ format(id, from_ts))
730
741
 
731
742
  # get items from database
732
743
  documents = self.get_db_data_by_id(id, from_ts)
@@ -736,7 +747,8 @@ class Indexing:
736
747
 
737
748
  self.index_document(index, d)
738
749
  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))
750
+ self.window.core.idx.log("Inserted ctx DB document: {} / {}, id: {}, metadata: {}".
751
+ format(n+1, len(documents), d.id_, d.metadata))
740
752
  self.window.core.ctx.idx.set_meta_as_indexed(id, idx, doc_id) # update ctx
741
753
  n += 1
742
754
  except Exception as e:
@@ -850,7 +862,8 @@ class Indexing:
850
862
  idx=idx,
851
863
  doc_id=doc_id,
852
864
  ) # update external index
853
- self.window.core.idx.log("Inserted web document: {} / {}, id: {}, metadata: {}".format(n+1, len(documents), d.id_, d.metadata))
865
+ self.window.core.idx.log("Inserted web document: {} / {}, id: {}, metadata: {}".
866
+ format(n+1, len(documents), d.id_, d.metadata))
854
867
  n += 1
855
868
  except Exception as e:
856
869
  errors.append(str(e))
@@ -1044,7 +1057,10 @@ class Indexing:
1044
1057
  model = self.window.core.models.from_defaults()
1045
1058
 
1046
1059
  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
1060
+ index = self.window.core.idx.storage.get_ctx_idx(
1061
+ index_path,
1062
+ service_context=service_context
1063
+ ) # get or create ctx index
1048
1064
 
1049
1065
  idx = "tmp:{}".format(index_path) # tmp index id
1050
1066
  self.window.core.idx.log("Indexing to context attachment index: {}...".format(idx))
@@ -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()