lollms-client 1.5.6__py3-none-any.whl → 1.7.10__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.
- lollms_client/__init__.py +1 -1
- lollms_client/llm_bindings/azure_openai/__init__.py +2 -2
- lollms_client/llm_bindings/claude/__init__.py +125 -34
- lollms_client/llm_bindings/gemini/__init__.py +261 -159
- lollms_client/llm_bindings/grok/__init__.py +52 -14
- lollms_client/llm_bindings/groq/__init__.py +2 -2
- lollms_client/llm_bindings/hugging_face_inference_api/__init__.py +2 -2
- lollms_client/llm_bindings/litellm/__init__.py +1 -1
- lollms_client/llm_bindings/llamacpp/__init__.py +18 -11
- lollms_client/llm_bindings/lollms/__init__.py +76 -21
- lollms_client/llm_bindings/lollms_webui/__init__.py +1 -1
- lollms_client/llm_bindings/mistral/__init__.py +2 -2
- lollms_client/llm_bindings/novita_ai/__init__.py +142 -6
- lollms_client/llm_bindings/ollama/__init__.py +307 -89
- lollms_client/llm_bindings/open_router/__init__.py +2 -2
- lollms_client/llm_bindings/openai/__init__.py +81 -20
- lollms_client/llm_bindings/openllm/__init__.py +362 -506
- lollms_client/llm_bindings/openwebui/__init__.py +333 -171
- lollms_client/llm_bindings/perplexity/__init__.py +2 -2
- lollms_client/llm_bindings/pythonllamacpp/__init__.py +3 -3
- lollms_client/llm_bindings/tensor_rt/__init__.py +1 -1
- lollms_client/llm_bindings/transformers/__init__.py +428 -632
- lollms_client/llm_bindings/vllm/__init__.py +1 -1
- lollms_client/lollms_agentic.py +4 -2
- lollms_client/lollms_base_binding.py +61 -0
- lollms_client/lollms_core.py +512 -1890
- lollms_client/lollms_discussion.py +25 -11
- lollms_client/lollms_llm_binding.py +112 -261
- lollms_client/lollms_mcp_binding.py +34 -75
- lollms_client/lollms_stt_binding.py +85 -52
- lollms_client/lollms_tti_binding.py +23 -37
- lollms_client/lollms_ttm_binding.py +24 -42
- lollms_client/lollms_tts_binding.py +28 -17
- lollms_client/lollms_ttv_binding.py +24 -42
- lollms_client/lollms_types.py +4 -2
- lollms_client/stt_bindings/whisper/__init__.py +108 -23
- lollms_client/stt_bindings/whispercpp/__init__.py +7 -1
- lollms_client/tti_bindings/diffusers/__init__.py +418 -810
- lollms_client/tti_bindings/diffusers/server/main.py +1051 -0
- lollms_client/tti_bindings/gemini/__init__.py +182 -239
- lollms_client/tti_bindings/leonardo_ai/__init__.py +6 -3
- lollms_client/tti_bindings/lollms/__init__.py +4 -1
- lollms_client/tti_bindings/novita_ai/__init__.py +5 -2
- lollms_client/tti_bindings/openai/__init__.py +10 -11
- lollms_client/tti_bindings/stability_ai/__init__.py +5 -3
- lollms_client/ttm_bindings/audiocraft/__init__.py +7 -12
- lollms_client/ttm_bindings/beatoven_ai/__init__.py +7 -3
- lollms_client/ttm_bindings/lollms/__init__.py +4 -17
- lollms_client/ttm_bindings/replicate/__init__.py +7 -4
- lollms_client/ttm_bindings/stability_ai/__init__.py +7 -4
- lollms_client/ttm_bindings/topmediai/__init__.py +6 -3
- lollms_client/tts_bindings/bark/__init__.py +7 -10
- lollms_client/tts_bindings/lollms/__init__.py +6 -1
- lollms_client/tts_bindings/piper_tts/__init__.py +8 -11
- lollms_client/tts_bindings/xtts/__init__.py +157 -74
- lollms_client/tts_bindings/xtts/server/main.py +241 -280
- {lollms_client-1.5.6.dist-info → lollms_client-1.7.10.dist-info}/METADATA +113 -5
- lollms_client-1.7.10.dist-info/RECORD +89 -0
- lollms_client-1.5.6.dist-info/RECORD +0 -87
- {lollms_client-1.5.6.dist-info → lollms_client-1.7.10.dist-info}/WHEEL +0 -0
- {lollms_client-1.5.6.dist-info → lollms_client-1.7.10.dist-info}/licenses/LICENSE +0 -0
- {lollms_client-1.5.6.dist-info → lollms_client-1.7.10.dist-info}/top_level.txt +0 -0
|
@@ -1,51 +1,32 @@
|
|
|
1
1
|
# lollms_client/lollms_mcp_binding.py
|
|
2
|
-
from abc import
|
|
2
|
+
from abc import abstractmethod
|
|
3
3
|
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, ASCIIColors
|
|
7
7
|
import yaml
|
|
8
|
-
|
|
8
|
+
from lollms_client.lollms_base_binding import LollmsBaseBinding
|
|
9
|
+
|
|
10
|
+
class LollmsMCPBinding(LollmsBaseBinding):
|
|
9
11
|
"""
|
|
10
12
|
Abstract Base Class for LOLLMS Model Context Protocol (MCP) Bindings.
|
|
11
|
-
|
|
12
|
-
MCP bindings are responsible for interacting with MCP-compliant tool servers
|
|
13
|
-
or emulating MCP tool interactions locally. They handle tool discovery
|
|
14
|
-
and execution based on requests, typically orchestrated by an LLM.
|
|
15
13
|
"""
|
|
16
14
|
|
|
17
15
|
def __init__(self,
|
|
18
|
-
binding_name: str
|
|
16
|
+
binding_name: str,
|
|
17
|
+
**kwargs
|
|
19
18
|
):
|
|
20
19
|
"""
|
|
21
20
|
Initialize the LollmsMCPBinding.
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
binding_name (str): The unique name of this binding.
|
|
25
21
|
"""
|
|
26
|
-
|
|
22
|
+
super().__init__(binding_name=binding_name, **kwargs)
|
|
23
|
+
self.settings = kwargs
|
|
27
24
|
|
|
28
25
|
|
|
29
26
|
@abstractmethod
|
|
30
27
|
def discover_tools(self, **kwargs) -> List[Dict[str, Any]]:
|
|
31
28
|
"""
|
|
32
29
|
Discover available tools compliant with the MCP specification.
|
|
33
|
-
|
|
34
|
-
Each tool definition should follow the MCP standard, typically including:
|
|
35
|
-
- name (str): Unique name of the tool.
|
|
36
|
-
- description (str): Natural language description of what the tool does.
|
|
37
|
-
- input_schema (dict): JSON schema defining the tool's input parameters.
|
|
38
|
-
- output_schema (dict): JSON schema defining the tool's output.
|
|
39
|
-
(Other MCP fields like `prompts`, `resources` could be supported by specific bindings)
|
|
40
|
-
|
|
41
|
-
Args:
|
|
42
|
-
**kwargs: Additional arguments specific to the binding's discovery mechanism
|
|
43
|
-
(e.g., tool_server_url, specific_tool_names_to_filter).
|
|
44
|
-
|
|
45
|
-
Returns:
|
|
46
|
-
List[Dict[str, Any]]: A list of tool definitions. Each dictionary
|
|
47
|
-
should conform to the MCP tool definition structure.
|
|
48
|
-
Returns an empty list if no tools are found or an error occurs.
|
|
49
30
|
"""
|
|
50
31
|
pass
|
|
51
32
|
|
|
@@ -56,35 +37,21 @@ class LollmsMCPBinding(ABC):
|
|
|
56
37
|
**kwargs) -> Dict[str, Any]:
|
|
57
38
|
"""
|
|
58
39
|
Execute a specified tool with the given parameters.
|
|
59
|
-
|
|
60
|
-
The execution should adhere to the input and output schemas defined in the
|
|
61
|
-
tool's MCP definition.
|
|
62
|
-
|
|
63
|
-
Args:
|
|
64
|
-
tool_name (str): The name of the tool to execute.
|
|
65
|
-
params (Dict[str, Any]): A dictionary of parameters to pass to the tool,
|
|
66
|
-
conforming to the tool's `input_schema`.
|
|
67
|
-
**kwargs: Additional arguments specific to the binding's execution mechanism
|
|
68
|
-
(e.g., timeout, user_context).
|
|
69
|
-
|
|
70
|
-
Returns:
|
|
71
|
-
Dict[str, Any]: The result of the tool execution, conforming to the
|
|
72
|
-
tool's `output_schema`. If an error occurs during
|
|
73
|
-
execution, the dictionary should ideally include an 'error'
|
|
74
|
-
key with a descriptive message.
|
|
75
|
-
Example success: {"result": "Weather is sunny"}
|
|
76
|
-
Example error: {"error": "API call failed", "details": "..."}
|
|
77
40
|
"""
|
|
78
41
|
pass
|
|
79
42
|
|
|
80
43
|
def get_binding_config(self) -> Dict[str, Any]:
|
|
81
44
|
"""
|
|
82
45
|
Returns the configuration of the binding.
|
|
46
|
+
"""
|
|
47
|
+
return self.settings
|
|
83
48
|
|
|
84
|
-
|
|
85
|
-
|
|
49
|
+
def list_models(self) -> List[Any]:
|
|
50
|
+
"""
|
|
51
|
+
For MCP, list_models returns an empty list as it primarily deals with tools.
|
|
52
|
+
Or could be implemented to return available tools as models if desired.
|
|
86
53
|
"""
|
|
87
|
-
return
|
|
54
|
+
return []
|
|
88
55
|
|
|
89
56
|
class LollmsMCPBindingManager:
|
|
90
57
|
"""
|
|
@@ -94,14 +61,9 @@ class LollmsMCPBindingManager:
|
|
|
94
61
|
def __init__(self, mcp_bindings_dir: Union[str, Path] = Path(__file__).parent / "mcp_bindings"):
|
|
95
62
|
"""
|
|
96
63
|
Initialize the LollmsMCPBindingManager.
|
|
97
|
-
|
|
98
|
-
Args:
|
|
99
|
-
mcp_bindings_dir (Union[str, Path]): Directory containing MCP binding implementations.
|
|
100
|
-
Defaults to "mcp_bindings" subdirectory relative to this file.
|
|
101
64
|
"""
|
|
102
65
|
self.mcp_bindings_dir = Path(mcp_bindings_dir)
|
|
103
66
|
if not self.mcp_bindings_dir.is_absolute():
|
|
104
|
-
# If relative, assume it's relative to the parent of this file (lollms_client directory)
|
|
105
67
|
self.mcp_bindings_dir = (Path(__file__).parent.parent / mcp_bindings_dir).resolve()
|
|
106
68
|
|
|
107
69
|
self.available_bindings: Dict[str, type[LollmsMCPBinding]] = {}
|
|
@@ -110,9 +72,7 @@ class LollmsMCPBindingManager:
|
|
|
110
72
|
|
|
111
73
|
def _load_binding_class(self, binding_name: str) -> Optional[type[LollmsMCPBinding]]:
|
|
112
74
|
"""
|
|
113
|
-
Dynamically load a specific MCP binding class
|
|
114
|
-
Assumes each binding is in a subdirectory named after the binding_name,
|
|
115
|
-
and has an __init__.py that defines a `BindingName` variable and the binding class.
|
|
75
|
+
Dynamically load a specific MCP binding class.
|
|
116
76
|
"""
|
|
117
77
|
binding_dir = self.mcp_bindings_dir / binding_name
|
|
118
78
|
if binding_dir.is_dir():
|
|
@@ -127,7 +87,6 @@ class LollmsMCPBindingManager:
|
|
|
127
87
|
module = importlib.util.module_from_spec(module_spec)
|
|
128
88
|
module_spec.loader.exec_module(module)
|
|
129
89
|
|
|
130
|
-
# Ensure BindingName is defined in the module, and it matches the class name
|
|
131
90
|
if not hasattr(module, 'BindingName'):
|
|
132
91
|
ASCIIColors.warning(f"Binding '{binding_name}' __init__.py does not define BindingName variable.")
|
|
133
92
|
return None
|
|
@@ -155,15 +114,6 @@ class LollmsMCPBindingManager:
|
|
|
155
114
|
) -> Optional[LollmsMCPBinding]:
|
|
156
115
|
"""
|
|
157
116
|
Create an instance of a specific MCP binding.
|
|
158
|
-
|
|
159
|
-
Args:
|
|
160
|
-
binding_name (str): Name of the MCP binding to create.
|
|
161
|
-
config (Optional[Dict[str, Any]]): Configuration for the binding.
|
|
162
|
-
lollms_paths (Optional[Dict[str, Union[str, Path]]]): LOLLMS specific paths.
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
Returns:
|
|
166
|
-
Optional[LollmsMCPBinding]: Binding instance or None if creation failed.
|
|
167
117
|
"""
|
|
168
118
|
if binding_name not in self.available_bindings:
|
|
169
119
|
binding_class = self._load_binding_class(binding_name)
|
|
@@ -177,6 +127,7 @@ class LollmsMCPBindingManager:
|
|
|
177
127
|
if binding_class_to_instantiate:
|
|
178
128
|
try:
|
|
179
129
|
return binding_class_to_instantiate(
|
|
130
|
+
binding_name=binding_name,
|
|
180
131
|
**kwargs
|
|
181
132
|
)
|
|
182
133
|
except Exception as e:
|
|
@@ -188,8 +139,7 @@ class LollmsMCPBindingManager:
|
|
|
188
139
|
|
|
189
140
|
def get_available_bindings(self) -> List[str]:
|
|
190
141
|
"""
|
|
191
|
-
Return list of available MCP binding names
|
|
192
|
-
This method scans the directory structure.
|
|
142
|
+
Return list of available MCP binding names.
|
|
193
143
|
"""
|
|
194
144
|
available = []
|
|
195
145
|
if self.mcp_bindings_dir.is_dir():
|
|
@@ -201,12 +151,6 @@ class LollmsMCPBindingManager:
|
|
|
201
151
|
def get_binding_description(self, binding_name: str) -> Optional[Dict[str, Any]]:
|
|
202
152
|
"""
|
|
203
153
|
Loads and returns the content of the description.yaml file for a given binding.
|
|
204
|
-
|
|
205
|
-
Args:
|
|
206
|
-
binding_name (str): The name of the binding.
|
|
207
|
-
|
|
208
|
-
Returns:
|
|
209
|
-
Optional[Dict[str, Any]]: A dictionary with the parsed YAML content, or None if the file doesn't exist or is invalid.
|
|
210
154
|
"""
|
|
211
155
|
binding_dir = self.mcp_bindings_dir / binding_name
|
|
212
156
|
description_file = binding_dir / "description.yaml"
|
|
@@ -226,4 +170,19 @@ class LollmsMCPBindingManager:
|
|
|
226
170
|
except Exception as e:
|
|
227
171
|
ASCIIColors.error(f"Error reading description.yaml for MCP binding '{binding_name}': {e}")
|
|
228
172
|
trace_exception(e)
|
|
229
|
-
return None
|
|
173
|
+
return None
|
|
174
|
+
|
|
175
|
+
def list_binding_models(mcp_binding_name: str, mcp_binding_config: Optional[Dict[str, any]]|None = None, mcp_bindings_dir: str|Path = Path(__file__).parent / "mcp_bindings") -> List[Dict]:
|
|
176
|
+
"""
|
|
177
|
+
Lists all available models/tools for a specific binding.
|
|
178
|
+
"""
|
|
179
|
+
binding = LollmsMCPBindingManager(mcp_bindings_dir).create_binding(
|
|
180
|
+
binding_name=mcp_binding_name,
|
|
181
|
+
**{
|
|
182
|
+
k: v
|
|
183
|
+
for k, v in (mcp_binding_config or {}).items()
|
|
184
|
+
if k != "binding_name"
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
return binding.discover_tools() if binding else []
|
|
@@ -1,39 +1,27 @@
|
|
|
1
1
|
# lollms_client/lollms_stt_binding.py
|
|
2
|
-
from abc import
|
|
2
|
+
from abc import abstractmethod
|
|
3
3
|
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
|
+
import yaml
|
|
8
|
+
from lollms_client.lollms_base_binding import LollmsBaseBinding
|
|
7
9
|
|
|
8
|
-
class LollmsSTTBinding(
|
|
10
|
+
class LollmsSTTBinding(LollmsBaseBinding):
|
|
9
11
|
"""Abstract base class for all LOLLMS Speech-to-Text bindings."""
|
|
10
12
|
|
|
11
13
|
def __init__(self,
|
|
12
|
-
binding_name:str="unknown"
|
|
14
|
+
binding_name:str="unknown",
|
|
15
|
+
**kwargs):
|
|
13
16
|
"""
|
|
14
17
|
Initialize the LollmsSTTBinding base class.
|
|
15
|
-
|
|
16
|
-
Args:
|
|
17
|
-
binding_name (Optional[str]): The binding name
|
|
18
18
|
"""
|
|
19
|
-
|
|
19
|
+
super().__init__(binding_name=binding_name, **kwargs)
|
|
20
20
|
|
|
21
21
|
@abstractmethod
|
|
22
22
|
def transcribe_audio(self, audio_path: Union[str, Path], model: Optional[str] = None, **kwargs) -> str:
|
|
23
23
|
"""
|
|
24
24
|
Transcribes the audio file at the given path into text.
|
|
25
|
-
|
|
26
|
-
Args:
|
|
27
|
-
audio_path (Union[str, Path]): The path to the audio file to transcribe.
|
|
28
|
-
model (Optional[str]): The specific STT model to use (if supported by the binding).
|
|
29
|
-
If None, a default model might be used.
|
|
30
|
-
**kwargs: Additional binding-specific parameters (e.g., language hint).
|
|
31
|
-
|
|
32
|
-
Returns:
|
|
33
|
-
str: The transcribed text.
|
|
34
|
-
|
|
35
|
-
Raises:
|
|
36
|
-
Exception: If audio transcription fails.
|
|
37
25
|
"""
|
|
38
26
|
pass
|
|
39
27
|
|
|
@@ -41,12 +29,6 @@ class LollmsSTTBinding(ABC):
|
|
|
41
29
|
def list_models(self, **kwargs) -> List[str]:
|
|
42
30
|
"""
|
|
43
31
|
Lists the available STT models supported by the binding.
|
|
44
|
-
|
|
45
|
-
Args:
|
|
46
|
-
**kwargs: Additional binding-specific parameters.
|
|
47
|
-
|
|
48
|
-
Returns:
|
|
49
|
-
List[str]: A list of available STT model identifiers.
|
|
50
32
|
"""
|
|
51
33
|
pass
|
|
52
34
|
|
|
@@ -54,13 +36,6 @@ class LollmsSTTBindingManager:
|
|
|
54
36
|
"""Manages STT binding discovery and instantiation."""
|
|
55
37
|
|
|
56
38
|
def __init__(self, stt_bindings_dir: Union[str, Path] = Path(__file__).parent.parent / "stt_bindings"):
|
|
57
|
-
"""
|
|
58
|
-
Initialize the LollmsSTTBindingManager.
|
|
59
|
-
|
|
60
|
-
Args:
|
|
61
|
-
stt_bindings_dir (Union[str, Path]): Directory containing STT binding implementations.
|
|
62
|
-
Defaults to the "stt_bindings" subdirectory.
|
|
63
|
-
"""
|
|
64
39
|
self.stt_bindings_dir = Path(stt_bindings_dir)
|
|
65
40
|
self.available_bindings = {}
|
|
66
41
|
|
|
@@ -85,17 +60,6 @@ class LollmsSTTBindingManager:
|
|
|
85
60
|
**kwargs) -> Optional[LollmsSTTBinding]:
|
|
86
61
|
"""
|
|
87
62
|
Create an instance of a specific STT binding.
|
|
88
|
-
|
|
89
|
-
Args:
|
|
90
|
-
binding_name (str): Name of the STT binding to create.
|
|
91
|
-
host_address (Optional[str]): Host address for the service.
|
|
92
|
-
model_name (Optional[str]): Default model identifier.
|
|
93
|
-
service_key (Optional[str]): Authentication key for the service.
|
|
94
|
-
verify_ssl_certificate (bool): Whether to verify SSL certificates.
|
|
95
|
-
**kwargs: Additional parameters specific to the binding's __init__.
|
|
96
|
-
|
|
97
|
-
Returns:
|
|
98
|
-
Optional[LollmsSTTBinding]: Binding instance or None if creation failed.
|
|
99
63
|
"""
|
|
100
64
|
if binding_name not in self.available_bindings:
|
|
101
65
|
self._load_binding(binding_name)
|
|
@@ -103,11 +67,14 @@ class LollmsSTTBindingManager:
|
|
|
103
67
|
binding_class = self.available_bindings.get(binding_name)
|
|
104
68
|
if binding_class:
|
|
105
69
|
try:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
70
|
+
# Merge specific args into kwargs to match unified init
|
|
71
|
+
kwargs.update({
|
|
72
|
+
"host_address": host_address,
|
|
73
|
+
"model_name": model_name,
|
|
74
|
+
"service_key": service_key,
|
|
75
|
+
"verify_ssl_certificate": verify_ssl_certificate
|
|
76
|
+
})
|
|
77
|
+
return binding_class(binding_name=binding_name, **kwargs)
|
|
111
78
|
except Exception as e:
|
|
112
79
|
trace_exception(e)
|
|
113
80
|
print(f"Failed to instantiate STT binding {binding_name}: {str(e)}")
|
|
@@ -117,9 +84,75 @@ class LollmsSTTBindingManager:
|
|
|
117
84
|
def get_available_bindings(self) -> list[str]:
|
|
118
85
|
"""
|
|
119
86
|
Return list of available STT binding names based on subdirectories.
|
|
120
|
-
|
|
121
|
-
Returns:
|
|
122
|
-
list[str]: List of binding names.
|
|
123
87
|
"""
|
|
124
88
|
return [binding_dir.name for binding_dir in self.stt_bindings_dir.iterdir()
|
|
125
|
-
if binding_dir.is_dir() and (binding_dir / "__init__.py").exists()]
|
|
89
|
+
if binding_dir.is_dir() and (binding_dir / "__init__.py").exists()]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@staticmethod
|
|
93
|
+
def _get_fallback_description(binding_name: str) -> Dict:
|
|
94
|
+
return {
|
|
95
|
+
"binding_name": binding_name,
|
|
96
|
+
"title": binding_name.replace("_", " ").title(),
|
|
97
|
+
"author": "Unknown",
|
|
98
|
+
"version": "N/A",
|
|
99
|
+
"description": f"A binding for {binding_name}. No description.yaml file was found.",
|
|
100
|
+
"input_parameters": [
|
|
101
|
+
{
|
|
102
|
+
"name": "model_name",
|
|
103
|
+
"type": "str",
|
|
104
|
+
"description": "The model name or ID to be used.",
|
|
105
|
+
"mandatory": False,
|
|
106
|
+
"default": ""
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"generate_audio_parameters": []
|
|
110
|
+
}
|
|
111
|
+
@staticmethod
|
|
112
|
+
def get_bindings_list(stt_bindings_dir: Union[str, Path]) -> List[Dict]:
|
|
113
|
+
bindings_dir = Path(stt_bindings_dir)
|
|
114
|
+
if not bindings_dir.is_dir():
|
|
115
|
+
return []
|
|
116
|
+
|
|
117
|
+
bindings_list = []
|
|
118
|
+
for binding_folder in bindings_dir.iterdir():
|
|
119
|
+
if binding_folder.is_dir() and (binding_folder / "__init__.py").exists():
|
|
120
|
+
binding_name = binding_folder.name
|
|
121
|
+
description_file = binding_folder / "description.yaml"
|
|
122
|
+
|
|
123
|
+
binding_info = {}
|
|
124
|
+
if description_file.exists():
|
|
125
|
+
try:
|
|
126
|
+
with open(description_file, 'r', encoding='utf-8') as f:
|
|
127
|
+
binding_info = yaml.safe_load(f)
|
|
128
|
+
binding_info['binding_name'] = binding_name
|
|
129
|
+
except Exception as e:
|
|
130
|
+
print(f"Error loading description.yaml for {binding_name}: {e}")
|
|
131
|
+
binding_info = LollmsSTTBindingManager._get_fallback_description(binding_name)
|
|
132
|
+
else:
|
|
133
|
+
binding_info = LollmsSTTBindingManager._get_fallback_description(binding_name)
|
|
134
|
+
|
|
135
|
+
bindings_list.append(binding_info)
|
|
136
|
+
|
|
137
|
+
return sorted(bindings_list, key=lambda b: b.get('title', b['binding_name']))
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def get_available_bindings(stt_bindings_dir: Union[str, Path] = None) -> List[Dict]:
|
|
141
|
+
if stt_bindings_dir is None:
|
|
142
|
+
stt_bindings_dir = Path(__file__).resolve().parent / "stt_bindings"
|
|
143
|
+
return LollmsSTTBindingManager.get_bindings_list(stt_bindings_dir)
|
|
144
|
+
|
|
145
|
+
def list_binding_models(stt_binding_name: str, stt_binding_config: Optional[Dict[str, any]]|None = None, stt_bindings_dir: str|Path = Path(__file__).parent / "stt_bindings") -> List[Dict]:
|
|
146
|
+
"""
|
|
147
|
+
Lists all available models for a specific binding.
|
|
148
|
+
"""
|
|
149
|
+
binding = LollmsSTTBindingManager(stt_bindings_dir).create_binding(
|
|
150
|
+
binding_name=stt_binding_name,
|
|
151
|
+
**{
|
|
152
|
+
k: v
|
|
153
|
+
for k, v in (stt_binding_config or {}).items()
|
|
154
|
+
if k != "binding_name"
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
return binding.list_models() if binding else []
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
from abc import
|
|
1
|
+
from abc import abstractmethod
|
|
2
2
|
import importlib
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
from typing import Optional, List, Dict, Any, Union
|
|
5
5
|
from ascii_colors import trace_exception
|
|
6
6
|
import yaml
|
|
7
|
+
from lollms_client.lollms_base_binding import LollmsBaseBinding
|
|
7
8
|
|
|
8
|
-
class LollmsTTIBinding(
|
|
9
|
+
class LollmsTTIBinding(LollmsBaseBinding):
|
|
9
10
|
"""Abstract base class for all LOLLMS Text-to-Image bindings."""
|
|
10
11
|
|
|
11
12
|
def __init__(self,
|
|
12
|
-
binding_name:str="unknown"
|
|
13
|
+
binding_name:str="unknown",
|
|
14
|
+
**kwargs):
|
|
13
15
|
"""
|
|
14
16
|
Initialize the LollmsTTIBinding base class.
|
|
15
|
-
|
|
16
|
-
Args:
|
|
17
|
-
binding_name (Optional[str]): The binding name
|
|
18
17
|
"""
|
|
19
|
-
|
|
18
|
+
super().__init__(binding_name=binding_name, **kwargs)
|
|
20
19
|
|
|
21
20
|
@abstractmethod
|
|
22
21
|
def generate_image(self,
|
|
@@ -27,19 +26,6 @@ class LollmsTTIBinding(ABC):
|
|
|
27
26
|
**kwargs) -> bytes:
|
|
28
27
|
"""
|
|
29
28
|
Generates image data from the provided text prompt.
|
|
30
|
-
|
|
31
|
-
Args:
|
|
32
|
-
prompt (str): The positive text prompt describing the desired image.
|
|
33
|
-
negative_prompt (Optional[str]): Text prompt describing elements to avoid.
|
|
34
|
-
width (int): The desired width of the image.
|
|
35
|
-
height (int): The desired height of the image.
|
|
36
|
-
**kwargs: Additional binding-specific parameters (e.g., seed, steps, cfg_scale).
|
|
37
|
-
|
|
38
|
-
Returns:
|
|
39
|
-
bytes: The generated image data (e.g., in PNG or JPEG format).
|
|
40
|
-
|
|
41
|
-
Raises:
|
|
42
|
-
Exception: If image generation fails.
|
|
43
29
|
"""
|
|
44
30
|
pass
|
|
45
31
|
|
|
@@ -54,21 +40,6 @@ class LollmsTTIBinding(ABC):
|
|
|
54
40
|
**kwargs) -> bytes:
|
|
55
41
|
"""
|
|
56
42
|
Edits an image or a set of images based on the provided prompts.
|
|
57
|
-
|
|
58
|
-
Args:
|
|
59
|
-
images (Union[str, List[str]]): One or multiple images in URL or base64 format.
|
|
60
|
-
prompt (str): Positive prompt describing desired modifications.
|
|
61
|
-
negative_prompt (Optional[str]): Prompt describing elements to avoid.
|
|
62
|
-
mask (Optional[str]): A mask image (URL or base64). Only valid if a single image is provided.
|
|
63
|
-
width (Optional[int]): Desired width of the output. If None, binding decides.
|
|
64
|
-
height (Optional[int]): Desired height of the output. If None, binding decides.
|
|
65
|
-
**kwargs: Additional binding-specific parameters (e.g., seed, steps, cfg_scale).
|
|
66
|
-
|
|
67
|
-
Returns:
|
|
68
|
-
bytes: The edited/generated image data (e.g., in PNG or JPEG format).
|
|
69
|
-
|
|
70
|
-
Raises:
|
|
71
|
-
Exception: If image editing fails.
|
|
72
43
|
"""
|
|
73
44
|
pass
|
|
74
45
|
|
|
@@ -83,7 +54,7 @@ class LollmsTTIBinding(ABC):
|
|
|
83
54
|
pass
|
|
84
55
|
|
|
85
56
|
@abstractmethod
|
|
86
|
-
def
|
|
57
|
+
def list_models(self) -> list:
|
|
87
58
|
"""Lists models"""
|
|
88
59
|
pass
|
|
89
60
|
|
|
@@ -120,7 +91,7 @@ class LollmsTTIBindingManager:
|
|
|
120
91
|
binding_class = self.available_bindings.get(binding_name)
|
|
121
92
|
if binding_class:
|
|
122
93
|
try:
|
|
123
|
-
return binding_class(**kwargs)
|
|
94
|
+
return binding_class(binding_name=binding_name, **kwargs)
|
|
124
95
|
except Exception as e:
|
|
125
96
|
trace_exception(e)
|
|
126
97
|
print(f"Failed to instantiate TTI binding {binding_name}: {str(e)}")
|
|
@@ -204,3 +175,18 @@ def get_available_bindings(tti_bindings_dir: Union[str, Path] = None) -> List[Di
|
|
|
204
175
|
if tti_bindings_dir is None:
|
|
205
176
|
tti_bindings_dir = Path(__file__).parent / "tti_bindings"
|
|
206
177
|
return LollmsTTIBindingManager.get_bindings_list(tti_bindings_dir)
|
|
178
|
+
|
|
179
|
+
def list_binding_models(tti_binding_name: str, tti_binding_config: Optional[Dict[str, any]]|None = None, tti_bindings_dir: str|Path = Path(__file__).parent / "tti_bindings") -> List[Dict]:
|
|
180
|
+
"""
|
|
181
|
+
Lists all available models for a specific binding.
|
|
182
|
+
"""
|
|
183
|
+
binding = LollmsTTIBindingManager(tti_bindings_dir).create_binding(
|
|
184
|
+
binding_name=tti_binding_name,
|
|
185
|
+
**{
|
|
186
|
+
k: v
|
|
187
|
+
for k, v in (tti_binding_config or {}).items()
|
|
188
|
+
if k != "binding_name"
|
|
189
|
+
}
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
return binding.list_models() if binding else []
|
|
@@ -1,38 +1,27 @@
|
|
|
1
1
|
# lollms_client/lollms_ttm_binding.py
|
|
2
|
-
from abc import
|
|
2
|
+
from abc import abstractmethod
|
|
3
3
|
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
|
+
from lollms_client.lollms_base_binding import LollmsBaseBinding
|
|
7
8
|
|
|
8
|
-
class LollmsTTMBinding(
|
|
9
|
+
class LollmsTTMBinding(LollmsBaseBinding):
|
|
9
10
|
"""Abstract base class for all LOLLMS Text-to-Music bindings."""
|
|
10
11
|
|
|
11
12
|
def __init__(self,
|
|
12
|
-
binding_name:str="unknown"
|
|
13
|
+
binding_name:str="unknown",
|
|
14
|
+
**kwargs):
|
|
13
15
|
"""
|
|
14
16
|
Initialize the LollmsTTMBinding base class.
|
|
15
|
-
|
|
16
|
-
Args:
|
|
17
|
-
binding_name (Optional[str]): The binding name
|
|
18
17
|
"""
|
|
19
|
-
|
|
18
|
+
super().__init__(binding_name=binding_name, **kwargs)
|
|
20
19
|
|
|
21
20
|
|
|
22
21
|
@abstractmethod
|
|
23
22
|
def generate_music(self, prompt: str, **kwargs) -> bytes:
|
|
24
23
|
"""
|
|
25
24
|
Generates music data from the provided text prompt.
|
|
26
|
-
|
|
27
|
-
Args:
|
|
28
|
-
prompt (str): The text prompt describing the desired music (e.g., genre, mood, instruments).
|
|
29
|
-
**kwargs: Additional binding-specific parameters (e.g., duration, style, seed).
|
|
30
|
-
|
|
31
|
-
Returns:
|
|
32
|
-
bytes: The generated music data (e.g., in WAV, MP3, or MIDI format).
|
|
33
|
-
|
|
34
|
-
Raises:
|
|
35
|
-
Exception: If music generation fails.
|
|
36
25
|
"""
|
|
37
26
|
pass
|
|
38
27
|
|
|
@@ -40,12 +29,6 @@ class LollmsTTMBinding(ABC):
|
|
|
40
29
|
def list_models(self, **kwargs) -> List[str]:
|
|
41
30
|
"""
|
|
42
31
|
Lists the available TTM models or services supported by the binding.
|
|
43
|
-
|
|
44
|
-
Args:
|
|
45
|
-
**kwargs: Additional binding-specific parameters.
|
|
46
|
-
|
|
47
|
-
Returns:
|
|
48
|
-
List[str]: A list of available model/service identifiers.
|
|
49
32
|
"""
|
|
50
33
|
pass
|
|
51
34
|
|
|
@@ -53,13 +36,6 @@ class LollmsTTMBindingManager:
|
|
|
53
36
|
"""Manages TTM binding discovery and instantiation."""
|
|
54
37
|
|
|
55
38
|
def __init__(self, ttm_bindings_dir: Union[str, Path] = Path(__file__).parent.parent / "ttm_bindings"):
|
|
56
|
-
"""
|
|
57
|
-
Initialize the LollmsTTMBindingManager.
|
|
58
|
-
|
|
59
|
-
Args:
|
|
60
|
-
ttm_bindings_dir (Union[str, Path]): Directory containing TTM binding implementations.
|
|
61
|
-
Defaults to the "ttm_bindings" subdirectory.
|
|
62
|
-
"""
|
|
63
39
|
self.ttm_bindings_dir = Path(ttm_bindings_dir)
|
|
64
40
|
self.available_bindings = {}
|
|
65
41
|
|
|
@@ -80,13 +56,6 @@ class LollmsTTMBindingManager:
|
|
|
80
56
|
**kwargs) -> Optional[LollmsTTMBinding]:
|
|
81
57
|
"""
|
|
82
58
|
Create an instance of a specific TTM binding.
|
|
83
|
-
|
|
84
|
-
Args:
|
|
85
|
-
binding_name (str): Name of the TTM binding to create.
|
|
86
|
-
**kwargs: Additional parameters specific to the binding's __init__.
|
|
87
|
-
|
|
88
|
-
Returns:
|
|
89
|
-
Optional[LollmsTTMBinding]: Binding instance or None if creation failed.
|
|
90
59
|
"""
|
|
91
60
|
if binding_name not in self.available_bindings:
|
|
92
61
|
self._load_binding(binding_name)
|
|
@@ -94,7 +63,7 @@ class LollmsTTMBindingManager:
|
|
|
94
63
|
binding_class = self.available_bindings.get(binding_name)
|
|
95
64
|
if binding_class:
|
|
96
65
|
try:
|
|
97
|
-
return binding_class(**kwargs)
|
|
66
|
+
return binding_class(binding_name=binding_name, **kwargs)
|
|
98
67
|
except Exception as e:
|
|
99
68
|
trace_exception(e)
|
|
100
69
|
print(f"Failed to instantiate TTM binding {binding_name}: {str(e)}")
|
|
@@ -104,9 +73,22 @@ class LollmsTTMBindingManager:
|
|
|
104
73
|
def get_available_bindings(self) -> list[str]:
|
|
105
74
|
"""
|
|
106
75
|
Return list of available TTM binding names based on subdirectories.
|
|
107
|
-
|
|
108
|
-
Returns:
|
|
109
|
-
list[str]: List of binding names.
|
|
110
76
|
"""
|
|
111
77
|
return [binding_dir.name for binding_dir in self.ttm_bindings_dir.iterdir()
|
|
112
|
-
if binding_dir.is_dir() and (binding_dir / "__init__.py").exists()]
|
|
78
|
+
if binding_dir.is_dir() and (binding_dir / "__init__.py").exists()]
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def list_binding_models(ttm_binding_name: str, ttm_binding_config: Optional[Dict[str, any]]|None = None, ttm_bindings_dir: str|Path = Path(__file__).parent / "ttm_bindings") -> List[Dict]:
|
|
82
|
+
"""
|
|
83
|
+
Lists all available models for a specific binding.
|
|
84
|
+
"""
|
|
85
|
+
binding = LollmsTTMBindingManager(ttm_bindings_dir).create_binding(
|
|
86
|
+
binding_name=ttm_binding_name,
|
|
87
|
+
**{
|
|
88
|
+
k: v
|
|
89
|
+
for k, v in (ttm_binding_config or {}).items()
|
|
90
|
+
if k != "binding_name"
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
return binding.list_models() if binding else []
|