lollms-client 0.15.2__py3-none-any.whl → 0.17.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.

Files changed (39) hide show
  1. examples/generate_and_speak/generate_and_speak.py +251 -0
  2. examples/generate_game_sfx/generate_game_fx.py +240 -0
  3. examples/simple_text_gen_with_image_test.py +8 -8
  4. examples/text_2_image.py +0 -1
  5. examples/text_gen.py +1 -1
  6. lollms_client/__init__.py +1 -1
  7. lollms_client/llm_bindings/llamacpp/__init__.py +61 -11
  8. lollms_client/llm_bindings/lollms/__init__.py +31 -24
  9. lollms_client/llm_bindings/ollama/__init__.py +47 -27
  10. lollms_client/llm_bindings/openai/__init__.py +62 -35
  11. lollms_client/llm_bindings/openllm/__init__.py +4 -1
  12. lollms_client/llm_bindings/pythonllamacpp/__init__.py +3 -0
  13. lollms_client/llm_bindings/tensor_rt/__init__.py +4 -1
  14. lollms_client/llm_bindings/transformers/__init__.py +3 -0
  15. lollms_client/llm_bindings/vllm/__init__.py +4 -1
  16. lollms_client/lollms_core.py +65 -33
  17. lollms_client/lollms_llm_binding.py +76 -22
  18. lollms_client/lollms_stt_binding.py +3 -15
  19. lollms_client/lollms_tti_binding.py +5 -29
  20. lollms_client/lollms_ttm_binding.py +5 -28
  21. lollms_client/lollms_tts_binding.py +4 -28
  22. lollms_client/lollms_ttv_binding.py +4 -28
  23. lollms_client/lollms_utilities.py +5 -3
  24. lollms_client/stt_bindings/lollms/__init__.py +5 -4
  25. lollms_client/stt_bindings/whisper/__init__.py +304 -0
  26. lollms_client/stt_bindings/whispercpp/__init__.py +380 -0
  27. lollms_client/tti_bindings/lollms/__init__.py +4 -6
  28. lollms_client/ttm_bindings/audiocraft/__init__.py +281 -0
  29. lollms_client/ttm_bindings/bark/__init__.py +339 -0
  30. lollms_client/tts_bindings/bark/__init__.py +336 -0
  31. lollms_client/tts_bindings/piper_tts/__init__.py +343 -0
  32. lollms_client/tts_bindings/xtts/__init__.py +317 -0
  33. lollms_client-0.17.0.dist-info/METADATA +183 -0
  34. lollms_client-0.17.0.dist-info/RECORD +65 -0
  35. lollms_client-0.15.2.dist-info/METADATA +0 -192
  36. lollms_client-0.15.2.dist-info/RECORD +0 -56
  37. {lollms_client-0.15.2.dist-info → lollms_client-0.17.0.dist-info}/WHEEL +0 -0
  38. {lollms_client-0.15.2.dist-info → lollms_client-0.17.0.dist-info}/licenses/LICENSE +0 -0
  39. {lollms_client-0.15.2.dist-info → lollms_client-0.17.0.dist-info}/top_level.txt +0 -0
@@ -2,13 +2,14 @@
2
2
  from abc import ABC, abstractmethod
3
3
  import importlib
4
4
  from pathlib import Path
5
- from typing import Optional, Callable, List
5
+ from typing import Optional, Callable, List, Union
6
6
  from lollms_client.lollms_types import ELF_COMPLETION_FORMAT
7
7
  import importlib
8
8
  from pathlib import Path
9
9
  from typing import Optional
10
10
  from ascii_colors import trace_exception
11
-
11
+ from lollms_client.lollms_types import MSG_TYPE
12
+ import re
12
13
  class LollmsLLMBinding(ABC):
13
14
  """Abstract base class for all LOLLMS LLM bindings"""
14
15
 
@@ -25,41 +26,50 @@ class LollmsLLMBinding(ABC):
25
26
  self.model_name = None #Must be set by the instance
26
27
 
27
28
  @abstractmethod
