lollms-client 1.5.6__py3-none-any.whl → 1.7.13__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 -35
- lollms_client/llm_bindings/gemini/__init__.py +261 -159
- lollms_client/llm_bindings/grok/__init__.py +52 -15
- 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/llama_cpp_server/__init__.py +605 -0
- 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 +345 -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 +65 -39
- lollms_client/lollms_llm_binding.py +126 -261
- lollms_client/lollms_mcp_binding.py +49 -77
- lollms_client/lollms_stt_binding.py +99 -52
- lollms_client/lollms_tti_binding.py +38 -38
- lollms_client/lollms_ttm_binding.py +38 -42
- lollms_client/lollms_tts_binding.py +43 -18
- lollms_client/lollms_ttv_binding.py +38 -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 +464 -803
- lollms_client/tti_bindings/diffusers/server/main.py +1062 -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.13.dist-info}/METADATA +113 -5
- lollms_client-1.7.13.dist-info/RECORD +90 -0
- lollms_client-1.5.6.dist-info/RECORD +0 -87
- {lollms_client-1.5.6.dist-info → lollms_client-1.7.13.dist-info}/WHEEL +0 -0
- {lollms_client-1.5.6.dist-info → lollms_client-1.7.13.dist-info}/licenses/LICENSE +0 -0
- {lollms_client-1.5.6.dist-info → lollms_client-1.7.13.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
|
-
from typing import Optional, List, Dict, Any, Union
|
|
5
|
+
from typing import Optional, List, Dict, Any, Union, Callable
|
|
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,35 @@ 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
|
|
48
|
+
|
|
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.
|
|
53
|
+
"""
|
|
54
|
+
return []
|
|
55
|
+
|
|
56
|
+
def get_zoo(self) -> List[Dict[str, Any]]:
|
|
57
|
+
"""
|
|
58
|
+
Returns a list of models available for download.
|
|
59
|
+
each entry is a dict with:
|
|
60
|
+
name, description, size, type, link
|
|
61
|
+
"""
|
|
62
|
+
return []
|
|
83
63
|
|
|
84
|
-
|
|
85
|
-
Dict[str, Any]: The configuration dictionary.
|
|
64
|
+
def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
|
|
86
65
|
"""
|
|
87
|
-
|
|
66
|
+
Downloads a model from the zoo using its index.
|
|
67
|
+
"""
|
|
68
|
+
return {"status": False, "message": "Not implemented"}
|
|
88
69
|
|
|
89
70
|
class LollmsMCPBindingManager:
|
|
90
71
|
"""
|
|
@@ -94,25 +75,17 @@ class LollmsMCPBindingManager:
|
|
|
94
75
|
def __init__(self, mcp_bindings_dir: Union[str, Path] = Path(__file__).parent / "mcp_bindings"):
|
|
95
76
|
"""
|
|
96
77
|
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
78
|
"""
|
|
102
79
|
self.mcp_bindings_dir = Path(mcp_bindings_dir)
|
|
103
80
|
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
81
|
self.mcp_bindings_dir = (Path(__file__).parent.parent / mcp_bindings_dir).resolve()
|
|
106
82
|
|
|
107
83
|
self.available_bindings: Dict[str, type[LollmsMCPBinding]] = {}
|
|
108
|
-
ASCIIColors.info(f"LollmsMCPBindingManager initialized. Bindings directory: {self.mcp_bindings_dir}")
|
|
109
84
|
|
|
110
85
|
|
|
111
86
|
def _load_binding_class(self, binding_name: str) -> Optional[type[LollmsMCPBinding]]:
|
|
112
87
|
"""
|
|
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.
|
|
88
|
+
Dynamically load a specific MCP binding class.
|
|
116
89
|
"""
|
|
117
90
|
binding_dir = self.mcp_bindings_dir / binding_name
|
|
118
91
|
if binding_dir.is_dir():
|
|
@@ -127,7 +100,6 @@ class LollmsMCPBindingManager:
|
|
|
127
100
|
module = importlib.util.module_from_spec(module_spec)
|
|
128
101
|
module_spec.loader.exec_module(module)
|
|
129
102
|
|
|
130
|
-
# Ensure BindingName is defined in the module, and it matches the class name
|
|
131
103
|
if not hasattr(module, 'BindingName'):
|
|
132
104
|
ASCIIColors.warning(f"Binding '{binding_name}' __init__.py does not define BindingName variable.")
|
|
133
105
|
return None
|
|
@@ -155,15 +127,6 @@ class LollmsMCPBindingManager:
|
|
|
155
127
|
) -> Optional[LollmsMCPBinding]:
|
|
156
128
|
"""
|
|
157
129
|
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
130
|
"""
|
|
168
131
|
if binding_name not in self.available_bindings:
|
|
169
132
|
binding_class = self._load_binding_class(binding_name)
|
|
@@ -177,6 +140,7 @@ class LollmsMCPBindingManager:
|
|
|
177
140
|
if binding_class_to_instantiate:
|
|
178
141
|
try:
|
|
179
142
|
return binding_class_to_instantiate(
|
|
143
|
+
binding_name=binding_name,
|
|
180
144
|
**kwargs
|
|
181
145
|
)
|
|
182
146
|
except Exception as e:
|
|
@@ -188,8 +152,7 @@ class LollmsMCPBindingManager:
|
|
|
188
152
|
|
|
189
153
|
def get_available_bindings(self) -> List[str]:
|
|
190
154
|
"""
|
|
191
|
-
Return list of available MCP binding names
|
|
192
|
-
This method scans the directory structure.
|
|
155
|
+
Return list of available MCP binding names.
|
|
193
156
|
"""
|
|
194
157
|
available = []
|
|
195
158
|
if self.mcp_bindings_dir.is_dir():
|
|
@@ -201,12 +164,6 @@ class LollmsMCPBindingManager:
|
|
|
201
164
|
def get_binding_description(self, binding_name: str) -> Optional[Dict[str, Any]]:
|
|
202
165
|
"""
|
|
203
166
|
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
167
|
"""
|
|
211
168
|
binding_dir = self.mcp_bindings_dir / binding_name
|
|
212
169
|
description_file = binding_dir / "description.yaml"
|
|
@@ -226,4 +183,19 @@ class LollmsMCPBindingManager:
|
|
|
226
183
|
except Exception as e:
|
|
227
184
|
ASCIIColors.error(f"Error reading description.yaml for MCP binding '{binding_name}': {e}")
|
|
228
185
|
trace_exception(e)
|
|
229
|
-
return None
|
|
186
|
+
return None
|
|
187
|
+
|
|
188
|
+
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]:
|
|
189
|
+
"""
|
|
190
|
+
Lists all available models/tools for a specific binding.
|
|
191
|
+
"""
|
|
192
|
+
binding = LollmsMCPBindingManager(mcp_bindings_dir).create_binding(
|
|
193
|
+
binding_name=mcp_binding_name,
|
|
194
|
+
**{
|
|
195
|
+
k: v
|
|
196
|
+
for k, v in (mcp_binding_config or {}).items()
|
|
197
|
+
if k != "binding_name"
|
|
198
|
+
}
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
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
|
-
from typing import Optional, List, Dict, Any, Union
|
|
5
|
+
from typing import Optional, List, Dict, Any, Union, Callable
|
|
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,26 +29,27 @@ 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.
|
|
32
|
+
"""
|
|
33
|
+
pass
|
|
44
34
|
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
def get_zoo(self) -> List[Dict[str, Any]]:
|
|
36
|
+
"""
|
|
37
|
+
Returns a list of models available for download.
|
|
38
|
+
each entry is a dict with:
|
|
39
|
+
name, description, size, type, link
|
|
40
|
+
"""
|
|
41
|
+
return []
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
List[str]: A list of available STT model identifiers.
|
|
43
|
+
def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
|
|
50
44
|
"""
|
|
51
|
-
|
|
45
|
+
Downloads a model from the zoo using its index.
|
|
46
|
+
"""
|
|
47
|
+
return {"status": False, "message": "Not implemented"}
|
|
52
48
|
|
|
53
49
|
class LollmsSTTBindingManager:
|
|
54
50
|
"""Manages STT binding discovery and instantiation."""
|
|
55
51
|
|
|
56
52
|
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
53
|
self.stt_bindings_dir = Path(stt_bindings_dir)
|
|
65
54
|
self.available_bindings = {}
|
|
66
55
|
|
|
@@ -85,17 +74,6 @@ class LollmsSTTBindingManager:
|
|
|
85
74
|
**kwargs) -> Optional[LollmsSTTBinding]:
|
|
86
75
|
"""
|
|
87
76
|
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
77
|
"""
|
|
100
78
|
if binding_name not in self.available_bindings:
|
|
101
79
|
self._load_binding(binding_name)
|
|
@@ -103,11 +81,14 @@ class LollmsSTTBindingManager:
|
|
|
103
81
|
binding_class = self.available_bindings.get(binding_name)
|
|
104
82
|
if binding_class:
|
|
105
83
|
try:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
84
|
+
# Merge specific args into kwargs to match unified init
|
|
85
|
+
kwargs.update({
|
|
86
|
+
"host_address": host_address,
|
|
87
|
+
"model_name": model_name,
|
|
88
|
+
"service_key": service_key,
|
|
89
|
+
"verify_ssl_certificate": verify_ssl_certificate
|
|
90
|
+
})
|
|
91
|
+
return binding_class(binding_name=binding_name, **kwargs)
|
|
111
92
|
except Exception as e:
|
|
112
93
|
trace_exception(e)
|
|
113
94
|
print(f"Failed to instantiate STT binding {binding_name}: {str(e)}")
|
|
@@ -117,9 +98,75 @@ class LollmsSTTBindingManager:
|
|
|
117
98
|
def get_available_bindings(self) -> list[str]:
|
|
118
99
|
"""
|
|
119
100
|
Return list of available STT binding names based on subdirectories.
|
|
120
|
-
|
|
121
|
-
Returns:
|
|
122
|
-
list[str]: List of binding names.
|
|
123
101
|
"""
|
|
124
102
|
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()]
|
|
103
|
+
if binding_dir.is_dir() and (binding_dir / "__init__.py").exists()]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@staticmethod
|
|
107
|
+
def _get_fallback_description(binding_name: str) -> Dict:
|
|
108
|
+
return {
|
|
109
|
+
"binding_name": binding_name,
|
|
110
|
+
"title": binding_name.replace("_", " ").title(),
|
|
111
|
+
"author": "Unknown",
|
|
112
|
+
"version": "N/A",
|
|
113
|
+
"description": f"A binding for {binding_name}. No description.yaml file was found.",
|
|
114
|
+
"input_parameters": [
|
|
115
|
+
{
|
|
116
|
+
"name": "model_name",
|
|
117
|
+
"type": "str",
|
|
118
|
+
"description": "The model name or ID to be used.",
|
|
119
|
+
"mandatory": False,
|
|
120
|
+
"default": ""
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
"generate_audio_parameters": []
|
|
124
|
+
}
|
|
125
|
+
@staticmethod
|
|
126
|
+
def get_bindings_list(stt_bindings_dir: Union[str, Path]) -> List[Dict]:
|
|
127
|
+
bindings_dir = Path(stt_bindings_dir)
|
|
128
|
+
if not bindings_dir.is_dir():
|
|
129
|
+
return []
|
|
130
|
+
|
|
131
|
+
bindings_list = []
|
|
132
|
+
for binding_folder in bindings_dir.iterdir():
|
|
133
|
+
if binding_folder.is_dir() and (binding_folder / "__init__.py").exists():
|
|
134
|
+
binding_name = binding_folder.name
|
|
135
|
+
description_file = binding_folder / "description.yaml"
|
|
136
|
+
|
|
137
|
+
binding_info = {}
|
|
138
|
+
if description_file.exists():
|
|
139
|
+
try:
|
|
140
|
+
with open(description_file, 'r', encoding='utf-8') as f:
|
|
141
|
+
binding_info = yaml.safe_load(f)
|
|
142
|
+
binding_info['binding_name'] = binding_name
|
|
143
|
+
except Exception as e:
|
|
144
|
+
print(f"Error loading description.yaml for {binding_name}: {e}")
|
|
145
|
+
binding_info = LollmsSTTBindingManager._get_fallback_description(binding_name)
|
|
146
|
+
else:
|
|
147
|
+
binding_info = LollmsSTTBindingManager._get_fallback_description(binding_name)
|
|
148
|
+
|
|
149
|
+
bindings_list.append(binding_info)
|
|
150
|
+
|
|
151
|
+
return sorted(bindings_list, key=lambda b: b.get('title', b['binding_name']))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def get_available_bindings(stt_bindings_dir: Union[str, Path] = None) -> List[Dict]:
|
|
155
|
+
if stt_bindings_dir is None:
|
|
156
|
+
stt_bindings_dir = Path(__file__).resolve().parent / "stt_bindings"
|
|
157
|
+
return LollmsSTTBindingManager.get_bindings_list(stt_bindings_dir)
|
|
158
|
+
|
|
159
|
+
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]:
|
|
160
|
+
"""
|
|
161
|
+
Lists all available models for a specific binding.
|
|
162
|
+
"""
|
|
163
|
+
binding = LollmsSTTBindingManager(stt_bindings_dir).create_binding(
|
|
164
|
+
binding_name=stt_binding_name,
|
|
165
|
+
**{
|
|
166
|
+
k: v
|
|
167
|
+
for k, v in (stt_binding_config or {}).items()
|
|
168
|
+
if k != "binding_name"
|
|
169
|
+
}
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
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
|
-
from typing import Optional, List, Dict, Any, Union
|
|
4
|
+
from typing import Optional, List, Dict, Any, Union, Callable
|
|
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,9 +54,23 @@ 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
|
|
60
|
+
|
|
61
|
+
def get_zoo(self) -> List[Dict[str, Any]]:
|
|
62
|
+
"""
|
|
63
|
+
Returns a list of models available for download.
|
|
64
|
+
each entry is a dict with:
|
|
65
|
+
name, description, size, type, link
|
|
66
|
+
"""
|
|
67
|
+
return []
|
|
68
|
+
|
|
69
|
+
def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
|
|
70
|
+
"""
|
|
71
|
+
Downloads a model from the zoo using its index.
|
|
72
|
+
"""
|
|
73
|
+
return {"status": False, "message": "Not implemented"}
|
|
89
74
|
|
|
90
75
|
@abstractmethod
|
|
91
76
|
def set_settings(self, settings: Dict[str, Any], **kwargs) -> bool:
|
|
@@ -120,7 +105,7 @@ class LollmsTTIBindingManager:
|
|
|
120
105
|
binding_class = self.available_bindings.get(binding_name)
|
|
121
106
|
if binding_class:
|
|
122
107
|
try:
|
|
123
|
-
return binding_class(**kwargs)
|
|
108
|
+
return binding_class(binding_name=binding_name, **kwargs)
|
|
124
109
|
except Exception as e:
|
|
125
110
|
trace_exception(e)
|
|
126
111
|
print(f"Failed to instantiate TTI binding {binding_name}: {str(e)}")
|
|
@@ -204,3 +189,18 @@ def get_available_bindings(tti_bindings_dir: Union[str, Path] = None) -> List[Di
|
|
|
204
189
|
if tti_bindings_dir is None:
|
|
205
190
|
tti_bindings_dir = Path(__file__).parent / "tti_bindings"
|
|
206
191
|
return LollmsTTIBindingManager.get_bindings_list(tti_bindings_dir)
|
|
192
|
+
|
|
193
|
+
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]:
|
|
194
|
+
"""
|
|
195
|
+
Lists all available models for a specific binding.
|
|
196
|
+
"""
|
|
197
|
+
binding = LollmsTTIBindingManager(tti_bindings_dir).create_binding(
|
|
198
|
+
binding_name=tti_binding_name,
|
|
199
|
+
**{
|
|
200
|
+
k: v
|
|
201
|
+
for k, v in (tti_binding_config or {}).items()
|
|
202
|
+
if k != "binding_name"
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
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
|
-
from typing import Optional, List, Dict, Any, Union
|
|
5
|
+
from typing import Optional, List, Dict, Any, Union, Callable
|
|
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,26 +29,27 @@ 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.
|
|
32
|
+
"""
|
|
33
|
+
pass
|
|
43
34
|
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
def get_zoo(self) -> List[Dict[str, Any]]:
|
|
36
|
+
"""
|
|
37
|
+
Returns a list of models available for download.
|
|
38
|
+
each entry is a dict with:
|
|
39
|
+
name, description, size, type, link
|
|
40
|
+
"""
|
|
41
|
+
return []
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
List[str]: A list of available model/service identifiers.
|
|
43
|
+
def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
|
|
49
44
|
"""
|
|
50
|
-
|
|
45
|
+
Downloads a model from the zoo using its index.
|
|
46
|
+
"""
|
|
47
|
+
return {"status": False, "message": "Not implemented"}
|
|
51
48
|
|
|
52
49
|
class LollmsTTMBindingManager:
|
|
53
50
|
"""Manages TTM binding discovery and instantiation."""
|
|
54
51
|
|
|
55
52
|
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
53
|
self.ttm_bindings_dir = Path(ttm_bindings_dir)
|
|
64
54
|
self.available_bindings = {}
|
|
65
55
|
|
|
@@ -80,13 +70,6 @@ class LollmsTTMBindingManager:
|
|
|
80
70
|
**kwargs) -> Optional[LollmsTTMBinding]:
|
|
81
71
|
"""
|
|
82
72
|
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
73
|
"""
|
|
91
74
|
if binding_name not in self.available_bindings:
|
|
92
75
|
self._load_binding(binding_name)
|
|
@@ -94,7 +77,7 @@ class LollmsTTMBindingManager:
|
|
|
94
77
|
binding_class = self.available_bindings.get(binding_name)
|
|
95
78
|
if binding_class:
|
|
96
79
|
try:
|
|
97
|
-
return binding_class(**kwargs)
|
|
80
|
+
return binding_class(binding_name=binding_name, **kwargs)
|
|
98
81
|
except Exception as e:
|
|
99
82
|
trace_exception(e)
|
|
100
83
|
print(f"Failed to instantiate TTM binding {binding_name}: {str(e)}")
|
|
@@ -104,9 +87,22 @@ class LollmsTTMBindingManager:
|
|
|
104
87
|
def get_available_bindings(self) -> list[str]:
|
|
105
88
|
"""
|
|
106
89
|
Return list of available TTM binding names based on subdirectories.
|
|
107
|
-
|
|
108
|
-
Returns:
|
|
109
|
-
list[str]: List of binding names.
|
|
110
90
|
"""
|
|
111
91
|
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()]
|
|
92
|
+
if binding_dir.is_dir() and (binding_dir / "__init__.py").exists()]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
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]:
|
|
96
|
+
"""
|
|
97
|
+
Lists all available models for a specific binding.
|
|
98
|
+
"""
|
|
99
|
+
binding = LollmsTTMBindingManager(ttm_bindings_dir).create_binding(
|
|
100
|
+
binding_name=ttm_binding_name,
|
|
101
|
+
**{
|
|
102
|
+
k: v
|
|
103
|
+
for k, v in (ttm_binding_config or {}).items()
|
|
104
|
+
if k != "binding_name"
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
return binding.list_models() if binding else []
|