lollms-client 0.12.6__py3-none-any.whl → 0.13.0__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.
Potentially problematic release.
This version of lollms-client might be problematic. Click here for more details.
- examples/article_summary/article_summary.py +58 -0
- examples/deep_analyze/deep_analyse.py +30 -0
- examples/deep_analyze/deep_analyze_multiple_files.py +32 -0
- examples/function_call/functions_call_with images.py +52 -0
- examples/personality_test/chat_test.py +37 -0
- examples/personality_test/chat_with_aristotle.py +42 -0
- examples/personality_test/tesks_test.py +62 -0
- examples/simple_text_gen_test.py +171 -0
- examples/simple_text_gen_with_image_test.py +166 -0
- examples/test_local_models/local_chat.py +9 -0
- examples/text_2_audio.py +77 -0
- examples/text_2_image.py +140 -0
- examples/text_and_image_2_audio.py +59 -0
- examples/text_gen.py +28 -0
- lollms_client/__init__.py +2 -1
- lollms_client/llm_bindings/lollms/__init__.py +13 -11
- lollms_client/llm_bindings/ollama/__init__.py +8 -7
- lollms_client/llm_bindings/openai/__init__.py +69 -29
- lollms_client/llm_bindings/tensor_rt/__init__.py +603 -0
- lollms_client/llm_bindings/transformers/__init__.py +7 -11
- lollms_client/llm_bindings/vllm/__init__.py +603 -0
- lollms_client/lollms_core.py +0 -3
- lollms_client/lollms_llm_binding.py +5 -25
- {lollms_client-0.12.6.dist-info → lollms_client-0.13.0.dist-info}/METADATA +12 -12
- lollms_client-0.13.0.dist-info/RECORD +52 -0
- {lollms_client-0.12.6.dist-info → lollms_client-0.13.0.dist-info}/WHEEL +1 -1
- {lollms_client-0.12.6.dist-info → lollms_client-0.13.0.dist-info}/top_level.txt +1 -0
- lollms_client/lollms_personality.py +0 -403
- lollms_client/lollms_personality_worker.py +0 -1485
- lollms_client/lollms_stt.py +0 -35
- lollms_client/lollms_tti.py +0 -35
- lollms_client/lollms_tts.py +0 -39
- lollms_client-0.12.6.dist-info/RECORD +0 -41
- {lollms_client-0.12.6.dist-info → lollms_client-0.13.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -13,12 +13,7 @@ class LollmsLLMBinding(ABC):
|
|
|
13
13
|
"""Abstract base class for all LOLLMS LLM bindings"""
|
|
14
14
|
|
|
15
15
|
def __init__(self,
|
|
16
|
-
binding_name: Optional[str] ="unknown"
|
|
17
|
-
host_address: Optional[str] = None,
|
|
18
|
-
model_name: str = "",
|
|
19
|
-
service_key: Optional[str] = None,
|
|
20
|
-
verify_ssl_certificate: bool = True,
|
|
21
|
-
default_completion_format: ELF_COMPLETION_FORMAT = ELF_COMPLETION_FORMAT.Chat
|
|
16
|
+
binding_name: Optional[str] ="unknown"
|
|
22
17
|
):
|
|
23
18
|
"""
|
|
24
19
|
Initialize the LollmsLLMBinding base class.
|
|
@@ -31,14 +26,7 @@ class LollmsLLMBinding(ABC):
|
|
|
31
26
|
default_completion_format (ELF_COMPLETION_FORMAT): The completion format (Chat or Instruct)
|
|
32
27
|
"""
|
|
33
28
|
self.binding_name=binding_name
|
|
34
|
-
|
|
35
|
-
self.host_address = host_address[:-1] if host_address.endswith("/") else host_address
|
|
36
|
-
else:
|
|
37
|
-
self.host_address = None
|
|
38
|
-
self.model_name = model_name
|
|
39
|
-
self.service_key = service_key
|
|
40
|
-
self.verify_ssl_certificate = verify_ssl_certificate
|
|
41
|
-
self.default_completion_format = default_completion_format
|
|
29
|
+
self.model_name = None #Must be set by the instance
|
|
42
30
|
|
|
43
31
|
@abstractmethod
|
|
44
32
|
def generate_text(self,
|
|
@@ -188,21 +176,13 @@ class LollmsLLMBindingManager:
|
|
|
188
176
|
|
|
189
177
|
def create_binding(self,
|
|
190
178
|
binding_name: str,
|
|
191
|
-
|
|
192
|
-
model_name: str = "",
|
|
193
|
-
service_key: Optional[str] = None,
|
|
194
|
-
verify_ssl_certificate: bool = True,
|
|
195
|
-
personality: Optional[int] = None) -> Optional[LollmsLLMBinding]:
|
|
179
|
+
**kwargs) -> Optional[LollmsLLMBinding]:
|
|
196
180
|
"""
|
|
197
181
|
Create an instance of a specific binding.
|
|
198
182
|
|
|
199
183
|
Args:
|
|
200
184
|
binding_name (str): Name of the binding to create.
|
|
201
|
-
|
|
202
|
-
model_name (str): Name of the model to use.
|
|
203
|
-
service_key (Optional[str]): Authentication key for the service.
|
|
204
|
-
verify_ssl_certificate (bool): Whether to verify SSL certificates.
|
|
205
|
-
personality (Optional[int]): Personality ID for LOLLMS binding.
|
|
185
|
+
kwargs: binding specific arguments
|
|
206
186
|
|
|
207
187
|
Returns:
|
|
208
188
|
Optional[LollmsLLMBinding]: Binding instance or None if creation failed.
|
|
@@ -212,7 +192,7 @@ class LollmsLLMBindingManager:
|
|
|
212
192
|
|
|
213
193
|
binding_class = self.available_bindings.get(binding_name)
|
|
214
194
|
if binding_class:
|
|
215
|
-
return binding_class(
|
|
195
|
+
return binding_class(**kwargs)
|
|
216
196
|
return None
|
|
217
197
|
|
|
218
198
|
def get_available_bindings(self) -> list[str]:
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lollms_client
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.13.0
|
|
4
4
|
Summary: A client library for LoLLMs generate endpoint
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Author-email: ParisNeo <parisneoai@gmail.com>
|
|
6
|
+
License: Apache Software License
|
|
7
|
+
Project-URL: Homepage, https://github.com/ParisNeo/lollms_client
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
14
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
15
|
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Requires-Python: >=3.7
|
|
11
19
|
Description-Content-Type: text/markdown
|
|
12
20
|
License-File: LICENSE
|
|
13
21
|
Requires-Dist: requests
|
|
14
|
-
Dynamic: author
|
|
15
|
-
Dynamic: author-email
|
|
16
|
-
Dynamic: classifier
|
|
17
|
-
Dynamic: description
|
|
18
|
-
Dynamic: description-content-type
|
|
19
|
-
Dynamic: home-page
|
|
20
22
|
Dynamic: license-file
|
|
21
|
-
Dynamic: requires-dist
|
|
22
|
-
Dynamic: summary
|
|
23
23
|
|
|
24
24
|
# lollms_client
|
|
25
25
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
examples/simple_text_gen_test.py,sha256=CqBvkG7Zm2ya13AxgRKlhV1M4PiqeSOi9--yKL8MZ-E,8596
|
|
2
|
+
examples/simple_text_gen_with_image_test.py,sha256=Euv53jbKTVJDvs854lgJvA5F-iRnAATLxAklig24ots,8534
|
|
3
|
+
examples/text_2_audio.py,sha256=MfL4AH_NNwl6m0I0ywl4BXRZJ0b9Y_9fRqDIe6O-Sbw,3523
|
|
4
|
+
examples/text_2_image.py,sha256=Ri7lQ-GW54YWQh2eofcaN6LpwFoorbpJsJffrcXl3cg,6415
|
|
5
|
+
examples/text_and_image_2_audio.py,sha256=QLvSsLff8VZZa7k7K1EFGlPpQWZy07zM4Fnli5btAl0,2074
|
|
6
|
+
examples/text_gen.py,sha256=S1UIXi3Aj8gTAmwHXtg-qUfgSkyCJFDLVKAbiOfsYGs,773
|
|
7
|
+
examples/article_summary/article_summary.py,sha256=CR8mCBNcZEVCR-q34uOmrJyMlG-xk4HkMbsV-TOZEnk,1978
|
|
8
|
+
examples/deep_analyze/deep_analyse.py,sha256=fZNmDrfEAuxEAfdbjAgJYIh1k6wbiuZ4RvwHRvtyUs8,971
|
|
9
|
+
examples/deep_analyze/deep_analyze_multiple_files.py,sha256=fOryShA33P4IFxcxUDe-nJ2kW0v9w9yW8KsToS3ETl8,1032
|
|
10
|
+
examples/function_call/functions_call_with images.py,sha256=jrNtTF7lAzad25Ob0Yv4pwLs12HSzDamKKR9ORkNWjc,1888
|
|
11
|
+
examples/personality_test/chat_test.py,sha256=o2jlpoddFc-T592iqAiA29xk3x27KsdK5DluqxBwHqw,1417
|
|
12
|
+
examples/personality_test/chat_with_aristotle.py,sha256=4X_fwubMpd0Eq2rCReS2bgVlUoAqJprjkLXk2Jz6pXU,1774
|
|
13
|
+
examples/personality_test/tesks_test.py,sha256=7LIiwrEbva9WWZOLi34fsmCBN__RZbPpxoUOKA_AtYk,1924
|
|
14
|
+
examples/test_local_models/local_chat.py,sha256=slakja2zaHOEAUsn2tn_VmI4kLx6luLBrPqAeaNsix8,456
|
|
15
|
+
lollms_client/__init__.py,sha256=5Rs-Uis0zGVg94icdyXKveRFsva8Vh1otWtGDKEfSsw,821
|
|
16
|
+
lollms_client/lollms_config.py,sha256=goEseDwDxYJf3WkYJ4IrLXwg3Tfw73CXV2Avg45M_hE,21876
|
|
17
|
+
lollms_client/lollms_core.py,sha256=_iTQY64ePop-6YxA2Xb90CxuiF9gzz9c5SHcLUsJxVc,77559
|
|
18
|
+
lollms_client/lollms_discussion.py,sha256=9b83m0D894jwpgssWYTQHbVxp1gJoI-J947Ui_dRXII,2073
|
|
19
|
+
lollms_client/lollms_functions.py,sha256=p8SFtmEPqvVCsIz2fZ5HxyOHaxjrAo5c12uTzJnb6m8,3594
|
|
20
|
+
lollms_client/lollms_js_analyzer.py,sha256=01zUvuO2F_lnUe_0NLxe1MF5aHE1hO8RZi48mNPv-aw,8361
|
|
21
|
+
lollms_client/lollms_llm_binding.py,sha256=vAFmGtdIB97nQwQzNauFowopH4qT2i-CS_-ckekY3V0,7361
|
|
22
|
+
lollms_client/lollms_python_analyzer.py,sha256=7gf1fdYgXCOkPUkBAPNmr6S-66hMH4_KonOMsADASxc,10246
|
|
23
|
+
lollms_client/lollms_stt_binding.py,sha256=ovmpFF0fnmPC9VNi1-rxAJA8xI4JZDUBh_YwdtoTx28,5818
|
|
24
|
+
lollms_client/lollms_tasks.py,sha256=Tgqces03gPTHFJCcPaeN9vBCsil3SSJX7nQAjCQ2-yg,34393
|
|
25
|
+
lollms_client/lollms_tti_binding.py,sha256=CBCdXt6GQzRPzq7eEujQ5mBOoYcqUUdYY-POHLbJhx8,7469
|
|
26
|
+
lollms_client/lollms_ttm_binding.py,sha256=ymGvHtFqesm32y1ZoyIgMBC1PckTABS-DOh-8SvMkRs,5706
|
|
27
|
+
lollms_client/lollms_tts_binding.py,sha256=c4PQVe6NyPUtNguKMPo5L2nHJXjoIEQpCtVLK06p_iA,5880
|
|
28
|
+
lollms_client/lollms_ttv_binding.py,sha256=u-gLIe22tbu4YsKA5RTyUT7iBlKxPXDmoQzccG3_KuA,5672
|
|
29
|
+
lollms_client/lollms_types.py,sha256=cfc1sremM8KR4avkYX99fIVkkdRvXErrCWKGjLrgv50,2723
|
|
30
|
+
lollms_client/lollms_utilities.py,sha256=YAgamfp0pBVApR68AHKjhp1lh6isMNF8iadwWLl63c0,7045
|
|
31
|
+
lollms_client/llm_bindings/__init__.py,sha256=9sWGpmWSSj6KQ8H4lKGCjpLYwhnVdL_2N7gXCphPqh4,14
|
|
32
|
+
lollms_client/llm_bindings/lollms/__init__.py,sha256=l1q2KnMQALz9QpLa3OUQ8e29KU4RCwkrmrdBvd7Z_kc,12236
|
|
33
|
+
lollms_client/llm_bindings/ollama/__init__.py,sha256=mKGLeoRVpKW1YW4fnLQ4KlgbgHsN4i5TTfG3B4CxwVA,28428
|
|
34
|
+
lollms_client/llm_bindings/openai/__init__.py,sha256=SWBgnOcOWmFRSKTN1S9ATownHNBJ9f6FEtI3L4xNJNM,11861
|
|
35
|
+
lollms_client/llm_bindings/tensor_rt/__init__.py,sha256=ZpeSKAbN8rh6zkysYl95sXG9Ci702NuPAhXC6zb1zT4,31840
|
|
36
|
+
lollms_client/llm_bindings/transformers/__init__.py,sha256=8JbX3B-obLt5NNtcNOGD_E0f8OQTma2pNYtVt2urTOM,12572
|
|
37
|
+
lollms_client/llm_bindings/vllm/__init__.py,sha256=54TxuHJhlujVxPN03BgfeUecIexTjvU6g1dVmmaDgtM,31824
|
|
38
|
+
lollms_client/stt_bindings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
39
|
+
lollms_client/stt_bindings/lollms/__init__.py,sha256=7-IZkrsn15Vaz0oqkqCxMeNQfMkeilbgScLlrrywES4,6098
|
|
40
|
+
lollms_client/tti_bindings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
41
|
+
lollms_client/tti_bindings/lollms/__init__.py,sha256=y1mcAsaYnWUVEw1Wq3Gxur4srwKDWu2IKRgwtsSPifY,9082
|
|
42
|
+
lollms_client/ttm_bindings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
|
+
lollms_client/ttm_bindings/lollms/__init__.py,sha256=DU3WLmJaWNM1NAMtJsnaFo4Y9wlfc675M8aUiaLnojA,3143
|
|
44
|
+
lollms_client/tts_bindings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
45
|
+
lollms_client/tts_bindings/lollms/__init__.py,sha256=8x2_T9XscvISw2TiaLoFxvrS7TIsVLdqbwSc04cX-wc,7164
|
|
46
|
+
lollms_client/ttv_bindings/__init__.py,sha256=UZ8o2izQOJLQgtZ1D1cXoNST7rzqW22rL2Vufc7ddRc,3141
|
|
47
|
+
lollms_client/ttv_bindings/lollms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
48
|
+
lollms_client-0.13.0.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
49
|
+
lollms_client-0.13.0.dist-info/METADATA,sha256=I5sQiDvtijyYe72vvQWBjecdglA_-oyfY4I9W23eUZw,7103
|
|
50
|
+
lollms_client-0.13.0.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
|
51
|
+
lollms_client-0.13.0.dist-info/top_level.txt,sha256=NI_W8S4OYZvJjb0QWMZMSIpOrYzpqwPGYaklhyWKH2w,23
|
|
52
|
+
lollms_client-0.13.0.dist-info/RECORD,,
|
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
from lollms_client import LollmsClient
|
|
3
|
-
from lollms_client.lollms_types import MSG_TYPE
|
|
4
|
-
from lollms_client.lollms_discussion import LollmsDiscussion
|
|
5
|
-
from lollms_client.lollms_utilities import PromptReshaper
|
|
6
|
-
import pkg_resources
|
|
7
|
-
from typing import List, Optional, Union, Callable
|
|
8
|
-
|
|
9
|
-
from lollmsvectordb.vector_database import VectorDatabase
|
|
10
|
-
from lollmsvectordb.text_document_loader import TextDocumentsLoader
|
|
11
|
-
from lollmsvectordb.text_chunker import TextChunker
|
|
12
|
-
|
|
13
|
-
from PIL import Image
|
|
14
|
-
import importlib
|
|
15
|
-
import yaml
|
|
16
|
-
from ascii_colors import ASCIIColors
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class LollmsPersonality:
|
|
20
|
-
|
|
21
|
-
# Extra
|
|
22
|
-
def __init__(
|
|
23
|
-
self,
|
|
24
|
-
lollmsClient:LollmsClient, # Assuming the type for lollmsClient is defined elsewhere
|
|
25
|
-
personality_work_dir: Union[str, Path],
|
|
26
|
-
personality_config_dir: Union[str, Path],
|
|
27
|
-
callback: Callable[[str, MSG_TYPE, dict, list], bool],
|
|
28
|
-
personality_package_path: Optional[Union[str, Path]] = None,
|
|
29
|
-
author: Optional[str] = None,
|
|
30
|
-
name: Optional[str] = None,
|
|
31
|
-
user_name: Optional[str] = None,
|
|
32
|
-
category: Optional[str] = None,
|
|
33
|
-
category_desc: Optional[str] = None,
|
|
34
|
-
language: Optional[str] = None,
|
|
35
|
-
supported_languages: Optional[List[str]] = None,
|
|
36
|
-
personality_description: Optional[str] = None,
|
|
37
|
-
personality_conditioning: Optional[str] = None,
|
|
38
|
-
welcome_message: Optional[str] = None,
|
|
39
|
-
include_welcome_message_in_discussion: Optional[bool] = None,
|
|
40
|
-
user_message_prefix: Optional[str] = None,
|
|
41
|
-
ai_message_prefix: Optional[str] = None,
|
|
42
|
-
anti_prompts: Optional[List[str]] = None,
|
|
43
|
-
model_temperature: Optional[float] = 0.1,
|
|
44
|
-
model_n_predicts: Optional[int] = 2048,
|
|
45
|
-
model_top_k: Optional[int] = 50,
|
|
46
|
-
model_top_p: Optional[float] = 0.95,
|
|
47
|
-
model_repeat_penalty: Optional[float] = 1.3,
|
|
48
|
-
model_repeat_last_n: Optional[int] = 40,
|
|
49
|
-
logo: Optional[Image.Image] = None,
|
|
50
|
-
):
|
|
51
|
-
"""
|
|
52
|
-
Initialize an LollmsPersonality instance.
|
|
53
|
-
|
|
54
|
-
Parameters:
|
|
55
|
-
personality_package_path (str or Path): The path to the folder containing the personality package.
|
|
56
|
-
Other optional parameters are attributes of the personality that can be provided upon initialization.
|
|
57
|
-
|
|
58
|
-
Raises:
|
|
59
|
-
ValueError: If the provided path is not a folder or does not contain a config.yaml file.
|
|
60
|
-
"""
|
|
61
|
-
self.bot_says = ""
|
|
62
|
-
|
|
63
|
-
self.lollmsClient = lollmsClient
|
|
64
|
-
self.personality_work_dir = Path(personality_work_dir)
|
|
65
|
-
self.personality_config_dir =Path(personality_config_dir)
|
|
66
|
-
|
|
67
|
-
self.callback = callback
|
|
68
|
-
|
|
69
|
-
self.text_files = []
|
|
70
|
-
self.image_files = []
|
|
71
|
-
self.audio_files = []
|
|
72
|
-
self.images_descriptions = []
|
|
73
|
-
self.vectorizer = None
|
|
74
|
-
|
|
75
|
-
# Whisper to transcribe audio
|
|
76
|
-
self.whisper = None
|
|
77
|
-
|
|
78
|
-
# First setup a default personality
|
|
79
|
-
# Version
|
|
80
|
-
self._version = pkg_resources.get_distribution('lollms_client').version
|
|
81
|
-
|
|
82
|
-
# General information
|
|
83
|
-
self.author: str = author if author is not None else "ParisNeo"
|
|
84
|
-
self.name: str = name if name is not None else "lollms"
|
|
85
|
-
self.user_name: str = user_name if user_name is not None else "user"
|
|
86
|
-
self.category: str = category if category is not None else "General"
|
|
87
|
-
self.category_desc: str = category_desc if category_desc is not None else "General purpose AI"
|
|
88
|
-
self.language: str = language if language is not None else "english"
|
|
89
|
-
self.supported_languages: List[str] = supported_languages if supported_languages is not None else []
|
|
90
|
-
|
|
91
|
-
# Conditioning
|
|
92
|
-
self.personality_description: str = personality_description if personality_description is not None else "This personality is a helpful and Kind AI ready to help you solve your problems"
|
|
93
|
-
self.personality_conditioning: str = personality_conditioning if personality_conditioning is not None else "\n".join([
|
|
94
|
-
"!@>system:",
|
|
95
|
-
"lollms (Lord of LLMs) is a smart and helpful Assistant built by the computer geek ParisNeo.",
|
|
96
|
-
"It is compatible with many bindings to LLM models such as llama, gpt4all, gptj, autogptq etc.",
|
|
97
|
-
"It can discuss with humans and assist them on many subjects.",
|
|
98
|
-
"It runs locally on your machine. No need to connect to the internet.",
|
|
99
|
-
"It answers the questions with precise details",
|
|
100
|
-
"Its performance depends on the underlying model size and training.",
|
|
101
|
-
"Try to answer with as much details as you can",
|
|
102
|
-
"Date: {{date}}",
|
|
103
|
-
])
|
|
104
|
-
self.welcome_message: str = welcome_message if welcome_message is not None else "Welcome! I am lollms (Lord of LLMs) A free and open assistant built by ParisNeo. What can I do for you today?"
|
|
105
|
-
self.include_welcome_message_in_discussion: bool = include_welcome_message_in_discussion if include_welcome_message_in_discussion is not None else True
|
|
106
|
-
self.user_message_prefix: str = user_message_prefix if user_message_prefix is not None else "!@>human: "
|
|
107
|
-
self.link_text: str = "\n"
|
|
108
|
-
self.ai_message_prefix: str = ai_message_prefix if ai_message_prefix is not None else "!@>lollms:"
|
|
109
|
-
self.anti_prompts:list = anti_prompts if anti_prompts is not None else ["!@>"]
|
|
110
|
-
|
|
111
|
-
# Extra
|
|
112
|
-
self.dependencies: List[str] = []
|
|
113
|
-
|
|
114
|
-
# Disclaimer
|
|
115
|
-
self.disclaimer: str = ""
|
|
116
|
-
self.help: str = ""
|
|
117
|
-
self.commands: list = []
|
|
118
|
-
|
|
119
|
-
# Default model parameters
|
|
120
|
-
self.model_temperature: float = model_temperature # higher: more creative, lower more deterministic
|
|
121
|
-
self.model_n_predicts: int = model_n_predicts # higher: generates many words, lower generates
|
|
122
|
-
self.model_top_k: int = model_top_k
|
|
123
|
-
self.model_top_p: float = model_top_p
|
|
124
|
-
self.model_repeat_penalty: float = model_repeat_penalty
|
|
125
|
-
self.model_repeat_last_n: int = model_repeat_last_n
|
|
126
|
-
|
|
127
|
-
self.logo: Optional[Image.Image] = logo
|
|
128
|
-
self.processor = None
|
|
129
|
-
self.data = None
|
|
130
|
-
|
|
131
|
-
if personality_package_path is None:
|
|
132
|
-
self.config = {}
|
|
133
|
-
self.assets_list = []
|
|
134
|
-
self.personality_package_path = None
|
|
135
|
-
|
|
136
|
-
self.conditionning_len = len(self.lollmsClient.tokenize(self.personality_conditioning+"\n"))
|
|
137
|
-
self.welcome_len = len(self.lollmsClient.tokenize(self.ai_message_prefix+self.welcome_message+"\n"))
|
|
138
|
-
self.preambule_len=self.conditionning_len
|
|
139
|
-
if self.include_welcome_message_in_discussion:
|
|
140
|
-
self.preambule = self.personality_conditioning+"\n"+self.ai_message_prefix+self.welcome_message+"\n"
|
|
141
|
-
self.preambule_len+=self.welcome_len
|
|
142
|
-
|
|
143
|
-
return
|
|
144
|
-
else:
|
|
145
|
-
self.personality_package_path = Path(personality_package_path)
|
|
146
|
-
# Validate that the path exists
|
|
147
|
-
if not self.personality_package_path.exists():
|
|
148
|
-
raise ValueError(f"Could not find the personality package:{self.personality_package_path}")
|
|
149
|
-
|
|
150
|
-
# Validate that the path format is OK with at least a config.yaml file present in the folder
|
|
151
|
-
if not self.personality_package_path.is_dir():
|
|
152
|
-
raise ValueError(f"Personality package path is not a folder:{self.personality_package_path}")
|
|
153
|
-
|
|
154
|
-
self.personality_folder_name = self.personality_package_path.stem
|
|
155
|
-
|
|
156
|
-
# Open and store the personality
|
|
157
|
-
self.load_personality()
|
|
158
|
-
self.personality_work_dir.mkdir(parents=True, exist_ok=True)
|
|
159
|
-
self.personality_config_dir.mkdir(parents=True, exist_ok=True)
|
|
160
|
-
|
|
161
|
-
self.conditionning_len = len(self.lollmsClient.tokenize(self.personality_conditioning+"\n"))
|
|
162
|
-
self.welcome_len = len(self.lollmsClient.tokenize(self.ai_message_prefix+self.welcome_message+"\n"))
|
|
163
|
-
self.preambule_len=self.conditionning_len
|
|
164
|
-
if self.include_welcome_message_in_discussion:
|
|
165
|
-
self.preambule = self.personality_conditioning+"\n"+self.ai_message_prefix+self.welcome_message+"\n"
|
|
166
|
-
self.preambule_len+=self.welcome_len
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def load_personality(self, package_path=None):
|
|
171
|
-
"""
|
|
172
|
-
Load personality parameters from a YAML configuration file.
|
|
173
|
-
|
|
174
|
-
Args:
|
|
175
|
-
package_path (str or Path): The path to the package directory.
|
|
176
|
-
|
|
177
|
-
Raises:
|
|
178
|
-
ValueError: If the configuration file does not exist.
|
|
179
|
-
"""
|
|
180
|
-
if package_path is None:
|
|
181
|
-
package_path = self.personality_package_path
|
|
182
|
-
else:
|
|
183
|
-
package_path = Path(package_path)
|
|
184
|
-
|
|
185
|
-
# Verify that there is at least a configuration file
|
|
186
|
-
config_file = package_path / "config.yaml"
|
|
187
|
-
if not config_file.exists():
|
|
188
|
-
raise ValueError(f"The provided folder {package_path} does not exist.")
|
|
189
|
-
|
|
190
|
-
with open(config_file, "r", encoding='utf-8') as f:
|
|
191
|
-
config = yaml.safe_load(f)
|
|
192
|
-
|
|
193
|
-
secret_file = package_path / "secret.yaml"
|
|
194
|
-
if secret_file.exists():
|
|
195
|
-
with open(secret_file, "r", encoding='utf-8') as f:
|
|
196
|
-
self._secret_cfg = yaml.safe_load(f)
|
|
197
|
-
else:
|
|
198
|
-
self._secret_cfg = None
|
|
199
|
-
|
|
200
|
-
languages = package_path / "languages"
|
|
201
|
-
|
|
202
|
-
if languages.exists():
|
|
203
|
-
self._supported_languages = []
|
|
204
|
-
for language in [l for l in languages.iterdir()]:
|
|
205
|
-
self._supported_languages.append(language.stem)
|
|
206
|
-
|
|
207
|
-
if self._selected_language is not None and self._selected_language in self._supported_languages:
|
|
208
|
-
config_file = languages / (self._selected_language+".yaml")
|
|
209
|
-
with open(config_file, "r", encoding='utf-8') as f:
|
|
210
|
-
config = yaml.safe_load(f)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
# Load parameters from the configuration file
|
|
215
|
-
self._version = config.get("version", self._version)
|
|
216
|
-
self._author = config.get("author", self._author)
|
|
217
|
-
self._name = config.get("name", self._name)
|
|
218
|
-
self._user_name = config.get("user_name", self._user_name)
|
|
219
|
-
self._category_desc = config.get("category", self._category)
|
|
220
|
-
self._language = config.get("language", self._language)
|
|
221
|
-
|
|
222
|
-
self._ignore_discussion_documents_rag = config.get("ignore_discussion_documents_rag", self._ignore_discussion_documents_rag)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
self._personality_description = config.get("personality_description", self._personality_description)
|
|
226
|
-
self._personality_conditioning = config.get("personality_conditioning", self._personality_conditioning)
|
|
227
|
-
self._prompts_list = config.get("prompts_list", self._prompts_list)
|
|
228
|
-
self._welcome_message = config.get("welcome_message", self._welcome_message)
|
|
229
|
-
self._include_welcome_message_in_discussion = config.get("include_welcome_message_in_discussion", self._include_welcome_message_in_discussion)
|
|
230
|
-
|
|
231
|
-
self._user_message_prefix = config.get("user_message_prefix", self._user_message_prefix)
|
|
232
|
-
self._link_text = config.get("link_text", self._link_text)
|
|
233
|
-
self._ai_message_prefix = config.get("ai_message_prefix", self._ai_message_prefix)
|
|
234
|
-
self._dependencies = config.get("dependencies", self._dependencies)
|
|
235
|
-
self._disclaimer = config.get("disclaimer", self._disclaimer)
|
|
236
|
-
self._help = config.get("help", self._help)
|
|
237
|
-
self._commands = config.get("commands", self._commands)
|
|
238
|
-
self._model_temperature = config.get("model_temperature", self._model_temperature)
|
|
239
|
-
self._model_top_k = config.get("model_top_k", self._model_top_k)
|
|
240
|
-
self._model_top_p = config.get("model_top_p", self._model_top_p)
|
|
241
|
-
self._model_repeat_penalty = config.get("model_repeat_penalty", self._model_repeat_penalty)
|
|
242
|
-
self._model_repeat_last_n = config.get("model_repeat_last_n", self._model_repeat_last_n)
|
|
243
|
-
|
|
244
|
-
# Script parameters (for example keys to connect to search engine or any other usage)
|
|
245
|
-
self._processor_cfg = config.get("processor_cfg", self._processor_cfg)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
#set package path
|
|
249
|
-
self.personality_package_path = package_path
|
|
250
|
-
|
|
251
|
-
# Check for a logo file
|
|
252
|
-
self.logo_path = self.personality_package_path / "assets" / "logo.png"
|
|
253
|
-
if self.logo_path.is_file():
|
|
254
|
-
self._logo = Image.open(self.logo_path)
|
|
255
|
-
|
|
256
|
-
# Get the assets folder path
|
|
257
|
-
self.assets_path = self.personality_package_path / "assets"
|
|
258
|
-
# Get the scripts folder path
|
|
259
|
-
self.scripts_path = self.personality_package_path / "scripts"
|
|
260
|
-
# Get the languages folder path
|
|
261
|
-
self.languages_path = self.personality_package_path / "languages"
|
|
262
|
-
# Get the data folder path
|
|
263
|
-
self.data_path = self.personality_package_path / "data"
|
|
264
|
-
# Get the data folder path
|
|
265
|
-
self.audio_path = self.personality_package_path / "audio"
|
|
266
|
-
# Get the data folder path
|
|
267
|
-
self.welcome_audio_path = self.personality_package_path / "welcome_audio"
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
# If not exist recreate
|
|
271
|
-
self.assets_path.mkdir(parents=True, exist_ok=True)
|
|
272
|
-
|
|
273
|
-
# If not exist recreate
|
|
274
|
-
self.scripts_path.mkdir(parents=True, exist_ok=True)
|
|
275
|
-
|
|
276
|
-
# If not exist recreate
|
|
277
|
-
self.audio_path.mkdir(parents=True, exist_ok=True)
|
|
278
|
-
|
|
279
|
-
# samples
|
|
280
|
-
self.audio_samples = [f for f in self.audio_path.iterdir()]
|
|
281
|
-
|
|
282
|
-
# Verify if the persona has a data folder
|
|
283
|
-
if self.data_path.exists():
|
|
284
|
-
self.database_path = self.data_path / "db.sqlite"
|
|
285
|
-
from lollmsvectordb.lollms_tokenizers.tiktoken_tokenizer import TikTokenTokenizer
|
|
286
|
-
|
|
287
|
-
if self.config.rag_vectorizer == "semantic":
|
|
288
|
-
from lollmsvectordb.lollms_vectorizers.semantic_vectorizer import SemanticVectorizer
|
|
289
|
-
v = SemanticVectorizer()
|
|
290
|
-
elif self.config.rag_vectorizer == "tfidf":
|
|
291
|
-
from lollmsvectordb.lollms_vectorizers.tfidf_vectorizer import TFIDFVectorizer
|
|
292
|
-
v = TFIDFVectorizer()
|
|
293
|
-
elif self.config.rag_vectorizer == "openai":
|
|
294
|
-
from lollmsvectordb.lollms_vectorizers.openai_vectorizer import OpenAIVectorizer
|
|
295
|
-
v = OpenAIVectorizer(api_key=self.config.rag_vectorizer_openai_key)
|
|
296
|
-
|
|
297
|
-
self.persona_data_vectorizer = VectorDatabase(self.database_path, v, TikTokenTokenizer(), self.config.rag_chunk_size, self.config.rag_overlap)
|
|
298
|
-
|
|
299
|
-
files = [f for f in self.data_path.iterdir() if f.suffix.lower() in ['.asm', '.bat', '.c', '.cpp', '.cs', '.csproj', '.css',
|
|
300
|
-
'.csv', '.docx', '.h', '.hh', '.hpp', '.html', '.inc', '.ini', '.java', '.js', '.json', '.log',
|
|
301
|
-
'.lua', '.map', '.md', '.pas', '.pdf', '.php', '.pptx', '.ps1', '.py', '.rb', '.rtf', '.s', '.se', '.sh', '.sln',
|
|
302
|
-
'.snippet', '.snippets', '.sql', '.sym', '.ts', '.txt', '.xlsx', '.xml', '.yaml', '.yml', '.msg'] ]
|
|
303
|
-
dl = TextDocumentsLoader()
|
|
304
|
-
|
|
305
|
-
for f in files:
|
|
306
|
-
text = dl.read_file(f)
|
|
307
|
-
self.persona_data_vectorizer.add_document(f.name, text, f)
|
|
308
|
-
# data_vectorization_chunk_size: 512 # chunk size
|
|
309
|
-
# data_vectorization_overlap_size: 128 # overlap between chunks size
|
|
310
|
-
# data_vectorization_nb_chunks: 2 # number of chunks to use
|
|
311
|
-
self.persona_data_vectorizer.build_index()
|
|
312
|
-
|
|
313
|
-
else:
|
|
314
|
-
self.persona_data_vectorizer = None
|
|
315
|
-
self._data = None
|
|
316
|
-
|
|
317
|
-
self.personality_output_folder = self.lollms_paths.personal_outputs_path/self.name
|
|
318
|
-
self.personality_output_folder.mkdir(parents=True, exist_ok=True)
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if self.run_scripts:
|
|
322
|
-
# Search for any processor code
|
|
323
|
-
processor_file_name = "processor.py"
|
|
324
|
-
self.processor_script_path = self.scripts_path / processor_file_name
|
|
325
|
-
if self.processor_script_path.exists():
|
|
326
|
-
module_name = processor_file_name[:-3] # Remove the ".py" extension
|
|
327
|
-
module_spec = importlib.util.spec_from_file_location(module_name, str(self.processor_script_path))
|
|
328
|
-
module = importlib.util.module_from_spec(module_spec)
|
|
329
|
-
module_spec.loader.exec_module(module)
|
|
330
|
-
if hasattr(module, "Processor"):
|
|
331
|
-
self._processor = module.Processor(self, callback=self.callback)
|
|
332
|
-
else:
|
|
333
|
-
self._processor = None
|
|
334
|
-
else:
|
|
335
|
-
self._processor = None
|
|
336
|
-
# Get a list of all files in the assets folder
|
|
337
|
-
contents = [str(file) for file in self.assets_path.iterdir() if file.is_file()]
|
|
338
|
-
|
|
339
|
-
self._assets_list = contents
|
|
340
|
-
return config
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
def notify(self, notification):
|
|
344
|
-
print(notification)
|
|
345
|
-
|
|
346
|
-
def generate(self, discussion:LollmsDiscussion, prompt:str, n_predict=1024, stream = False, callback=None):
|
|
347
|
-
if callback is None:
|
|
348
|
-
callback=self.callback
|
|
349
|
-
if self.processor:
|
|
350
|
-
self.processor.run_workflow(prompt, discussion.format_discussion(self.lollmsClient.ctx_size-n_predict), callback)
|
|
351
|
-
else:
|
|
352
|
-
discussion.add_message(self.user_message_prefix, prompt)
|
|
353
|
-
discussion.add_message(self.ai_message_prefix, "")
|
|
354
|
-
full_discussion = self.preambule + discussion.format_discussion(self.lollmsClient.ctx_size-n_predict-self.preambule_len)
|
|
355
|
-
discussion.messages[-1].content = self.lollmsClient.generate(full_discussion, n_predict, stream=stream, streaming_callback=callback)
|
|
356
|
-
|
|
357
|
-
def fast_gen(self, prompt: str, max_generation_size: int=None, placeholders: dict = {}, sacrifice: list = ["previous_discussion"], debug: bool = False, callback=None, show_progress=False) -> str:
|
|
358
|
-
"""
|
|
359
|
-
Fast way to generate code
|
|
360
|
-
|
|
361
|
-
This method takes in a prompt, maximum generation size, optional placeholders, sacrifice list, and debug flag.
|
|
362
|
-
It reshapes the context before performing text generation by adjusting and cropping the number of tokens.
|
|
363
|
-
|
|
364
|
-
Parameters:
|
|
365
|
-
- prompt (str): The input prompt for text generation.
|
|
366
|
-
- max_generation_size (int): The maximum number of tokens to generate.
|
|
367
|
-
- placeholders (dict, optional): A dictionary of placeholders to be replaced in the prompt. Defaults to an empty dictionary.
|
|
368
|
-
- sacrifice (list, optional): A list of placeholders to sacrifice if the window is bigger than the context size minus the number of tokens to generate. Defaults to ["previous_discussion"].
|
|
369
|
-
- debug (bool, optional): Flag to enable/disable debug mode. Defaults to False.
|
|
370
|
-
|
|
371
|
-
Returns:
|
|
372
|
-
- str: The generated text after removing special tokens ("<s>" and "</s>") and stripping any leading/trailing whitespace.
|
|
373
|
-
"""
|
|
374
|
-
if debug == False:
|
|
375
|
-
debug = self.config.debug
|
|
376
|
-
|
|
377
|
-
if max_generation_size is None:
|
|
378
|
-
prompt_size = self.model.tokenize(prompt)
|
|
379
|
-
max_generation_size = self.model.config.ctx_size - len(prompt_size)
|
|
380
|
-
|
|
381
|
-
pr = PromptReshaper(prompt)
|
|
382
|
-
prompt = pr.build(placeholders,
|
|
383
|
-
self.lollmsClient.tokenize,
|
|
384
|
-
self.lollmsClient.detokenize,
|
|
385
|
-
self.lollmsClient.ctx_size - max_generation_size,
|
|
386
|
-
sacrifice
|
|
387
|
-
)
|
|
388
|
-
ntk = len(self.lollmsClient.tokenize(prompt))
|
|
389
|
-
max_generation_size = min(self.lollmsClient.ctx_size - ntk, max_generation_size)
|
|
390
|
-
# TODO : add show progress
|
|
391
|
-
|
|
392
|
-
gen = self.lollmsClient.generate(prompt, max_generation_size, callback=callback).strip().replace("</s>", "").replace("<s>", "")
|
|
393
|
-
if debug:
|
|
394
|
-
self.print_prompt("prompt", prompt+gen)
|
|
395
|
-
|
|
396
|
-
return gen
|
|
397
|
-
|
|
398
|
-
def print_prompt(self, title, prompt):
|
|
399
|
-
ASCIIColors.red("*-*-*-*-*-*-*-* ", end="")
|
|
400
|
-
ASCIIColors.red(title, end="")
|
|
401
|
-
ASCIIColors.red(" *-*-*-*-*-*-*-*")
|
|
402
|
-
ASCIIColors.yellow(prompt)
|
|
403
|
-
ASCIIColors.red(" *-*-*-*-*-*-*-*")
|