28
- def generate_text(self,
29
+ def generate_text(self,
29
30
  prompt: str,
30
31
  images: Optional[List[str]] = None,
31
32
  system_prompt: str = "",
32
33
  n_predict: Optional[int] = None,
33
- stream: bool = False,
34
- temperature: float = 0.1,
35
- top_k: int = 50,
36
- top_p: float = 0.95,
37
- repeat_penalty: float = 0.8,
38
- repeat_last_n: int = 40,
34
+ stream: Optional[bool] = None,
35
+ temperature: Optional[float] = None,
36
+ top_k: Optional[int] = None,
37
+ top_p: Optional[float] = None,
38
+ repeat_penalty: Optional[float] = None,
39
+ repeat_last_n: Optional[int] = None,
39
40
  seed: Optional[int] = None,
40
- n_threads: int = 8,
41
- streaming_callback: Optional[Callable[[str, str], None]] = None) -> str:
41
+ n_threads: Optional[int] = None,
42
+ ctx_size: int | None = None,
43
+ streaming_callback: Optional[Callable[[str, MSG_TYPE], None]] = None,
44
+ split:Optional[bool]=False, # put to true if the prompt is a discussion
45
+ user_keyword:Optional[str]="!@>user:",
46
+ ai_keyword:Optional[str]="!@>assistant:",
47
+ ) -> Union[str, dict]:
42
48
  """
43
- Generate text based on the provided prompt and parameters.
49
+ Generate text using the active LLM binding, using instance defaults if parameters are not provided.
44
50
 
45
51
  Args:
46
52
  prompt (str): The input prompt for text generation.
47
53
  images (Optional[List[str]]): List of image file paths for multimodal generation.
48
- n_predict (Optional[int]): Maximum number of tokens to generate.
49
- stream (bool): Whether to stream the output. Defaults to False.
50
- temperature (float): Sampling temperature. Defaults to 0.1.
51
- top_k (int): Top-k sampling parameter. Defaults to 50.
52
- top_p (float): Top-p sampling parameter. Defaults to 0.95.
53
- repeat_penalty (float): Penalty for repeated tokens. Defaults to 0.8.
54
- repeat_last_n (int): Number of previous tokens to consider for repeat penalty. Defaults to 40.
55
- seed (Optional[int]): Random seed for generation.
56
- n_threads (int): Number of threads to use. Defaults to 8.
54
+ n_predict (Optional[int]): Maximum number of tokens to generate. Uses instance default if None.
55
+ stream (Optional[bool]): Whether to stream the output. Uses instance default if None.
56
+ temperature (Optional[float]): Sampling temperature. Uses instance default if None.
57
+ top_k (Optional[int]): Top-k sampling parameter. Uses instance default if None.
58
+ top_p (Optional[float]): Top-p sampling parameter. Uses instance default if None.
59
+ repeat_penalty (Optional[float]): Penalty for repeated tokens. Uses instance default if None.
60
+ repeat_last_n (Optional[int]): Number of previous tokens to consider for repeat penalty. Uses instance default if None.
61
+ seed (Optional[int]): Random seed for generation. Uses instance default if None.
62
+ n_threads (Optional[int]): Number of threads to use. Uses instance default if None.
63
+ ctx_size (int | None): Context size override for this generation.
57
64
  streaming_callback (Optional[Callable[[str, str], None]]): Callback function for streaming output.
58
65
  - First parameter (str): The chunk of text received.
59
66
  - Second parameter (str): The message type (e.g., MSG_TYPE.MSG_TYPE_CHUNK).
67
+ split:Optional[bool]: put to true if the prompt is a discussion
68
+ user_keyword:Optional[str]: when splitting we use this to extract user prompt
69
+ ai_keyword:Optional[str]": when splitting we use this to extract ai prompt
60
70
 
61
71
  Returns:
62
- str: Generated text or error dictionary if failed.
72
+ Union[str, dict]: Generated text or error dictionary if failed.
63
73
  """
64
74
  pass
65
75
 
@@ -146,6 +156,50 @@ class LollmsLLMBinding(ABC):
146
156
  pass
147
157
 
148
158
 
