lollms-client 0.11.0__py3-none-any.whl → 0.12.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/lollms/__init__.py +1 -0
- lollms_client/llm_bindings/ollama/__init__.py +2 -1
- lollms_client/llm_bindings/openai/__init__.py +2 -1
- lollms_client/llm_bindings/transformers/__init__.py +1 -0
- lollms_client/lollms_core.py +1133 -617
- lollms_client/lollms_llm_binding.py +2 -0
- lollms_client/lollms_stt_binding.py +137 -0
- lollms_client/lollms_tasks.py +1 -2
- lollms_client/lollms_tti_binding.py +175 -0
- lollms_client/lollms_ttm_binding.py +135 -0
- lollms_client/lollms_tts_binding.py +138 -0
- lollms_client/lollms_ttv_binding.py +135 -0
- lollms_client/stt_bindings/lollms/__init__.py +138 -0
- lollms_client/tti_bindings/lollms/__init__.py +210 -0
- lollms_client/ttm_bindings/__init__.py +0 -0
- lollms_client/ttm_bindings/lollms/__init__.py +73 -0
- lollms_client/tts_bindings/lollms/__init__.py +145 -0
- lollms_client/ttv_bindings/__init__.py +73 -0
- {lollms_client-0.11.0.dist-info → lollms_client-0.12.1.dist-info}/METADATA +1 -1
- lollms_client-0.12.1.dist-info/RECORD +41 -0
- lollms_client-0.11.0.dist-info/RECORD +0 -34
- {lollms_client-0.11.0.dist-info → lollms_client-0.12.1.dist-info}/WHEEL +0 -0
- {lollms_client-0.11.0.dist-info → lollms_client-0.12.1.dist-info}/licenses/LICENSE +0 -0
- {lollms_client-0.11.0.dist-info → lollms_client-0.12.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# lollms_client/lollms_ttv_binding.py
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
import importlib
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Optional, List, Dict, Any, Union
|
|
6
|
+
from ascii_colors import trace_exception
|
|
7
|
+
|
|
8
|
+
class LollmsTTVBinding(ABC):
|
|
9
|
+
"""Abstract base class for all LOLLMS Text-to-Video bindings."""
|
|
10
|
+
|
|
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):
|
|
16
|
+
"""
|
|
17
|
+
Initialize the LollmsTTVBinding base class.
|
|
18
|
+
|
|
19
|
+
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.
|
|
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
|
|
32
|
+
|
|
33
|
+
@abstractmethod
|
|
34
|
+
def generate_video(self, prompt: str, **kwargs) -> bytes:
|
|
35
|
+
"""
|
|
36
|
+
Generates video data from the provided text prompt.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
prompt (str): The text prompt describing the desired video content.
|
|
40
|
+
**kwargs: Additional binding-specific parameters (e.g., duration, fps, style, seed).
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
bytes: The generated video data (e.g., in MP4 format).
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
Exception: If video generation fails.
|
|
47
|
+
"""
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
@abstractmethod
|
|
51
|
+
def list_models(self, **kwargs) -> List[str]:
|
|
52
|
+
"""
|
|
53
|
+
Lists the available TTV models or services supported by the binding.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
**kwargs: Additional binding-specific parameters.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
List[str]: A list of available model/service identifiers.
|
|
60
|
+
"""
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
class LollmsTTVBindingManager:
|
|
64
|
+
"""Manages TTV binding discovery and instantiation."""
|
|
65
|
+
|
|
66
|
+
def __init__(self, ttv_bindings_dir: Union[str, Path] = Path(__file__).parent.parent / "ttv_bindings"):
|
|
67
|
+
"""
|
|
68
|
+
Initialize the LollmsTTVBindingManager.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
ttv_bindings_dir (Union[str, Path]): Directory containing TTV binding implementations.
|
|
72
|
+
Defaults to the "ttv_bindings" subdirectory.
|
|
73
|
+
"""
|
|
74
|
+
self.ttv_bindings_dir = Path(ttv_bindings_dir)
|
|
75
|
+
self.available_bindings = {}
|
|
76
|
+
|
|
77
|
+
def _load_binding(self, binding_name: str):
|
|
78
|
+
"""Dynamically load a specific TTV binding implementation."""
|
|
79
|
+
binding_dir = self.ttv_bindings_dir / binding_name
|
|
80
|
+
if binding_dir.is_dir() and (binding_dir / "__init__.py").exists():
|
|
81
|
+
try:
|
|
82
|
+
module = importlib.import_module(f"lollms_client.ttv_bindings.{binding_name}")
|
|
83
|
+
binding_class = getattr(module, module.BindingName) # Assumes BindingName is defined
|
|
84
|
+
self.available_bindings[binding_name] = binding_class
|
|
85
|
+
except Exception as e:
|
|
86
|
+
trace_exception(e)
|
|
87
|
+
print(f"Failed to load TTV binding {binding_name}: {str(e)}")
|
|
88
|
+
|
|
89
|
+
def create_binding(self,
|
|
90
|
+
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
|
+
**kwargs) -> Optional[LollmsTTVBinding]:
|
|
96
|
+
"""
|
|
97
|
+
Create an instance of a specific TTV binding.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
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
|
+
**kwargs: Additional parameters specific to the binding's __init__.
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
Optional[LollmsTTVBinding]: Binding instance or None if creation failed.
|
|
109
|
+
"""
|
|
110
|
+
if binding_name not in self.available_bindings:
|
|
111
|
+
self._load_binding(binding_name)
|
|
112
|
+
|
|
113
|
+
binding_class = self.available_bindings.get(binding_name)
|
|
114
|
+
if binding_class:
|
|
115
|
+
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)
|
|
121
|
+
except Exception as e:
|
|
122
|
+
trace_exception(e)
|
|
123
|
+
print(f"Failed to instantiate TTV binding {binding_name}: {str(e)}")
|
|
124
|
+
return None
|
|
125
|
+
return None
|
|
126
|
+
|
|
127
|
+
def get_available_bindings(self) -> list[str]:
|
|
128
|
+
"""
|
|
129
|
+
Return list of available TTV binding names based on subdirectories.
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
list[str]: List of binding names.
|
|
133
|
+
"""
|
|
134
|
+
return [binding_dir.name for binding_dir in self.ttv_bindings_dir.iterdir()
|
|
135
|
+
if binding_dir.is_dir() and (binding_dir / "__init__.py").exists()]
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# lollms_client/stt_bindings/lollms/__init__.py
|
|
2
|
+
import requests
|
|
3
|
+
import base64
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from lollms_client.lollms_stt_binding import LollmsSTTBinding
|
|
6
|
+
from typing import Optional, List, Union
|
|
7
|
+
from ascii_colors import trace_exception, ASCIIColors
|
|
8
|
+
import json # Added for potential error parsing
|
|
9
|
+
|
|
10
|
+
# Defines the binding name for the manager
|
|
11
|
+
BindingName = "LollmsSTTBinding_Impl"
|
|
12
|
+
|
|
13
|
+
class LollmsSTTBinding_Impl(LollmsSTTBinding):
|
|
14
|
+
"""Concrete implementation of the LollmsSTTBinding for the standard LOLLMS server."""
|
|
15
|
+
|
|
16
|
+
def __init__(self,
|
|
17
|
+
host_address: Optional[str] = "http://localhost:9600", # Default LOLLMS host
|
|
18
|
+
model_name: Optional[str] = None, # Default model (server decides if None)
|
|
19
|
+
service_key: Optional[str] = None,
|
|
20
|
+
verify_ssl_certificate: bool = True):
|
|
21
|
+
"""
|
|
22
|
+
Initialize the LOLLMS STT binding.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
host_address (Optional[str]): Host address for the LOLLMS service.
|
|
26
|
+
model_name (Optional[str]): Default STT model identifier.
|
|
27
|
+
service_key (Optional[str]): Authentication key (currently unused by default LOLLMS STT).
|
|
28
|
+
verify_ssl_certificate (bool): Whether to verify SSL certificates.
|
|
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)
|
|
34
|
+
|
|
35
|
+
def transcribe_audio(self, audio_path: Union[str, Path], model: Optional[str] = None, **kwargs) -> str:
|
|
36
|
+
"""
|
|
37
|
+
Transcribes audio using an assumed LOLLMS /audio2text endpoint.
|
|
38
|
+
Sends audio data as base64 encoded string.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
audio_path (Union[str, Path]): Path to the audio file.
|
|
42
|
+
model (Optional[str]): Specific STT model to use. If None, uses default from init.
|
|
43
|
+
**kwargs: Additional parameters (e.g., language hint - passed if provided).
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
str: The transcribed text.
|
|
47
|
+
|
|
48
|
+
Raises:
|
|
49
|
+
FileNotFoundError: If the audio file does not exist.
|
|
50
|
+
Exception: If the request fails or transcription fails on the server.
|
|
51
|
+
"""
|
|
52
|
+
endpoint = f"{self.host_address}/audio2text" # Assumed endpoint
|
|
53
|
+
model_to_use = model if model else self.model_name
|
|
54
|
+
|
|
55
|
+
audio_file = Path(audio_path)
|
|
56
|
+
if not audio_file.exists():
|
|
57
|
+
raise FileNotFoundError(f"Audio file not found at: {audio_path}")
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
# Read audio file and encode as base64
|
|
61
|
+
with open(audio_file, "rb") as f:
|
|
62
|
+
audio_data = f.read()
|
|
63
|
+
audio_base64 = base64.b64encode(audio_data).decode('utf-8')
|
|
64
|
+
|
|
65
|
+
request_data = {
|
|
66
|
+
"audio_data": audio_base64, # Sending data instead of path
|
|
67
|
+
"model": model_to_use,
|
|
68
|
+
"file_name": audio_file.name # Send filename as metadata if server supports it
|
|
69
|
+
}
|
|
70
|
+
# Add language hint if provided in kwargs
|
|
71
|
+
if "language" in kwargs:
|
|
72
|
+
request_data["language"] = kwargs["language"]
|
|
73
|
+
|
|
74
|
+
# Filter out None values if server requires it
|
|
75
|
+
request_data = {k: v for k, v in request_data.items() if v is not None}
|
|
76
|
+
|
|
77
|
+
headers = {'Content-Type': 'application/json'}
|
|
78
|
+
if self.service_key:
|
|
79
|
+
headers['Authorization'] = f'Bearer {self.service_key}'
|
|
80
|
+
|
|
81
|
+
response = requests.post(endpoint, json=request_data, headers=headers, verify=self.verify_ssl_certificate)
|
|
82
|
+
response.raise_for_status()
|
|
83
|
+
|
|
84
|
+
response_json = response.json()
|
|
85
|
+
transcribed_text = response_json.get("text")
|
|
86
|
+
|
|
87
|
+
if transcribed_text is None:
|
|
88
|
+
# Check for error message from server
|
|
89
|
+
error_msg = response_json.get("error", "Server did not return transcribed text.")
|
|
90
|
+
raise Exception(error_msg)
|
|
91
|
+
|
|
92
|
+
return transcribed_text
|
|
93
|
+
|
|
94
|
+
except FileNotFoundError as e:
|
|
95
|
+
raise e # Re-raise file not found
|
|
96
|
+
except requests.exceptions.RequestException as e:
|
|
97
|
+
trace_exception(e)
|
|
98
|
+
raise Exception(f"HTTP request failed: {e}") from e
|
|
99
|
+
except Exception as e:
|
|
100
|
+
trace_exception(e)
|
|
101
|
+
raise Exception(f"Audio transcription failed: {e}") from e
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def list_models(self, **kwargs) -> List[str]:
|
|
105
|
+
"""
|
|
106
|
+
Lists available STT models using an assumed LOLLMS /list_stt_models endpoint.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
**kwargs: Additional parameters (currently unused).
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
List[str]: List of STT model identifiers. Returns empty list on failure.
|
|
113
|
+
"""
|
|
114
|
+
endpoint = f"{self.host_address}/list_stt_models" # Assumed endpoint
|
|
115
|
+
headers = {'Content-Type': 'application/json'}
|
|
116
|
+
if self.service_key:
|
|
117
|
+
headers['Authorization'] = f'Bearer {self.service_key}'
|
|
118
|
+
|
|
119
|
+
try:
|
|
120
|
+
response = requests.get(endpoint, headers=headers, verify=self.verify_ssl_certificate)
|
|
121
|
+
response.raise_for_status()
|
|
122
|
+
models_data = response.json()
|
|
123
|
+
if "error" in models_data:
|
|
124
|
+
ASCIIColors.error(f"Error listing STT models from server: {models_data['error']}")
|
|
125
|
+
return [] # Fallback
|
|
126
|
+
return models_data.get("models", []) # Default if key missing
|
|
127
|
+
except requests.exceptions.RequestException as e:
|
|
128
|
+
ASCIIColors.error(f"Couldn't list STT models due to connection error: {e}")
|
|
129
|
+
trace_exception(e)
|
|
130
|
+
return [] # Fallback
|
|
131
|
+
except json.JSONDecodeError as e:
|
|
132
|
+
ASCIIColors.error(f"Couldn't parse STT models response from server: {e}")
|
|
133
|
+
trace_exception(e)
|
|
134
|
+
return [] # Fallback
|
|
135
|
+
except Exception as e:
|
|
136
|
+
ASCIIColors.error(f"An unexpected error occurred while listing STT models: {e}")
|
|
137
|
+
trace_exception(e)
|
|
138
|
+
return [] # Fallback
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# lollms_client/tti_bindings/lollms/__init__.py
|
|
2
|
+
import requests
|
|
3
|
+
import base64
|
|
4
|
+
import io
|
|
5
|
+
from PIL import Image
|
|
6
|
+
from lollms_client.lollms_tti_binding import LollmsTTIBinding
|
|
7
|
+
from typing import Optional, List, Dict, Any
|
|
8
|
+
from ascii_colors import trace_exception, ASCIIColors
|
|
9
|
+
import json # Added for potential error parsing
|
|
10
|
+
|
|
11
|
+
# Defines the binding name for the manager
|
|
12
|
+
BindingName = "LollmsTTIBinding_Impl"
|
|
13
|
+
|
|
14
|
+
class LollmsTTIBinding_Impl(LollmsTTIBinding):
|
|
15
|
+
"""Concrete implementation of the LollmsTTIBinding for the standard LOLLMS server."""
|
|
16
|
+
|
|
17
|
+
def __init__(self,
|
|
18
|
+
host_address: Optional[str] = "http://localhost:9600", # Default LOLLMS host
|
|
19
|
+
model_name: Optional[str] = None, # Default service name (server decides if None)
|
|
20
|
+
service_key: Optional[str] = None,
|
|
21
|
+
verify_ssl_certificate: bool = True):
|
|
22
|
+
"""
|
|
23
|
+
Initialize the LOLLMS TTI binding.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
host_address (Optional[str]): Host address for the LOLLMS service.
|
|
27
|
+
model_name (Optional[str]): Default service/model identifier (currently unused by LOLLMS TTI endpoints).
|
|
28
|
+
service_key (Optional[str]): Authentication key (used for client_id verification).
|
|
29
|
+
verify_ssl_certificate (bool): Whether to verify SSL certificates.
|
|
30
|
+
"""
|
|
31
|
+
super().__init__(host_address=host_address,
|
|
32
|
+
model_name=model_name, # model_name is not directly used by LOLLMS TTI API yet
|
|
33
|
+
service_key=service_key,
|
|
34
|
+
verify_ssl_certificate=verify_ssl_certificate)
|
|
35
|
+
# The 'service_key' here will act as the 'client_id' for TTI requests if provided.
|
|
36
|
+
# This assumes the client library user provides their LOLLMS client_id here.
|
|
37
|
+
self.client_id = service_key
|
|
38
|
+
|
|
39
|
+
def _get_client_id(self, **kwargs) -> str:
|
|
40
|
+
"""Helper to get client_id, prioritizing kwargs then instance default."""
|
|
41
|
+
client_id = kwargs.get("client_id", self.client_id)
|
|
42
|
+
if not client_id:
|
|
43
|
+
# Allowing anonymous access for generation, but other endpoints might fail
|
|
44
|
+
# raise ValueError("client_id is required for this TTI operation but was not provided.")
|
|
45
|
+
ASCIIColors.warning("client_id not provided for TTI operation. Some features might require it.")
|
|
46
|
+
return "lollms_client_user" # Default anonymous ID
|
|
47
|
+
return client_id
|
|
48
|
+
|
|
49
|
+
def generate_image(self,
|
|
50
|
+
prompt: str,
|
|
51
|
+
negative_prompt: Optional[str] = "",
|
|
52
|
+
width: int = 512,
|
|
53
|
+
height: int = 512,
|
|
54
|
+
**kwargs) -> bytes:
|
|
55
|
+
"""
|
|
56
|
+
Generates image data using the LOLLMS /generate_image endpoint.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
prompt (str): The positive text prompt.
|
|
60
|
+
negative_prompt (Optional[str]): The negative prompt.
|
|
61
|
+
width (int): Image width.
|
|
62
|
+
height (int): Image height.
|
|
63
|
+
**kwargs: Additional parameters (passed to server if needed, currently unused by endpoint).
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
bytes: The generated image data (JPEG format).
|
|
67
|
+
|
|
68
|
+
Raises:
|
|
69
|
+
Exception: If the request fails or image generation fails on the server.
|
|
70
|
+
"""
|
|
71
|
+
endpoint = f"{self.host_address}/generate_image"
|
|
72
|
+
request_data = {
|
|
73
|
+
"prompt": prompt,
|
|
74
|
+
"negative_prompt": negative_prompt,
|
|
75
|
+
"width": width,
|
|
76
|
+
"height": height
|
|
77
|
+
}
|
|
78
|
+
# Include extra kwargs if the server API might use them in the future
|
|
79
|
+
request_data.update(kwargs)
|
|
80
|
+
|
|
81
|
+
headers = {'Content-Type': 'application/json'}
|
|
82
|
+
# Note: /generate_image endpoint doesn't currently require client_id based on provided code
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
response = requests.post(endpoint, json=request_data, headers=headers, verify=self.verify_ssl_certificate)
|
|
86
|
+
response.raise_for_status()
|
|
87
|
+
|
|
88
|
+
response_json = response.json()
|
|
89
|
+
img_base64 = response_json.get("image")
|
|
90
|
+
|
|
91
|
+
if not img_base64:
|
|
92
|
+
raise Exception("Server did not return image data.")
|
|
93
|
+
|
|
94
|
+
# Decode the base64 string to bytes
|
|
95
|
+
img_bytes = base64.b64decode(img_base64)
|
|
96
|
+
return img_bytes
|
|
97
|
+
|
|
98
|
+
except requests.exceptions.RequestException as e:
|
|
99
|
+
trace_exception(e)
|
|
100
|
+
raise Exception(f"HTTP request failed: {e}") from e
|
|
101
|
+
except Exception as e:
|
|
102
|
+
trace_exception(e)
|
|
103
|
+
# Attempt to get error detail from response if possible
|
|
104
|
+
error_detail = "Unknown server error"
|
|
105
|
+
try:
|
|
106
|
+
error_detail = response.json().get("detail", error_detail)
|
|
107
|
+
except: pass
|
|
108
|
+
raise Exception(f"Image generation failed: {e} - Detail: {error_detail}") from e
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def list_services(self, **kwargs) -> List[Dict[str, str]]:
|
|
112
|
+
"""
|
|
113
|
+
Lists available TTI services using the LOLLMS /list_tti_services endpoint.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
**kwargs: Must include 'client_id' for server verification.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
List[Dict[str, str]]: List of service dictionaries.
|
|
120
|
+
|
|
121
|
+
Raises:
|
|
122
|
+
ValueError: If client_id is not provided.
|
|
123
|
+
Exception: If the request fails.
|
|
124
|
+
"""
|
|
125
|
+
endpoint = f"{self.host_address}/list_tti_services"
|
|
126
|
+
client_id = self._get_client_id(**kwargs) # Raises ValueError if missing
|
|
127
|
+
|
|
128
|
+
request_data = {"client_id": client_id}
|
|
129
|
+
headers = {'Content-Type': 'application/json'}
|
|
130
|
+
|
|
131
|
+
try:
|
|
132
|
+
response = requests.post(endpoint, json=request_data, headers=headers, verify=self.verify_ssl_certificate)
|
|
133
|
+
response.raise_for_status()
|
|
134
|
+
return response.json() # Returns the list directly
|
|
135
|
+
except requests.exceptions.RequestException as e:
|
|
136
|
+
trace_exception(e)
|
|
137
|
+
raise Exception(f"HTTP request failed: {e}") from e
|
|
138
|
+
except Exception as e:
|
|
139
|
+
trace_exception(e)
|
|
140
|
+
raise Exception(f"Failed to list TTI services: {e}") from e
|
|
141
|
+
|
|
142
|
+
def get_settings(self, **kwargs) -> Optional[Dict[str, Any]]:
|
|
143
|
+
"""
|
|
144
|
+
Retrieves TTI settings using the LOLLMS /get_active_tti_settings endpoint.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
**kwargs: Must include 'client_id' for server verification.
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
Optional[Dict[str, Any]]: Settings dictionary or empty dict if not available/failed.
|
|
151
|
+
|
|
152
|
+
Raises:
|
|
153
|
+
ValueError: If client_id is not provided.
|
|
154
|
+
Exception: If the request fails.
|
|
155
|
+
"""
|
|
156
|
+
endpoint = f"{self.host_address}/get_active_tti_settings"
|
|
157
|
+
client_id = self._get_client_id(**kwargs) # Raises ValueError if missing
|
|
158
|
+
|
|
159
|
+
request_data = {"client_id": client_id}
|
|
160
|
+
headers = {'Content-Type': 'application/json'}
|
|
161
|
+
|
|
162
|
+
try:
|
|
163
|
+
response = requests.post(endpoint, json=request_data, headers=headers, verify=self.verify_ssl_certificate)
|
|
164
|
+
response.raise_for_status()
|
|
165
|
+
settings = response.json()
|
|
166
|
+
# The endpoint returns the template directly if successful, or {} if no TTI/settings
|
|
167
|
+
return settings if isinstance(settings, list) else {} # Ensure correct format or empty
|
|
168
|
+
except requests.exceptions.RequestException as e:
|
|
169
|
+
trace_exception(e)
|
|
170
|
+
raise Exception(f"HTTP request failed: {e}") from e
|
|
171
|
+
except Exception as e:
|
|
172
|
+
trace_exception(e)
|
|
173
|
+
raise Exception(f"Failed to get TTI settings: {e}") from e
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def set_settings(self, settings: Dict[str, Any], **kwargs) -> bool:
|
|
177
|
+
"""
|
|
178
|
+
Applies TTI settings using the LOLLMS /set_active_tti_settings endpoint.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
settings (Dict[str, Any]): The new settings (matching server's expected format).
|
|
182
|
+
**kwargs: Must include 'client_id' for server verification.
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
bool: True if successful, False otherwise.
|
|
186
|
+
|
|
187
|
+
Raises:
|
|
188
|
+
ValueError: If client_id is not provided.
|
|
189
|
+
Exception: If the request fails.
|
|
190
|
+
"""
|
|
191
|
+
endpoint = f"{self.host_address}/set_active_tti_settings"
|
|
192
|
+
client_id = self._get_client_id(**kwargs) # Raises ValueError if missing
|
|
193
|
+
|
|
194
|
+
request_data = {
|
|
195
|
+
"client_id": client_id,
|
|
196
|
+
"settings": settings
|
|
197
|
+
}
|
|
198
|
+
headers = {'Content-Type': 'application/json'}
|
|
199
|
+
|
|
200
|
+
try:
|
|
201
|
+
response = requests.post(endpoint, json=request_data, headers=headers, verify=self.verify_ssl_certificate)
|
|
202
|
+
response.raise_for_status()
|
|
203
|
+
response_json = response.json()
|
|
204
|
+
return response_json.get("status", False)
|
|
205
|
+
except requests.exceptions.RequestException as e:
|
|
206
|
+
trace_exception(e)
|
|
207
|
+
raise Exception(f"HTTP request failed: {e}") from e
|
|
208
|
+
except Exception as e:
|
|
209
|
+
trace_exception(e)
|
|
210
|
+
raise Exception(f"Failed to set TTI settings: {e}") from e
|
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# lollms_client/ttm_bindings/lollms/__init__.py
|
|
2
|
+
import requests
|
|
3
|
+
from lollms_client.lollms_ttm_binding import LollmsTTMBinding
|
|
4
|
+
from typing import Optional, List
|
|
5
|
+
from ascii_colors import trace_exception, ASCIIColors
|
|
6
|
+
|
|
7
|
+
# Defines the binding name for the manager
|
|
8
|
+
BindingName = "LollmsTTMBinding_Impl"
|
|
9
|
+
|
|
10
|
+
class LollmsTTMBinding_Impl(LollmsTTMBinding):
|
|
11
|
+
"""Concrete implementation of the LollmsTTMBinding for the standard LOLLMS server (Placeholder)."""
|
|
12
|
+
|
|
13
|
+
def __init__(self,
|
|
14
|
+
host_address: Optional[str] = "http://localhost:9600", # Default LOLLMS host
|
|
15
|
+
model_name: Optional[str] = None, # Default model (server decides if None)
|
|
16
|
+
service_key: Optional[str] = None,
|
|
17
|
+
verify_ssl_certificate: bool = True):
|
|
18
|
+
"""
|
|
19
|
+
Initialize the LOLLMS TTM binding.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
host_address (Optional[str]): Host address for the LOLLMS service.
|
|
23
|
+
model_name (Optional[str]): Default TTM model identifier.
|
|
24
|
+
service_key (Optional[str]): Authentication key.
|
|
25
|
+
verify_ssl_certificate (bool): Whether to verify SSL certificates.
|
|
26
|
+
"""
|
|
27
|
+
super().__init__(host_address=host_address,
|
|
28
|
+
model_name=model_name,
|
|
29
|
+
service_key=service_key,
|
|
30
|
+
verify_ssl_certificate=verify_ssl_certificate)
|
|
31
|
+
ASCIIColors.warning("LOLLMS TTM binding is not yet fully implemented in the client.")
|
|
32
|
+
ASCIIColors.warning("Please ensure your LOLLMS server has a TTM service running.")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def generate_music(self, prompt: str, **kwargs) -> bytes:
|
|
36
|
+
"""
|
|
37
|
+
Generates music data using an assumed LOLLMS /generate_music endpoint. (Not Implemented)
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
prompt (str): The text prompt describing the desired music.
|
|
41
|
+
**kwargs: Additional parameters (e.g., duration, style).
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
bytes: Placeholder empty bytes.
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
NotImplementedError: This method is not yet implemented.
|
|
48
|
+
"""
|
|
49
|
+
# endpoint = f"{self.host_address}/generate_music" # Assumed endpoint
|
|
50
|
+
# request_data = {"prompt": prompt, **kwargs}
|
|
51
|
+
# headers = {'Content-Type': 'application/json'}
|
|
52
|
+
# ... make request ...
|
|
53
|
+
# return response.content # Assuming direct bytes response
|
|
54
|
+
raise NotImplementedError("LOLLMS TTM generate_music client binding is not implemented yet.")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def list_models(self, **kwargs) -> List[str]:
|
|
58
|
+
"""
|
|
59
|
+
Lists available TTM models using an assumed LOLLMS /list_ttm_models endpoint. (Not Implemented)
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
**kwargs: Additional parameters.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
List[str]: Placeholder empty list.
|
|
66
|
+
|
|
67
|
+
Raises:
|
|
68
|
+
NotImplementedError: This method is not yet implemented.
|
|
69
|
+
"""
|
|
70
|
+
# endpoint = f"{self.host_address}/list_ttm_models" # Assumed endpoint
|
|
71
|
+
# ... make request ...
|
|
72
|
+
# return response.json().get("models", [])
|
|
73
|
+
raise NotImplementedError("LOLLMS TTM list_models client binding is not implemented yet.")
|