lollms-client 1.0.0__py3-none-any.whl → 1.1.1__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.
- lollms_client/__init__.py +1 -1
- lollms_client/llm_bindings/ollama/__init__.py +1 -1
- lollms_client/lollms_core.py +19 -15
- lollms_client/lollms_llm_binding.py +3 -2
- lollms_client/lollms_tti_binding.py +107 -2
- lollms_client/tti_bindings/dalle/__init__.py +24 -4
- lollms_client/tti_bindings/diffusers/__init__.py +494 -577
- lollms_client/tti_bindings/gemini/__init__.py +241 -136
- {lollms_client-1.0.0.dist-info → lollms_client-1.1.1.dist-info}/METADATA +1 -1
- {lollms_client-1.0.0.dist-info → lollms_client-1.1.1.dist-info}/RECORD +13 -13
- {lollms_client-1.0.0.dist-info → lollms_client-1.1.1.dist-info}/WHEEL +0 -0
- {lollms_client-1.0.0.dist-info → lollms_client-1.1.1.dist-info}/licenses/LICENSE +0 -0
- {lollms_client-1.0.0.dist-info → lollms_client-1.1.1.dist-info}/top_level.txt +0 -0
lollms_client/__init__.py
CHANGED
|
@@ -8,7 +8,7 @@ from lollms_client.lollms_utilities import PromptReshaper # Keep general utiliti
|
|
|
8
8
|
from lollms_client.lollms_mcp_binding import LollmsMCPBinding, LollmsMCPBindingManager
|
|
9
9
|
from lollms_client.lollms_llm_binding import LollmsLLMBindingManager
|
|
10
10
|
|
|
11
|
-
__version__ = "1.
|
|
11
|
+
__version__ = "1.1.1" # Updated version
|
|
12
12
|
|
|
13
13
|
# Optionally, you could define __all__ if you want to be explicit about exports
|
|
14
14
|
__all__ = [
|
|
@@ -434,7 +434,7 @@ class OllamaBinding(LollmsLLMBinding):
|
|
|
434
434
|
list: List of individual characters.
|
|
435
435
|
"""
|
|
436
436
|
## Since ollama has no endpoints to tokenize the text, we use tiktoken to have a rough estimate
|
|
437
|
-
return tiktoken.model.encoding_for_model("gpt-3.5-turbo").encode(text)
|
|
437
|
+
return tiktoken.model.encoding_for_model("gpt-3.5-turbo").encode(text, disallowed_special=())
|
|
438
438
|
|
|
439
439
|
def detokenize(self, tokens: list) -> str:
|
|
440
440
|
"""
|
lollms_client/lollms_core.py
CHANGED
|
@@ -32,7 +32,7 @@ class LollmsClient():
|
|
|
32
32
|
def __init__(self,
|
|
33
33
|
|
|
34
34
|
# Optional Modality Binding Names
|
|
35
|
-
llm_binding_name: str =
|
|
35
|
+
llm_binding_name: Optional[str] = None,
|
|
36
36
|
tts_binding_name: Optional[str] = None,
|
|
37
37
|
tti_binding_name: Optional[str] = None,
|
|
38
38
|
stt_binding_name: Optional[str] = None,
|
|
@@ -106,21 +106,8 @@ class LollmsClient():
|
|
|
106
106
|
ValueError: If the primary LLM binding cannot be created.
|
|
107
107
|
"""
|
|
108
108
|
# --- LLM Binding Setup ---
|
|
109
|
-
self.llm_binding_manager = LollmsLLMBindingManager(llm_bindings_dir)
|
|
110
|
-
self.llm = self.llm_binding_manager.create_binding(
|
|
111
|
-
binding_name=llm_binding_name,
|
|
112
|
-
**{
|
|
113
|
-
k: v
|
|
114
|
-
for k, v in (llm_binding_config or {}).items()
|
|
115
|
-
if k != "binding_name"
|
|
116
|
-
}
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
if self.llm is None:
|
|
120
|
-
available = self.llm_binding_manager.get_available_bindings()
|
|
121
|
-
raise ValueError(f"Failed to create LLM binding: {llm_binding_name}. Available: {available}")
|
|
122
|
-
|
|
123
109
|
# --- Modality Binding Setup ---
|
|
110
|
+
self.llm_binding_manager = LollmsLLMBindingManager(llm_bindings_dir)
|
|
124
111
|
self.tts_binding_manager = LollmsTTSBindingManager(tts_bindings_dir)
|
|
125
112
|
self.tti_binding_manager = LollmsTTIBindingManager(tti_bindings_dir)
|
|
126
113
|
self.stt_binding_manager = LollmsSTTBindingManager(stt_bindings_dir)
|
|
@@ -128,6 +115,8 @@ class LollmsClient():
|
|
|
128
115
|
self.ttm_binding_manager = LollmsTTMBindingManager(ttm_bindings_dir)
|
|
129
116
|
self.mcp_binding_manager = LollmsMCPBindingManager(mcp_bindings_dir)
|
|
130
117
|
|
|
118
|
+
|
|
119
|
+
self.llm: Optional[LollmsLLMBinding] = None
|
|
131
120
|
self.tts: Optional[LollmsTTSBinding] = None
|
|
132
121
|
self.tti: Optional[LollmsTTIBinding] = None
|
|
133
122
|
self.stt: Optional[LollmsSTTBinding] = None
|
|
@@ -135,6 +124,21 @@ class LollmsClient():
|
|
|
135
124
|
self.ttm: Optional[LollmsTTMBinding] = None
|
|
136
125
|
self.mcp: Optional[LollmsMCPBinding] = None
|
|
137
126
|
|
|
127
|
+
|
|
128
|
+
if llm_binding_name:
|
|
129
|
+
self.llm = self.llm_binding_manager.create_binding(
|
|
130
|
+
binding_name=llm_binding_name,
|
|
131
|
+
**{
|
|
132
|
+
k: v
|
|
133
|
+
for k, v in (llm_binding_config or {}).items()
|
|
134
|
+
if k != "binding_name"
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
if self.llm is None:
|
|
139
|
+
available = self.llm_binding_manager.get_available_bindings()
|
|
140
|
+
ASCIIColors.warning(f"Failed to create LLM binding: {llm_binding_name}. Available: {available}")
|
|
141
|
+
|
|
138
142
|
if tts_binding_name:
|
|
139
143
|
self.tts = self.tts_binding_manager.create_binding(
|
|
140
144
|
binding_name=tts_binding_name,
|
|
@@ -373,14 +373,15 @@ class LollmsLLMBinding(ABC):
|
|
|
373
373
|
if messages[-1]["content"]=="":
|
|
374
374
|
del messages[-1]
|
|
375
375
|
return messages
|
|
376
|
-
|
|
376
|
+
def ps(self):
|
|
377
|
+
return []
|
|
377
378
|
|
|
378
379
|
|
|
379
380
|
|
|
380
381
|
class LollmsLLMBindingManager:
|
|
381
382
|
"""Manages binding discovery and instantiation"""
|
|
382
383
|
|
|
383
|
-
def __init__(self, llm_bindings_dir: str = "llm_bindings"):
|
|
384
|
+
def __init__(self, llm_bindings_dir: Union[str, Path] = Path(__file__).parent.parent / "llm_bindings"):
|
|
384
385
|
"""
|
|
385
386
|
Initialize the LollmsLLMBindingManager.
|
|
386
387
|
|
|
@@ -4,7 +4,7 @@ import importlib
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from typing import Optional, List, Dict, Any, Union
|
|
6
6
|
from ascii_colors import trace_exception
|
|
7
|
-
|
|
7
|
+
import yaml
|
|
8
8
|
class LollmsTTIBinding(ABC):
|
|
9
9
|
"""Abstract base class for all LOLLMS Text-to-Image bindings."""
|
|
10
10
|
|
|
@@ -58,6 +58,7 @@ class LollmsTTIBinding(ABC):
|
|
|
58
58
|
"""
|
|
59
59
|
pass
|
|
60
60
|
|
|
61
|
+
|
|
61
62
|
@abstractmethod
|
|
62
63
|
def get_settings(self, **kwargs) -> Optional[Dict[str, Any]]:
|
|
63
64
|
"""
|
|
@@ -73,6 +74,11 @@ class LollmsTTIBinding(ABC):
|
|
|
73
74
|
"""
|
|
74
75
|
pass
|
|
75
76
|
|
|
77
|
+
@abstractmethod
|
|
78
|
+
def listModels(self) -> list:
|
|
79
|
+
"""Lists models"""
|
|
80
|
+
pass
|
|
81
|
+
|
|
76
82
|
@abstractmethod
|
|
77
83
|
def set_settings(self, settings: Dict[str, Any], **kwargs) -> bool:
|
|
78
84
|
"""
|
|
@@ -139,7 +145,86 @@ class LollmsTTIBindingManager:
|
|
|
139
145
|
print(f"Failed to instantiate TTI binding {binding_name}: {str(e)}")
|
|
140
146
|
return None
|
|
141
147
|
return None
|
|
148
|
+
def _get_fallback_description(binding_name: str) -> Dict:
|
|
149
|
+
"""
|
|
150
|
+
Generates a default description dictionary for a binding without a description.yaml file.
|
|
151
|
+
"""
|
|
152
|
+
return {
|
|
153
|
+
"binding_name": binding_name,
|
|
154
|
+
"title": binding_name.replace("_", " ").title(),
|
|
155
|
+
"author": "Unknown",
|
|
156
|
+
"creation_date": "N/A",
|
|
157
|
+
"last_update_date": "N/A",
|
|
158
|
+
"description": f"A binding for {binding_name}. No description.yaml file was found, so common parameters are shown as a fallback.",
|
|
159
|
+
"input_parameters": [
|
|
160
|
+
{
|
|
161
|
+
"name": "model_name",
|
|
162
|
+
"type": "str",
|
|
163
|
+
"description": "The model name, ID, or filename to be used.",
|
|
164
|
+
"mandatory": False,
|
|
165
|
+
"default": ""
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"name": "host_address",
|
|
169
|
+
"type": "str",
|
|
170
|
+
"description": "The host address of the service (for API-based bindings).",
|
|
171
|
+
"mandatory": False,
|
|
172
|
+
"default": ""
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"name": "models_path",
|
|
176
|
+
"type": "str",
|
|
177
|
+
"description": "The path to the models directory (for local bindings).",
|
|
178
|
+
"mandatory": False,
|
|
179
|
+
"default": ""
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"name": "service_key",
|
|
183
|
+
"type": "str",
|
|
184
|
+
"description": "The API key or service key for authentication (if applicable).",
|
|
185
|
+
"mandatory": False,
|
|
186
|
+
"default": ""
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
142
190
|
|
|
191
|
+
@staticmethod
|
|
192
|
+
def get_bindings_list(llm_bindings_dir: Union[str, Path]) -> List[Dict]:
|
|
193
|
+
"""
|
|
194
|
+
Lists all available LLM bindings by scanning a directory, loading their
|
|
195
|
+
description.yaml file if present, or providing a default description.
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
llm_bindings_dir (Union[str, Path]): The path to the directory containing LLM binding folders.
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
List[Dict]: A list of dictionaries, each describing a binding.
|
|
202
|
+
"""
|
|
203
|
+
bindings_dir = Path(llm_bindings_dir)
|
|
204
|
+
if not bindings_dir.is_dir():
|
|
205
|
+
return []
|
|
206
|
+
|
|
207
|
+
bindings_list = []
|
|
208
|
+
for binding_folder in bindings_dir.iterdir():
|
|
209
|
+
if binding_folder.is_dir() and (binding_folder / "__init__.py").exists():
|
|
210
|
+
binding_name = binding_folder.name
|
|
211
|
+
description_file = binding_folder / "description.yaml"
|
|
212
|
+
|
|
213
|
+
binding_info = {}
|
|
214
|
+
if description_file.exists():
|
|
215
|
+
try:
|
|
216
|
+
with open(description_file, 'r', encoding='utf-8') as f:
|
|
217
|
+
binding_info = yaml.safe_load(f)
|
|
218
|
+
binding_info['binding_name'] = binding_name
|
|
219
|
+
except Exception as e:
|
|
220
|
+
print(f"Error loading description.yaml for {binding_name}: {e}")
|
|
221
|
+
binding_info = LollmsTTIBindingManager._get_fallback_description(binding_name)
|
|
222
|
+
else:
|
|
223
|
+
binding_info = LollmsTTIBindingManager._get_fallback_description(binding_name)
|
|
224
|
+
|
|
225
|
+
bindings_list.append(binding_info)
|
|
226
|
+
|
|
227
|
+
return sorted(bindings_list, key=lambda b: b.get('title', b['binding_name']))
|
|
143
228
|
def get_available_bindings(self) -> list[str]:
|
|
144
229
|
"""
|
|
145
230
|
Return list of available TTI binding names based on subdirectories.
|
|
@@ -148,4 +233,24 @@ class LollmsTTIBindingManager:
|
|
|
148
233
|
list[str]: List of binding names.
|
|
149
234
|
"""
|
|
150
235
|
return [binding_dir.name for binding_dir in self.tti_bindings_dir.iterdir()
|
|
151
|
-
if binding_dir.is_dir() and (binding_dir / "__init__.py").exists()]
|
|
236
|
+
if binding_dir.is_dir() and (binding_dir / "__init__.py").exists()]
|
|
237
|
+
|
|
238
|
+
def get_available_bindings(tti_bindings_dir: Union[str, Path] = None) -> List[Dict]:
|
|
239
|
+
"""
|
|
240
|
+
Lists all available LLM bindings with their detailed descriptions.
|
|
241
|
+
|
|
242
|
+
This function serves as a primary entry point for discovering what bindings
|
|
243
|
+
are available and how to configure them.
|
|
244
|
+
|
|
245
|
+
Args:
|
|
246
|
+
llm_bindings_dir (Union[str, Path], optional):
|
|
247
|
+
The path to the LLM bindings directory. If None, it defaults to the
|
|
248
|
+
'llm_bindings' subdirectory relative to this file.
|
|
249
|
+
Defaults to None.
|
|
250
|
+
|
|
251
|
+
Returns:
|
|
252
|
+
List[Dict]: A list of dictionaries, each describing a binding.
|
|
253
|
+
"""
|
|
254
|
+
if tti_bindings_dir is None:
|
|
255
|
+
tti_bindings_dir = Path(__file__).parent / "tti_bindings"
|
|
256
|
+
return LollmsTTIBindingManager.get_bindings_list(tti_bindings_dir)
|
|
@@ -60,7 +60,7 @@ class DalleTTIBinding_Impl(LollmsTTIBinding):
|
|
|
60
60
|
super().__init__(binding_name="dalle")
|
|
61
61
|
|
|
62
62
|
# Extract parameters from kwargs, providing defaults
|
|
63
|
-
self.api_key = kwargs.get("
|
|
63
|
+
self.api_key = kwargs.get("service_key")
|
|
64
64
|
self.model_name = kwargs.get("model_name")
|
|
65
65
|
self.default_size = kwargs.get("default_size")
|
|
66
66
|
self.default_quality = kwargs.get("default_quality")
|
|
@@ -81,9 +81,11 @@ class DalleTTIBinding_Impl(LollmsTTIBinding):
|
|
|
81
81
|
|
|
82
82
|
# Model name validation
|
|
83
83
|
if not self.model_name:
|
|
84
|
-
|
|
84
|
+
ASCIIColors.warning("Model name is required.")
|
|
85
85
|
if self.model_name not in DALLE_MODELS:
|
|
86
|
-
|
|
86
|
+
ASCIIColors.warning(f"Unsupported DALL-E model: {self.model_name}. Supported models: {list(DALLE_MODELS.keys())}")
|
|
87
|
+
self.model_name = list(DALLE_MODELS.keys())[1]
|
|
88
|
+
ASCIIColors.warning(f"Defaulting to {self.model_name}")
|
|
87
89
|
|
|
88
90
|
model_props = DALLE_MODELS[self.model_name]
|
|
89
91
|
|
|
@@ -431,4 +433,22 @@ class DalleTTIBinding_Impl(LollmsTTIBinding):
|
|
|
431
433
|
except Exception as e:
|
|
432
434
|
trace_exception(e)
|
|
433
435
|
ASCIIColors.error(f"Failed to apply settings due to an unexpected error: {e}")
|
|
434
|
-
return False
|
|
436
|
+
return False
|
|
437
|
+
|
|
438
|
+
def listModels(self) -> list:
|
|
439
|
+
"""Lists models"""
|
|
440
|
+
formatted_models=[
|
|
441
|
+
{
|
|
442
|
+
'model_name': "dall-e-2",
|
|
443
|
+
'display_name': "Dall-e 2",
|
|
444
|
+
'description': "Dalle 2 model",
|
|
445
|
+
'owned_by': 'openai'
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
'model_name': "dall-e-3",
|
|
449
|
+
'display_name': "Dall-e 3",
|
|
450
|
+
'description': "Dalle 3 model",
|
|
451
|
+
'owned_by': 'openai'
|
|
452
|
+
}
|
|
453
|
+
]
|
|
454
|
+
return formatted_models
|