159
+ def split_discussion(self, lollms_prompt_string: str, system_keyword="!@>system:", user_keyword="!@>user:", ai_keyword="!@>assistant:") -> list:
160
+
161
+ """
162
+ Abra-cadabra! Splits a combined LoLLMs prompt string into a list of
163
+ OpenAI chat messages.
164
+
165
+ Each segment starting with system_keyword/user_keyword/ai_keyword
166
+ becomes a {"role": ..., "content": ...} dict.
167
+ """
168
+ # Build a regex that looks ahead for any of the three markers
169
+ pattern = r"(?={}|{}|{})".format(
170
+ re.escape(system_keyword),
171
+ re.escape(user_keyword),
172
+ re.escape(ai_keyword)
173
+ )
174
+ # Split the big string into little bits at each keyword
175
+ parts = re.split(pattern, lollms_prompt_string)
176
+ messages = []
177
+
178
+ for part in parts:
179
+ part = part.strip()
180
+ if not part:
181
+ continue # Skip empty rabbitholes
182
+
183
+ if part.startswith(system_keyword):
184
+ role = "system"
185
+ content = part[len(system_keyword):].strip()
186
+ elif part.startswith(user_keyword):
187
+ role = "user"
188
+ content = part[len(user_keyword):].strip()
189
+ elif part.startswith(ai_keyword):
190
+ role = "assistant"
191
+ content = part[len(ai_keyword):].strip()
192
+ else:
193
+ # Unknown segment—maybe a ghost?
194
+ continue
195
+
196
+ messages.append({"role": role, "content": content})
197
+ if messages[-1]["content"]=="":
198
+ del messages[-1]
199
+ return messages
200
+
201
+
202
+
149
203
  class LollmsLLMBindingManager:
150
204
  """Manages binding discovery and instantiation"""
151
205
 
@@ -9,26 +9,14 @@ class LollmsSTTBinding(ABC):
9
9
  """Abstract base class for all LOLLMS Speech-to-Text bindings."""
10
10
 
11
11
  def __init__(self,
12
- host_address: Optional[str] = None,
13
- model_name: Optional[str] = None, # Can represent a default model
14
- service_key: Optional[str] = None,
15
- verify_ssl_certificate: bool = True):
12
+ binding_name:str="unknown"):
16
13
  """
17
14
  Initialize the LollmsSTTBinding base class.
18
15
 
19
16
  Args:
20
- host_address (Optional[str]): The host address for the STT service.
21
- model_name (Optional[str]): A default identifier for the STT model.
22
- service_key (Optional[str]): Authentication key for the service.
23
- verify_ssl_certificate (bool): Whether to verify SSL certificates.
17
+ binding_name (Optional[str]): The binding name
24
18
  """
25
- if host_address is not None:
26
- self.host_address = host_address.rstrip('/')
27
- else:
28
- self.host_address = None
29
- self.model_name = model_name
30
- self.service_key = service_key
31
- self.verify_ssl_certificate = verify_ssl_certificate
19
+ self.binding_name = binding_name
32
20
 
33
21
  @abstractmethod
34
22
  def transcribe_audio(self, audio_path: Union[str, Path], model: Optional[str] = None, **kwargs) -> str:
@@ -9,26 +9,14 @@ class LollmsTTIBinding(ABC):
9
9
  """Abstract base class for all LOLLMS Text-to-Image bindings."""
10
10
 
11
11
  def __init__(self,
12
- host_address: Optional[str] = None,
13
- model_name: Optional[str] = None, # Can represent a default service/model
14
- service_key: Optional[str] = None,
15
- verify_ssl_certificate: bool = True):
12
+ binding_name:str="unknown"):
16
13
  """
17
14
  Initialize the LollmsTTIBinding base class.
18
15
 
19
16
  Args:
20
- host_address (Optional[str]): The host address for the TTI service.
21
- model_name (Optional[str]): A default identifier (e.g., service or model name).
22
- service_key (Optional[str]): Authentication key for the service.
23
- verify_ssl_certificate (bool): Whether to verify SSL certificates.
24
- """
25
- if host_address is not None:
26
- self.host_address = host_address.rstrip('/')
27
- else:
28
- self.host_address = None
29
- self.model_name = model_name
30
- self.service_key = service_key
31
- self.verify_ssl_certificate = verify_ssl_certificate
17
+ binding_name (Optional[str]): The binding name
18
+ """
19
+ self.binding_name = binding_name
32
20
 
33
21
  @abstractmethod
34
22
  def generate_image(self,
@@ -128,20 +116,12 @@ class LollmsTTIBindingManager:
128
116
 
129
117
  def create_binding(self,
130
118
  binding_name: str,
131
- host_address: Optional[str] = None,
132
- model_name: Optional[str] = None,
133
- service_key: Optional[str] = None,
134
- verify_ssl_certificate: bool = True,
135
119
  **kwargs) -> Optional[LollmsTTIBinding]:
136
120
  """
