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.
- CHANGELOG.md +8 -0
- README.md +135 -70
- pygpt_net/CHANGELOG.txt +8 -0
- pygpt_net/__init__.py +3 -3
- pygpt_net/app.py +3 -1
- pygpt_net/controller/audio/__init__.py +2 -2
- pygpt_net/controller/camera.py +1 -10
- pygpt_net/controller/chat/audio.py +2 -2
- pygpt_net/controller/config/placeholder.py +15 -1
- pygpt_net/controller/ui/mode.py +16 -21
- pygpt_net/core/audio/__init__.py +4 -1
- pygpt_net/core/audio/whisper.py +37 -0
- pygpt_net/core/bridge/worker.py +2 -2
- pygpt_net/core/debug/events.py +22 -10
- pygpt_net/core/debug/tabs.py +6 -3
- pygpt_net/core/history.py +3 -2
- pygpt_net/core/idx/__init__.py +16 -4
- pygpt_net/core/idx/chat.py +15 -5
- pygpt_net/core/idx/indexing.py +24 -8
- pygpt_net/core/installer.py +2 -4
- pygpt_net/core/models.py +62 -17
- pygpt_net/core/modes.py +11 -13
- pygpt_net/core/notepad.py +4 -4
- pygpt_net/core/plugins.py +27 -16
- pygpt_net/core/presets.py +20 -9
- pygpt_net/core/profile.py +11 -3
- pygpt_net/core/render/web/parser.py +3 -1
- pygpt_net/core/settings.py +5 -5
- pygpt_net/core/tabs/tab.py +10 -2
- pygpt_net/core/tokens.py +8 -6
- pygpt_net/core/web/__init__.py +105 -0
- pygpt_net/core/{web.py → web/helpers.py} +93 -67
- pygpt_net/data/config/config.json +3 -3
- pygpt_net/data/config/models.json +3 -3
- pygpt_net/data/config/modes.json +3 -3
- pygpt_net/data/locale/locale.en.ini +1 -0
- pygpt_net/data/locale/plugin.cmd_web.en.ini +2 -0
- pygpt_net/data/locale/plugin.mailer.en.ini +21 -0
- pygpt_net/item/ctx.py +13 -2
- pygpt_net/plugin/agent/__init__.py +7 -2
- pygpt_net/plugin/audio_output/__init__.py +6 -1
- pygpt_net/plugin/base/plugin.py +58 -26
- pygpt_net/plugin/base/worker.py +20 -17
- pygpt_net/plugin/cmd_history/config.py +2 -2
- pygpt_net/plugin/cmd_web/__init__.py +3 -4
- pygpt_net/plugin/cmd_web/config.py +71 -3
- pygpt_net/plugin/cmd_web/websearch.py +20 -12
- pygpt_net/plugin/cmd_web/worker.py +67 -4
- pygpt_net/plugin/idx_llama_index/config.py +3 -3
- pygpt_net/plugin/mailer/__init__.py +123 -0
- pygpt_net/plugin/mailer/config.py +149 -0
- pygpt_net/plugin/mailer/runner.py +285 -0
- pygpt_net/plugin/mailer/worker.py +123 -0
- pygpt_net/provider/agents/base.py +5 -2
- pygpt_net/provider/agents/openai.py +4 -2
- pygpt_net/provider/agents/openai_assistant.py +4 -2
- pygpt_net/provider/agents/planner.py +4 -2
- pygpt_net/provider/agents/react.py +4 -2
- pygpt_net/provider/audio_output/openai_tts.py +5 -11
- pygpt_net/provider/core/assistant/base.py +5 -3
- pygpt_net/provider/core/assistant/json_file.py +8 -5
- pygpt_net/provider/core/assistant_file/base.py +4 -3
- pygpt_net/provider/core/assistant_file/db_sqlite/__init__.py +4 -3
- pygpt_net/provider/core/assistant_file/db_sqlite/storage.py +3 -2
- pygpt_net/provider/core/assistant_store/base.py +6 -4
- pygpt_net/provider/core/assistant_store/db_sqlite/__init__.py +5 -4
- pygpt_net/provider/core/assistant_store/db_sqlite/storage.py +5 -3
- pygpt_net/provider/core/attachment/base.py +5 -3
- pygpt_net/provider/core/attachment/json_file.py +4 -3
- pygpt_net/provider/core/calendar/base.py +5 -3
- pygpt_net/provider/core/calendar/db_sqlite/__init__.py +6 -5
- pygpt_net/provider/core/calendar/db_sqlite/storage.py +5 -4
- pygpt_net/provider/core/config/base.py +8 -6
- pygpt_net/provider/core/config/json_file.py +9 -7
- pygpt_net/provider/core/ctx/base.py +27 -25
- pygpt_net/provider/core/ctx/db_sqlite/__init__.py +51 -35
- pygpt_net/provider/core/ctx/db_sqlite/storage.py +42 -31
- pygpt_net/provider/core/ctx/db_sqlite/utils.py +11 -9
- pygpt_net/provider/core/index/base.py +129 -23
- pygpt_net/provider/core/index/db_sqlite/__init__.py +130 -23
- pygpt_net/provider/core/index/db_sqlite/storage.py +130 -23
- pygpt_net/provider/core/index/db_sqlite/utils.py +4 -2
- pygpt_net/provider/core/mode/base.py +5 -3
- pygpt_net/provider/core/mode/json_file.py +7 -6
- pygpt_net/provider/core/model/base.py +6 -4
- pygpt_net/provider/core/model/json_file.py +9 -7
- pygpt_net/provider/core/notepad/base.py +5 -3
- pygpt_net/provider/core/notepad/db_sqlite/__init__.py +5 -4
- pygpt_net/provider/core/notepad/db_sqlite/storage.py +4 -3
- pygpt_net/provider/core/plugin_preset/base.py +4 -2
- pygpt_net/provider/core/plugin_preset/json_file.py +5 -3
- pygpt_net/provider/core/preset/base.py +6 -4
- pygpt_net/provider/core/preset/json_file.py +9 -9
- pygpt_net/provider/core/prompt/base.py +6 -3
- pygpt_net/provider/core/prompt/json_file.py +11 -6
- pygpt_net/provider/gpt/assistants.py +15 -6
- pygpt_net/provider/gpt/audio.py +5 -5
- pygpt_net/provider/gpt/chat.py +7 -5
- pygpt_net/provider/gpt/completion.py +8 -4
- pygpt_net/provider/gpt/image.py +3 -3
- pygpt_net/provider/gpt/store.py +46 -12
- pygpt_net/provider/gpt/vision.py +16 -11
- pygpt_net/provider/llms/anthropic.py +7 -2
- pygpt_net/provider/llms/azure_openai.py +26 -5
- pygpt_net/provider/llms/base.py +47 -9
- pygpt_net/provider/llms/google.py +7 -2
- pygpt_net/provider/llms/hugging_face.py +13 -3
- pygpt_net/provider/llms/hugging_face_api.py +18 -4
- pygpt_net/provider/llms/local.py +7 -2
- pygpt_net/provider/llms/ollama.py +30 -6
- pygpt_net/provider/llms/openai.py +32 -6
- pygpt_net/provider/vector_stores/__init__.py +45 -14
- pygpt_net/provider/vector_stores/base.py +35 -8
- pygpt_net/provider/vector_stores/chroma.py +13 -3
- pygpt_net/provider/vector_stores/ctx_attachment.py +31 -12
- pygpt_net/provider/vector_stores/elasticsearch.py +12 -3
- pygpt_net/provider/vector_stores/pinecode.py +12 -3
- pygpt_net/provider/vector_stores/redis.py +12 -3
- pygpt_net/provider/vector_stores/simple.py +12 -3
- pygpt_net/provider/vector_stores/temp.py +16 -4
- pygpt_net/provider/web/base.py +10 -3
- pygpt_net/provider/web/google_custom_search.py +9 -3
- pygpt_net/provider/web/microsoft_bing.py +9 -3
- pygpt_net/tools/__init__.py +13 -5
- pygpt_net/tools/audio_transcriber/__init__.py +4 -3
- pygpt_net/tools/base.py +15 -8
- pygpt_net/tools/code_interpreter/__init__.py +4 -3
- pygpt_net/tools/html_canvas/__init__.py +4 -3
- pygpt_net/tools/image_viewer/__init__.py +10 -4
- pygpt_net/tools/indexer/__init__.py +8 -7
- pygpt_net/tools/media_player/__init__.py +4 -3
- pygpt_net/tools/text_editor/__init__.py +36 -10
- pygpt_net/ui/layout/chat/output.py +2 -2
- pygpt_net/ui/menu/audio.py +12 -1
- {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/METADATA +136 -71
- {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/RECORD +139 -132
- {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/LICENSE +0 -0
- {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/WHEEL +0 -0
- {pygpt_net-2.4.41.dist-info → pygpt_net-2.4.42.dist-info}/entry_points.txt +0 -0
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.
|
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)
|
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
|
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) ->
|
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
|
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) ->
|
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) ->
|
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) ->
|
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) ->
|
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:
|
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:
|
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) ->
|
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(
|
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(
|
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(
|
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
|
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(
|
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) ->
|
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) ->
|
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(
|
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(
|
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
|
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(
|
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(
|
235
|
+
def append(
|
236
|
+
self,
|
237
|
+
uuid: str,
|
238
|
+
profile: Dict
|
239
|
+
):
|
232
240
|
"""
|
233
241
|
Append profile
|
234
242
|
|
pygpt_net/core/settings.py
CHANGED
@@ -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
|
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) ->
|
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) ->
|
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) ->
|
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
|
|
pygpt_net/core/tabs/tab.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
|
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
|
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:
|
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:
|
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:
|
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
|