137
121
  Create an instance of a specific TTI binding.
138
122
 
139
123
  Args:
140
124
  binding_name (str): Name of the TTI binding to create.
141
- host_address (Optional[str]): Host address for the service.
142
- model_name (Optional[str]): Default model/service identifier.
143
- service_key (Optional[str]): Authentication key for the service.
144
- verify_ssl_certificate (bool): Whether to verify SSL certificates.
145
125
  **kwargs: Additional parameters specific to the binding's __init__.
146
126
 
147
127
  Returns:
@@ -153,11 +133,7 @@ class LollmsTTIBindingManager:
153
133
  binding_class = self.available_bindings.get(binding_name)
154
134
  if binding_class:
155
135
  try:
156
- return binding_class(host_address=host_address,
157
- model_name=model_name,
158
- service_key=service_key,
159
- verify_ssl_certificate=verify_ssl_certificate,
160
- **kwargs)
136
+ return binding_class(**kwargs)
161
137
  except Exception as e:
162
138
  trace_exception(e)
163
139
  print(f"Failed to instantiate TTI binding {binding_name}: {str(e)}")
@@ -9,26 +9,15 @@ class LollmsTTMBinding(ABC):
9
9
  """Abstract base class for all LOLLMS Text-to-Music bindings."""
10
10
 
11
11
  def __init__(self,
12
- host_address: Optional[str] = None,
13
- model_name: Optional[str] = None, # Can represent a default model/service
14
- service_key: Optional[str] = None,
15
- verify_ssl_certificate: bool = True):
12
+ binding_name:str="unknown"):
16
13
  """
17
14
  Initialize the LollmsTTMBinding base class.
18
15
 
19
16
  Args:
20
- host_address (Optional[str]): The host address for the TTM service.
21
- model_name (Optional[str]): A default identifier (e.g., service or model name).
22
- service_key (Optional[str]): Authentication key for the service.
23
- verify_ssl_certificate (bool): Whether to verify SSL certificates.
17
+ binding_name (Optional[str]): The binding name
24
18
  """
25
- if host_address is not None:
26
- self.host_address = host_address.rstrip('/')
27
- else:
28
- self.host_address = None
29
- self.model_name = model_name
30
- self.service_key = service_key
31
- self.verify_ssl_certificate = verify_ssl_certificate
19
+ self.binding_name = binding_name
20
+
32
21
 
33
22
  @abstractmethod
34
23
  def generate_music(self, prompt: str, **kwargs) -> bytes:
@@ -88,20 +77,12 @@ class LollmsTTMBindingManager:
88
77
 
89
78
  def create_binding(self,
90
79
  binding_name: str,
91
- host_address: Optional[str] = None,
92
- model_name: Optional[str] = None,
93
- service_key: Optional[str] = None,
94
- verify_ssl_certificate: bool = True,
95
80
  **kwargs) -> Optional[LollmsTTMBinding]:
96
81
  """
97
82
  Create an instance of a specific TTM binding.
98
83
 
99
84
  Args:
100
85
  binding_name (str): Name of the TTM binding to create.
101
- host_address (Optional[str]): Host address for the service.
102
- model_name (Optional[str]): Default model/service identifier.
103
- service_key (Optional[str]): Authentication key for the service.
104
- verify_ssl_certificate (bool): Whether to verify SSL certificates.
105
86
  **kwargs: Additional parameters specific to the binding's __init__.
106
87
 
107
88
  Returns:
@@ -113,11 +94,7 @@ class LollmsTTMBindingManager:
113
94
  binding_class = self.available_bindings.get(binding_name)
114
95
  if binding_class:
115
96
  try:
116
- return binding_class(host_address=host_address,
117
- model_name=model_name,
118
- service_key=service_key,
119
- verify_ssl_certificate=verify_ssl_certificate,
120
- **kwargs)
97
+ return binding_class(**kwargs)
121
98
  except Exception as e:
122
99
  trace_exception(e)
123
100
  print(f"Failed to instantiate TTM binding {binding_name}: {str(e)}")
@@ -9,26 +9,14 @@ class LollmsTTSBinding(ABC):
9
9
  """Abstract base class for all LOLLMS Text-to-Speech bindings."""
10
10
 
11
11
  def __init__(self,
12
- host_address: Optional[str] = None,
13
- model_name: Optional[str] = None, # Can represent a default voice or model
14
- service_key: Optional[str] = None,
15
- verify_ssl_certificate: bool = True):
12
+ binding_name:str="unknown"):
16
13
  """
17
14
  Initialize the LollmsTTSBinding base class.
18
15
 
19
16
  Args:
20
- host_address (Optional[str]): The host address for the TTS service.
21
- model_name (Optional[str]): A default identifier (e.g., voice or model name).
22
- service_key (Optional[str]): Authentication key for the service.
23
- verify_ssl_certificate (bool): Whether to verify SSL certificates.
17
+ binding_name (Optional[str]): The binding name
24
18
  """
25
- if host_address is not None:
26
- self.host_address = host_address.rstrip('/')
27
- else:
28
- self.host_address = None
29
- self.model_name = model_name
30
- self.service_key = service_key
31
- self.verify_ssl_certificate = verify_ssl_certificate
19
+ self.binding_name = binding_name
32
20
 
33
21
  @abstractmethod
34
22
  def generate_audio(self, text: str, voice: Optional[str] = None, **kwargs) -> bytes:
@@ -91,20 +79,12 @@ class LollmsTTSBindingManager:
91
79
 
92
80
  def create_binding(self,
93
81
  binding_name: str,
94
- host_address: Optional[str] = None,
95
- model_name: Optional[str] = None,
96
- service_key: Optional[str] = None,
97
- verify_ssl_certificate: bool = True,
98
82
  **kwargs) -> Optional[LollmsTTSBinding]:
99
83
  """
100
84
  Create an instance of a specific TTS binding.
101
85
 
102
86
  Args:
103
87
  binding_name (str): Name of the TTS binding to create.
104
- host_address (Optional[str]): Host address for the service.
105
- model_name (Optional[str]): Default model/voice identifier.
106
- service_key (Optional[str]): Authentication key for the service.
107
- verify_ssl_certificate (bool): Whether to verify SSL certificates.
108
88
  **kwargs: Additional parameters specific to the binding's __init__.
109
89
 
110
90
  Returns:
@@ -116,11 +96,7 @@ class LollmsTTSBindingManager:
116
96
  binding_class = self.available_bindings.get(binding_name)
117
97
  if binding_class:
118
98
  try:
119
- return binding_class(host_address=host_address,
120
- model_name=model_name,
121
- service_key=service_key,
122
- verify_ssl_certificate=verify_ssl_certificate,
123
- **kwargs)
99
+ return binding_class(**kwargs)
124
100
  except Exception as e:
125
101
  trace_exception(e)
126
102
  print(f"Failed to instantiate TTS binding {binding_name}: {str(e)}")
@@ -9,26 +9,14 @@ class LollmsTTVBinding(ABC):
9
9
  """Abstract base class for all LOLLMS Text-to-Video bindings."""
10
10
 
11
11
  def __init__(self,
12
- host_address: Optional[str] = None,
13
- model_name: Optional[str] = None, # Can represent a default model/service
14
- service_key: Optional[str] = None,
15
- verify_ssl_certificate: bool = True):
12
+ binding_name:str="unknown"):
16
13
  """
17
14
  Initialize the LollmsTTVBinding base class.
18
15
 
19
16
  Args:
20
- host_address (Optional[str]): The host address for the TTV service.
21
- model_name (Optional[str]): A default identifier (e.g., service or model name).
22
- service_key (Optional[str]): Authentication key for the service.
23
- verify_ssl_certificate (bool): Whether to verify SSL certificates.
17
+ binding_name (Optional[str]): The binding name
24
18
  """
25
- if host_address is not None:
26
- self.host_address = host_address.rstrip('/')
27
- else:
28
- self.host_address = None
29
- self.model_name = model_name
30
- self.service_key = service_key
31
- self.verify_ssl_certificate = verify_ssl_certificate
19
+ self.binding_name = binding_name
32
20
 
33
21
  @abstractmethod
34
22
  def generate_video(self, prompt: str, **kwargs) -> bytes:
@@ -88,20 +76,12 @@ class LollmsTTVBindingManager:
88
76
 
89
77
  def create_binding(self,
90
78
  binding_name: str,
91
- host_address: Optional[str] = None,
92
- model_name: Optional[str] = None,
93
- service_key: Optional[str] = None,
94
- verify_ssl_certificate: bool = True,
95
79
  **kwargs) -> Optional[LollmsTTVBinding]:
96
80
  """
97
81
  Create an instance of a specific TTV binding.
98
82
 
99
83
  Args:
100
84
  binding_name (str): Name of the TTV binding to create.
101
- host_address (Optional[str]): Host address for the service.
102
- model_name (Optional[str]): Default model/service identifier.
103
- service_key (Optional[str]): Authentication key for the service.
104
- verify_ssl_certificate (bool): Whether to verify SSL certificates.
105
85
  **kwargs: Additional parameters specific to the binding's __init__.
106
86
 
107
87
  Returns:
@@ -113,11 +93,7 @@ class LollmsTTVBindingManager:
113
93
  binding_class = self.available_bindings.get(binding_name)
114
94
  if binding_class:
115
95
  try:
116
- return binding_class(host_address=host_address,
117
- model_name=model_name,
118
- service_key=service_key,
119
- verify_ssl_certificate=verify_ssl_certificate,
120
- **kwargs)
96
+ return binding_class(**kwargs)
121
97
  except Exception as e:
122
98
  trace_exception(e)
123
99
  print(f"Failed to instantiate TTV binding {binding_name}: {str(e)}")
@@ -1,10 +1,12 @@
1
1
  import urllib
2
2
  import numpy
3
3
  from pathlib import Path
4
- from pipmaster import PackageManager
4
+ import pipmaster as pm
5
5
  from PIL import Image
6
6
  import io
7
7
  import base64
8
+ import re
9
+ import numpy as np
8
10
  class PromptReshaper:
9
11
  def __init__(self, template:str):
10
12
  self.template = template
@@ -122,8 +124,8 @@ def remove_text_from_string(string: str, text_to_find:str):
122
124
 
123
125
 
124
126
  def process_ai_output(output, images, output_folder):
125
- if not PackageManager.is_installed("cv2"):
126
- PackageManager.install("opencv-python")
127
+ if not pm.is_installed("opencv-python"):
128
+ pm.install("opencv-python")
127
129
  import cv2
128
130
  images = [cv2.imread(str(img)) for img in images]
129
131
  # Find all bounding box entries in the output
@@ -27,10 +27,11 @@ class LollmsSTTBinding_Impl(LollmsSTTBinding):
27
27
  service_key (Optional[str]): Authentication key (currently unused by default LOLLMS STT).
28
28
  verify_ssl_certificate (bool): Whether to verify SSL certificates.
29
29
  """
30
- super().__init__(host_address=host_address,
31
- model_name=model_name,
32
- service_key=service_key,
33
- verify_ssl_certificate=verify_ssl_certificate)
30
+ super().__init__("lollms")
31
+ self.host_address=host_address
32
+ self.model_name=model_name
33
+ self.service_key=service_key
34
+ self.verify_ssl_certificate=verify_ssl_certificate
34
35
 
35
36
  def transcribe_audio(self, audio_path: Union[str, Path], model: Optional[str] = None, **kwargs) -> str:
36
37
  """