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
|
@@ -1,96 +1,149 @@
|
|
|
1
1
|
# lollms_client/tti_bindings/gemini/__init__.py
|
|
2
2
|
import sys
|
|
3
3
|
from typing import Optional, List, Dict, Any, Union
|
|
4
|
+
import os
|
|
4
5
|
|
|
5
6
|
from lollms_client.lollms_tti_binding import LollmsTTIBinding
|
|
6
7
|
from ascii_colors import trace_exception, ASCIIColors
|
|
7
|
-
import
|
|
8
|
+
import math
|
|
8
9
|
|
|
10
|
+
# --- SDK & Dependency Management ---
|
|
9
11
|
try:
|
|
10
12
|
import pipmaster as pm
|
|
11
|
-
#
|
|
12
|
-
pm.ensure_packages(['google-cloud-aiplatform', 'Pillow'])
|
|
13
|
+
# Ensure both potential SDKs and Pillow are available
|
|
14
|
+
pm.ensure_packages(['google-cloud-aiplatform', 'google-generativeai', 'Pillow'])
|
|
15
|
+
except ImportError:
|
|
16
|
+
pass # pipmaster is optional
|
|
17
|
+
|
|
18
|
+
# Attempt to import Vertex AI (google-cloud-aiplatform)
|
|
19
|
+
try:
|
|
13
20
|
import vertexai
|
|
14
21
|
from vertexai.preview.vision_models import ImageGenerationModel
|
|
15
22
|
from google.api_core import exceptions as google_exceptions
|
|
16
|
-
|
|
17
|
-
except ImportError
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
VERTEX_AI_AVAILABLE = True
|
|
24
|
+
except ImportError:
|
|
25
|
+
VERTEX_AI_AVAILABLE = False
|
|
26
|
+
|
|
27
|
+
# Attempt to import Gemini API (google-generativeai)
|
|
28
|
+
try:
|
|
29
|
+
from google import genai
|
|
30
|
+
from google.genai import types as genai_types
|
|
31
|
+
GEMINI_API_AVAILABLE = True
|
|
32
|
+
except ImportError:
|
|
33
|
+
GEMINI_API_AVAILABLE = False
|
|
20
34
|
|
|
21
35
|
# Defines the binding name for the manager
|
|
22
36
|
BindingName = "GeminiTTIBinding_Impl"
|
|
23
37
|
|
|
24
|
-
# Known Imagen models
|
|
25
|
-
|
|
38
|
+
# Known Imagen models for each service
|
|
39
|
+
IMAGEN_VERTEX_MODELS = ["imagegeneration@006", "imagegeneration@005", "imagegeneration@002"]
|
|
40
|
+
IMAGEN_GEMINI_API_MODELS = ["imagen-3", "gemini-1.5-flash-preview-0514"] # Short names are often aliases
|
|
41
|
+
GEMINI_API_KEY_ENV_VAR = "GEMINI_API_KEY"
|
|
26
42
|
|
|
27
43
|
class GeminiTTIBinding_Impl(LollmsTTIBinding):
|
|
28
44
|
"""
|
|
29
|
-
Concrete implementation of LollmsTTIBinding for Google's Imagen models
|
|
45
|
+
Concrete implementation of LollmsTTIBinding for Google's Imagen models.
|
|
46
|
+
Supports both Vertex AI (project_id) and Gemini API (api_key) authentication.
|
|
30
47
|
"""
|
|
31
|
-
|
|
32
|
-
"project_id": None,
|
|
33
|
-
"location": "us-central1",
|
|
34
|
-
"model_name": IMAGEN_MODELS[0],
|
|
35
|
-
"seed": -1, # -1 for random
|
|
36
|
-
"guidance_scale": 7.5,
|
|
37
|
-
"number_of_images": 1
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
def __init__(self, config: Optional[Dict[str, Any]] = None, **kwargs):
|
|
48
|
+
def __init__(self, **kwargs):
|
|
41
49
|
"""
|
|
42
|
-
Initialize the Gemini (Vertex AI
|
|
50
|
+
Initialize the Gemini (Vertex AI / API) TTI binding.
|
|
43
51
|
|
|
44
52
|
Args:
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
**kwargs: Configuration parameters.
|
|
54
|
+
- auth_method (str): "vertex_ai" or "api_key". (Required)
|
|
55
|
+
- project_id (str): Google Cloud project ID (for vertex_ai).
|
|
56
|
+
- location (str): Google Cloud region (for vertex_ai).
|
|
57
|
+
- service_key (str): Gemini API Key (for api_key).
|
|
58
|
+
- model_name (str): The Imagen model to use.
|
|
59
|
+
- default_seed (int): Default seed for generation (-1 for random).
|
|
60
|
+
- default_guidance_scale (float): Default guidance scale (CFG).
|
|
47
61
|
"""
|
|
48
62
|
super().__init__(binding_name="gemini")
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
# Core settings
|
|
65
|
+
self.auth_method = kwargs.get("auth_method", "vertex_ai") # Default to vertex_ai for backward compatibility
|
|
66
|
+
|
|
67
|
+
# Vertex AI specific settings
|
|
68
|
+
self.project_id = kwargs.get("project_id")
|
|
69
|
+
self.location = kwargs.get("location", "us-central1")
|
|
70
|
+
|
|
71
|
+
# Gemini API specific settings
|
|
72
|
+
self.gemini_api_key = kwargs.get("service_key")
|
|
73
|
+
|
|
74
|
+
# Common settings
|
|
75
|
+
self.model_name = kwargs.get("model_name")
|
|
76
|
+
self.default_seed = int(kwargs.get("default_seed", -1))
|
|
77
|
+
self.default_guidance_scale = float(kwargs.get("default_guidance_scale", 7.5))
|
|
78
|
+
self.client_id = kwargs.get("client_id", "gemini_client_user")
|
|
56
79
|
|
|
57
|
-
|
|
58
|
-
self.
|
|
80
|
+
# The actual client/model instance
|
|
81
|
+
self.client: Optional[Any] = None
|
|
82
|
+
|
|
83
|
+
# --- Validation and Initialization ---
|
|
84
|
+
if self.auth_method == "vertex_ai":
|
|
85
|
+
if not VERTEX_AI_AVAILABLE:
|
|
86
|
+
raise ImportError("Vertex AI authentication selected, but 'google-cloud-aiplatform' is not installed.")
|
|
87
|
+
if not self.project_id:
|
|
88
|
+
raise ValueError("For 'vertex_ai' auth, a Google Cloud 'project_id' is required.")
|
|
89
|
+
if not self.model_name:
|
|
90
|
+
self.model_name = IMAGEN_VERTEX_MODELS[0]
|
|
91
|
+
elif self.auth_method == "api_key":
|
|
92
|
+
if not GEMINI_API_AVAILABLE:
|
|
93
|
+
raise ImportError("API Key authentication selected, but 'google-generativeai' is not installed.")
|
|
94
|
+
|
|
95
|
+
# Resolve API key from kwargs or environment variable
|
|
96
|
+
if not self.gemini_api_key:
|
|
97
|
+
ASCIIColors.info(f"API key not provided directly, checking environment variable '{GEMINI_API_KEY_ENV_VAR}'...")
|
|
98
|
+
self.gemini_api_key = os.environ.get(GEMINI_API_KEY_ENV_VAR)
|
|
99
|
+
|
|
100
|
+
if not self.gemini_api_key:
|
|
101
|
+
raise ValueError(f"For 'api_key' auth, a Gemini API Key is required. Provide it as 'service_key' or set the '{GEMINI_API_KEY_ENV_VAR}' environment variable.")
|
|
102
|
+
|
|
103
|
+
if not self.model_name:
|
|
104
|
+
self.model_name = IMAGEN_GEMINI_API_MODELS[0]
|
|
105
|
+
else:
|
|
106
|
+
raise ValueError(f"Invalid auth_method: '{self.auth_method}'. Must be 'vertex_ai' or 'api_key'.")
|
|
59
107
|
|
|
60
108
|
self._initialize_client()
|
|
61
109
|
|
|
62
110
|
def _initialize_client(self):
|
|
63
|
-
"""Initializes the
|
|
64
|
-
|
|
65
|
-
location = self.config.get("location")
|
|
66
|
-
model_name = self.config.get("model_name")
|
|
67
|
-
|
|
68
|
-
if not project_id:
|
|
69
|
-
raise ValueError("Google Cloud 'project_id' is required for the Gemini (Vertex AI) binding.")
|
|
70
|
-
|
|
71
|
-
ASCIIColors.info("Initializing Vertex AI client...")
|
|
111
|
+
"""Initializes the appropriate client based on the selected auth_method."""
|
|
112
|
+
ASCIIColors.info(f"Initializing Google client with auth method: '{self.auth_method}'...")
|
|
72
113
|
try:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
114
|
+
if self.auth_method == "vertex_ai":
|
|
115
|
+
vertexai.init(project=self.project_id, location=self.location)
|
|
116
|
+
self.client = ImageGenerationModel.from_pretrained(self.model_name)
|
|
117
|
+
ASCIIColors.green(f"Vertex AI initialized successfully. Project: '{self.project_id}', Model: '{self.model_name}'")
|
|
118
|
+
elif self.auth_method == "api_key":
|
|
119
|
+
genai.configure(api_key=self.gemini_api_key)
|
|
120
|
+
# For the genai SDK, the "client" is the configured module itself,
|
|
121
|
+
# and we specify the model per-call. Let's store the genai module.
|
|
122
|
+
self.client = genai
|
|
123
|
+
ASCIIColors.green(f"Gemini API configured successfully. Model to be used: '{self.model_name}'")
|
|
76
124
|
except google_exceptions.PermissionDenied as e:
|
|
77
125
|
trace_exception(e)
|
|
78
126
|
raise Exception(
|
|
79
|
-
"Authentication failed.
|
|
80
|
-
"and that the Vertex AI API is enabled for your project."
|
|
127
|
+
"Authentication failed. For Vertex AI, run 'gcloud auth application-default login'. For API Key, check if the key is valid and has permissions."
|
|
81
128
|
) from e
|
|
82
129
|
except Exception as e:
|
|
83
130
|
trace_exception(e)
|
|
84
|
-
raise Exception(f"Failed to initialize
|
|
131
|
+
raise Exception(f"Failed to initialize Google client: {e}") from e
|
|
132
|
+
|
|
133
|
+
def _validate_dimensions_vertex(self, width: int, height: int) -> None:
|
|
134
|
+
"""Validates image dimensions against Vertex AI Imagen constraints."""
|
|
135
|
+
if not (256 <= width <= 1536 and width % 8 == 0):
|
|
136
|
+
raise ValueError(f"Invalid width for Vertex AI: {width}. Must be 256-1536 and a multiple of 8.")
|
|
137
|
+
if not (256 <= height <= 1536 and height % 8 == 0):
|
|
138
|
+
raise ValueError(f"Invalid height for Vertex AI: {height}. Must be 256-1536 and a multiple of 8.")
|
|
85
139
|
|
|
86
|
-
def
|
|
87
|
-
"""
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
raise ValueError(f"Invalid dimensions: {width}x{height}. The total number of pixels cannot exceed 1536*1536.")
|
|
140
|
+
def _get_aspect_ratio_for_api(self, width: int, height: int) -> str:
|
|
141
|
+
"""Finds the closest supported aspect ratio string for the Gemini API."""
|
|
142
|
+
ratios = {"1:1": 1.0, "16:9": 16/9, "9:16": 9/16, "4:3": 4/3, "3:4": 3/4}
|
|
143
|
+
target_ratio = width / height
|
|
144
|
+
closest_ratio_name = min(ratios, key=lambda r: abs(ratios[r] - target_ratio))
|
|
145
|
+
ASCIIColors.info(f"Converted {width}x{height} to closest aspect ratio: '{closest_ratio_name}' for Gemini API.")
|
|
146
|
+
return closest_ratio_name
|
|
94
147
|
|
|
95
148
|
def generate_image(self,
|
|
96
149
|
prompt: str,
|
|
@@ -99,117 +152,169 @@ class GeminiTTIBinding_Impl(LollmsTTIBinding):
|
|
|
99
152
|
height: int = 1024,
|
|
100
153
|
**kwargs) -> bytes:
|
|
101
154
|
"""
|
|
102
|
-
Generates image data using the
|
|
103
|
-
|
|
104
|
-
Args:
|
|
105
|
-
prompt (str): The positive text prompt.
|
|
106
|
-
negative_prompt (Optional[str]): The negative prompt.
|
|
107
|
-
width (int): Image width. Must be 256-1536 and a multiple of 64.
|
|
108
|
-
height (int): Image height. Must be 256-1536 and a multiple of 64.
|
|
109
|
-
**kwargs: Additional parameters:
|
|
110
|
-
- seed (int)
|
|
111
|
-
- guidance_scale (float)
|
|
112
|
-
Returns:
|
|
113
|
-
bytes: The generated image data (PNG format).
|
|
114
|
-
Raises:
|
|
115
|
-
Exception: If the request fails or image generation fails.
|
|
155
|
+
Generates image data using the configured Google Imagen model.
|
|
116
156
|
"""
|
|
117
|
-
if not self.
|
|
118
|
-
raise RuntimeError("
|
|
119
|
-
|
|
120
|
-
self._validate_dimensions(width, height)
|
|
157
|
+
if not self.client:
|
|
158
|
+
raise RuntimeError("Google client is not initialized. Cannot generate image.")
|
|
121
159
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
# Use -1 for random seed, otherwise pass the integer value.
|
|
160
|
+
# Use overrides from kwargs, otherwise instance defaults
|
|
161
|
+
seed = kwargs.get("seed", self.default_seed)
|
|
162
|
+
guidance_scale = kwargs.get("guidance_scale", self.default_guidance_scale)
|
|
126
163
|
gen_seed = seed if seed != -1 else None
|
|
127
164
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
"
|
|
131
|
-
"number_of_images": 1, # This binding returns one image
|
|
132
|
-
"width": width,
|
|
133
|
-
"height": height,
|
|
134
|
-
"guidance_scale": guidance_scale,
|
|
135
|
-
}
|
|
136
|
-
if gen_seed is not None:
|
|
137
|
-
gen_params["seed"] = gen_seed
|
|
165
|
+
final_prompt = prompt
|
|
166
|
+
if negative_prompt:
|
|
167
|
+
final_prompt = f"{prompt}. Do not include: {negative_prompt}."
|
|
138
168
|
|
|
139
|
-
ASCIIColors.info(f"Generating image with prompt: '{
|
|
140
|
-
ASCIIColors.debug(f"Imagen generation parameters: {gen_params}")
|
|
169
|
+
ASCIIColors.info(f"Generating image with prompt: '{final_prompt[:100]}...'")
|
|
141
170
|
|
|
142
171
|
try:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
172
|
+
if self.auth_method == "vertex_ai":
|
|
173
|
+
self._validate_dimensions_vertex(width, height)
|
|
174
|
+
gen_params = {
|
|
175
|
+
"prompt": final_prompt,
|
|
176
|
+
"number_of_images": 1,
|
|
177
|
+
"width": width,
|
|
178
|
+
"height": height,
|
|
179
|
+
"guidance_scale": guidance_scale,
|
|
180
|
+
}
|
|
181
|
+
if gen_seed is not None:
|
|
182
|
+
gen_params["seed"] = gen_seed
|
|
183
|
+
|
|
184
|
+
ASCIIColors.debug(f"Vertex AI generation parameters: {gen_params}")
|
|
185
|
+
response = self.client.generate_images(**gen_params)
|
|
186
|
+
|
|
187
|
+
if not response.images:
|
|
188
|
+
raise Exception("Image generation resulted in no images (Vertex AI). Check safety filters.")
|
|
189
|
+
|
|
190
|
+
return response.images[0]._image_bytes
|
|
147
191
|
|
|
148
|
-
|
|
149
|
-
|
|
192
|
+
elif self.auth_method == "api_key":
|
|
193
|
+
aspect_ratio = self._get_aspect_ratio_for_api(width, height)
|
|
194
|
+
gen_params = {
|
|
195
|
+
"model": self.model_name,
|
|
196
|
+
"prompt": final_prompt,
|
|
197
|
+
"number_of_images": 1,
|
|
198
|
+
"aspect_ratio": aspect_ratio
|
|
199
|
+
# Note: seed and guidance_scale are not standard in this simpler API call
|
|
200
|
+
}
|
|
201
|
+
ASCIIColors.debug(f"Gemini API generation parameters: {gen_params}")
|
|
202
|
+
response = self.client.generate_image(**gen_params)
|
|
150
203
|
|
|
151
|
-
|
|
204
|
+
if not response.images:
|
|
205
|
+
raise Exception("Image generation resulted in no images (Gemini API). Check safety filters.")
|
|
206
|
+
|
|
207
|
+
return response.images[0].image_bytes
|
|
208
|
+
|
|
209
|
+
except (google_exceptions.InvalidArgument, AttributeError) as e:
|
|
152
210
|
trace_exception(e)
|
|
153
|
-
raise ValueError(f"Invalid argument sent to
|
|
211
|
+
raise ValueError(f"Invalid argument sent to Google API: {e}") from e
|
|
154
212
|
except google_exceptions.GoogleAPICallError as e:
|
|
155
213
|
trace_exception(e)
|
|
156
|
-
raise Exception(f"A Google API call error occurred: {e
|
|
214
|
+
raise Exception(f"A Google API call error occurred: {e}") from e
|
|
157
215
|
except Exception as e:
|
|
158
216
|
trace_exception(e)
|
|
159
217
|
raise Exception(f"Imagen image generation failed: {e}") from e
|
|
160
218
|
|
|
161
219
|
def list_services(self, **kwargs) -> List[Dict[str, str]]:
|
|
162
|
-
"""
|
|
163
|
-
|
|
164
|
-
"""
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
"
|
|
169
|
-
"
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return services
|
|
220
|
+
"""Lists available Imagen models for the current auth method."""
|
|
221
|
+
models = IMAGEN_VERTEX_MODELS if self.auth_method == "vertex_ai" else IMAGEN_GEMINI_API_MODELS
|
|
222
|
+
service_name = "Vertex AI" if self.auth_method == "vertex_ai" else "Gemini API"
|
|
223
|
+
return [
|
|
224
|
+
{
|
|
225
|
+
"name": name,
|
|
226
|
+
"caption": f"Google Imagen ({name}) via {service_name}",
|
|
227
|
+
"help": "High-quality text-to-image model from Google."
|
|
228
|
+
} for name in models
|
|
229
|
+
]
|
|
173
230
|
|
|
174
231
|
def get_settings(self, **kwargs) -> List[Dict[str, Any]]:
|
|
175
|
-
"""
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return [
|
|
179
|
-
{"name": "project_id", "type": "str", "value": self.config["project_id"], "description": "Your Google Cloud project ID."},
|
|
180
|
-
{"name": "location", "type": "str", "value": self.config["location"], "description": "Google Cloud region for the project (e.g., 'us-central1')."},
|
|
181
|
-
{"name": "model_name", "type": "str", "value": self.config["model_name"], "description": "The Imagen model version to use.", "options": IMAGEN_MODELS},
|
|
182
|
-
{"name": "seed", "type": "int", "value": self.config["seed"], "description": "Default seed for generation (-1 for random)."},
|
|
183
|
-
{"name": "guidance_scale", "type": "float", "value": self.config["guidance_scale"], "description": "Default guidance scale (CFG). Higher values follow the prompt more strictly."},
|
|
232
|
+
"""Retrieves the current configurable settings for the binding."""
|
|
233
|
+
settings = [
|
|
234
|
+
{"name": "auth_method", "type": "str", "value": self.auth_method, "description": "Authentication method to use.", "options": ["vertex_ai", "api_key"], "category": "Authentication"},
|
|
184
235
|
]
|
|
236
|
+
if self.auth_method == "vertex_ai":
|
|
237
|
+
settings.extend([
|
|
238
|
+
{"name": "project_id", "type": "str", "value": self.project_id, "description": "Your Google Cloud project ID.", "category": "Authentication"},
|
|
239
|
+
{"name": "location", "type": "str", "value": self.location, "description": "Google Cloud region (e.g., 'us-central1').", "category": "Authentication"},
|
|
240
|
+
{"name": "model_name", "type": "str", "value": self.model_name, "description": "Default Imagen model for generation.", "options": IMAGEN_VERTEX_MODELS, "category": "Model Configuration"},
|
|
241
|
+
])
|
|
242
|
+
elif self.auth_method == "api_key":
|
|
243
|
+
settings.extend([
|
|
244
|
+
{"name": "api_key_status", "type": "str", "value": "Set" if self.gemini_api_key else "Not Set", "description": f"Gemini API Key status (set at initialization via service_key or '{GEMINI_API_KEY_ENV_VAR}').", "category": "Authentication", "read_only": True},
|
|
245
|
+
{"name": "model_name", "type": "str", "value": self.model_name, "description": "Default Imagen model for generation.", "options": IMAGEN_GEMINI_API_MODELS, "category": "Model Configuration"},
|
|
246
|
+
])
|
|
247
|
+
|
|
248
|
+
settings.extend([
|
|
249
|
+
{"name": "default_seed", "type": "int", "value": self.default_seed, "description": "Default seed (-1 for random).", "category": "Image Generation Defaults"},
|
|
250
|
+
{"name": "default_guidance_scale", "type": "float", "value": self.default_guidance_scale, "description": "Default guidance scale (CFG). (Vertex AI only)", "category": "Image Generation Defaults"},
|
|
251
|
+
])
|
|
252
|
+
return settings
|
|
185
253
|
|
|
186
254
|
def set_settings(self, settings: Union[Dict[str, Any], List[Dict[str, Any]]], **kwargs) -> bool:
|
|
187
|
-
"""
|
|
188
|
-
|
|
189
|
-
"""
|
|
190
|
-
if isinstance(settings, list):
|
|
191
|
-
parsed_settings = {item["name"]: item["value"] for item in settings if "name" in item and "value" in item}
|
|
192
|
-
elif isinstance(settings, dict):
|
|
193
|
-
parsed_settings = settings
|
|
194
|
-
else:
|
|
195
|
-
ASCIIColors.error("Invalid settings format. Expected a dictionary or list of dictionaries.")
|
|
196
|
-
return False
|
|
255
|
+
"""Applies new settings. Re-initializes the client if core settings change."""
|
|
256
|
+
applied_some_settings = False
|
|
257
|
+
settings_dict = {item["name"]: item["value"] for item in settings} if isinstance(settings, list) else settings
|
|
197
258
|
|
|
198
259
|
needs_reinit = False
|
|
199
|
-
for key, value in parsed_settings.items():
|
|
200
|
-
if key in self.config and self.config[key] != value:
|
|
201
|
-
self.config[key] = value
|
|
202
|
-
ASCIIColors.info(f"Setting '{key}' changed to: {value}")
|
|
203
|
-
if key in ["project_id", "location", "model_name"]:
|
|
204
|
-
needs_reinit = True
|
|
205
260
|
|
|
261
|
+
# Phase 1: Check for auth_method or core credential changes
|
|
262
|
+
if "auth_method" in settings_dict and self.auth_method != settings_dict["auth_method"]:
|
|
263
|
+
self.auth_method = settings_dict["auth_method"]
|
|
264
|
+
ASCIIColors.info(f"Authentication method changed to: {self.auth_method}")
|
|
265
|
+
# Reset model to a valid default for the new method
|
|
266
|
+
if self.auth_method == "vertex_ai":
|
|
267
|
+
self.model_name = IMAGEN_VERTEX_MODELS[0]
|
|
268
|
+
else:
|
|
269
|
+
self.model_name = IMAGEN_GEMINI_API_MODELS[0]
|
|
270
|
+
ASCIIColors.info(f"Model name reset to default for new auth method: {self.model_name}")
|
|
271
|
+
needs_reinit = True
|
|
272
|
+
applied_some_settings = True
|
|
273
|
+
|
|
274
|
+
if self.auth_method == "vertex_ai":
|
|
275
|
+
if "project_id" in settings_dict and self.project_id != settings_dict["project_id"]:
|
|
276
|
+
self.project_id = settings_dict["project_id"]
|
|
277
|
+
needs_reinit = True; applied_some_settings = True
|
|
278
|
+
if "location" in settings_dict and self.location != settings_dict["location"]:
|
|
279
|
+
self.location = settings_dict["location"]
|
|
280
|
+
needs_reinit = True; applied_some_settings = True
|
|
281
|
+
# API key is not settable after init, so we don't check for it here.
|
|
282
|
+
|
|
283
|
+
# Phase 2: Apply other settings
|
|
284
|
+
current_models = IMAGEN_VERTEX_MODELS if self.auth_method == "vertex_ai" else IMAGEN_GEMINI_API_MODELS
|
|
285
|
+
if "model_name" in settings_dict:
|
|
286
|
+
new_model = settings_dict["model_name"]
|
|
287
|
+
if new_model not in current_models:
|
|
288
|
+
ASCIIColors.warning(f"Invalid model '{new_model}' for auth method '{self.auth_method}'. Keeping '{self.model_name}'.")
|
|
289
|
+
elif self.model_name != new_model:
|
|
290
|
+
self.model_name = new_model
|
|
291
|
+
needs_reinit = True; applied_some_settings = True
|
|
292
|
+
|
|
293
|
+
if "default_seed" in settings_dict and self.default_seed != int(settings_dict["default_seed"]):
|
|
294
|
+
self.default_seed = int(settings_dict["default_seed"])
|
|
295
|
+
applied_some_settings = True
|
|
296
|
+
if "default_guidance_scale" in settings_dict and self.default_guidance_scale != float(settings_dict["default_guidance_scale"]):
|
|
297
|
+
self.default_guidance_scale = float(settings_dict["default_guidance_scale"])
|
|
298
|
+
applied_some_settings = True
|
|
299
|
+
|
|
300
|
+
# Phase 3: Re-initialize if needed
|
|
206
301
|
if needs_reinit:
|
|
207
302
|
try:
|
|
208
303
|
self._initialize_client()
|
|
209
|
-
ASCIIColors.green("Vertex AI client re-initialized successfully with new settings.")
|
|
210
304
|
except Exception as e:
|
|
211
305
|
ASCIIColors.error(f"Failed to re-initialize client with new settings: {e}")
|
|
212
|
-
# Optionally, revert to old config here to maintain a working state
|
|
213
306
|
return False
|
|
214
307
|
|
|
215
|
-
return
|
|
308
|
+
return applied_some_settings
|
|
309
|
+
|
|
310
|
+
def listModels(self) -> list:
|
|
311
|
+
"""Lists available Imagen models in a standardized format."""
|
|
312
|
+
models = IMAGEN_VERTEX_MODELS if self.auth_method == "vertex_ai" else IMAGEN_GEMINI_API_MODELS
|
|
313
|
+
return [
|
|
314
|
+
{
|
|
315
|
+
'model_name': name,
|
|
316
|
+
'display_name': f"Imagen ({name})",
|
|
317
|
+
'description': f"Google's Imagen model, version {name}",
|
|
318
|
+
'owned_by': 'Google'
|
|
319
|
+
} for name in models
|
|
320
|
+
]
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
lollms_client/__init__.py,sha256=
|
|
1
|
+
lollms_client/__init__.py,sha256=GeDlYB0SLi4cbO3qk5kj3P84Z_9oPXXSGC7JLDWnTB0,1146
|
|
2
2
|
lollms_client/lollms_config.py,sha256=goEseDwDxYJf3WkYJ4IrLXwg3Tfw73CXV2Avg45M_hE,21876
|
|
3
|
-
lollms_client/lollms_core.py,sha256=
|
|
3
|
+
lollms_client/lollms_core.py,sha256=zqaxEJJDXiwpDd3E-PFDLJOnmG1d9cOiL_CrYRUa7Z0,167361
|
|
4
4
|
lollms_client/lollms_discussion.py,sha256=wkadV6qiegxOzukMVn5vukdeJivnlyygSzZBkzOi9Gc,106714
|
|
5
5
|
lollms_client/lollms_js_analyzer.py,sha256=01zUvuO2F_lnUe_0NLxe1MF5aHE1hO8RZi48mNPv-aw,8361
|
|
6
|
-
lollms_client/lollms_llm_binding.py,sha256=
|
|
6
|
+
lollms_client/lollms_llm_binding.py,sha256=5-Vknm0YILPd6ZiwZynsXMfns__Yd_1tDDc2fciRiiA,25020
|
|
7
7
|
lollms_client/lollms_mcp_binding.py,sha256=psb27A23VFWDfZsR2WUbQXQxiZDW5yfOak6ZtbMfszI,10222
|
|
8
8
|
lollms_client/lollms_mcp_security.py,sha256=FhVTDhSBjksGEZnopVnjFmEF5dv7D8bBTqoaj4BiF0E,3562
|
|
9
9
|
lollms_client/lollms_personality.py,sha256=O-9nqZhazcITOkxjT24ENTxTmIoZLgqIsQ9WtWs0Id0,8719
|
|
10
10
|
lollms_client/lollms_python_analyzer.py,sha256=7gf1fdYgXCOkPUkBAPNmr6S-66hMH4_KonOMsADASxc,10246
|
|
11
11
|
lollms_client/lollms_stt_binding.py,sha256=jAUhLouEhh2hmm1bK76ianfw_6B59EHfY3FmLv6DU-g,5111
|
|
12
|
-
lollms_client/lollms_tti_binding.py,sha256=
|
|
12
|
+
lollms_client/lollms_tti_binding.py,sha256=zsKA8K4E54n_60wKjRIwLxEetKAI_IAggQUzkpip5YE,10406
|
|
13
13
|
lollms_client/lollms_ttm_binding.py,sha256=FjVVSNXOZXK1qvcKEfxdiX6l2b4XdGOSNnZ0utAsbDg,4167
|
|
14
14
|
lollms_client/lollms_tts_binding.py,sha256=5cJYECj8PYLJAyB6SEH7_fhHYK3Om-Y3arkygCnZ24o,4342
|
|
15
15
|
lollms_client/lollms_ttv_binding.py,sha256=KkTaHLBhEEdt4sSVBlbwr5i_g_TlhcrwrT-7DjOsjWQ,4131
|
|
@@ -27,7 +27,7 @@ lollms_client/llm_bindings/llamacpp/__init__.py,sha256=4CbNYpfquVEgfsxuLsxQta_dZ
|
|
|
27
27
|
lollms_client/llm_bindings/lollms/__init__.py,sha256=a4gNH4axiDgsri8NGAcq0OitgYdnzBDLNkzUMhkFArA,24781
|
|
28
28
|
lollms_client/llm_bindings/lollms_webui/__init__.py,sha256=iuDfhZZoLC-PDEPLHrcjk5-962S5c7OeCI7PMdJxI_A,17753
|
|
29
29
|
lollms_client/llm_bindings/mistral/__init__.py,sha256=cddz9xIj8NRFLKHe2JMxzstpUrNIu5s9juci3mhiHfo,14133
|
|
30
|
-
lollms_client/llm_bindings/ollama/__init__.py,sha256=
|
|
30
|
+
lollms_client/llm_bindings/ollama/__init__.py,sha256=3Jyb9Yyp6lcz52HKF8nEiB4s3ChKBCjs7I27ohNOT4A,41216
|
|
31
31
|
lollms_client/llm_bindings/open_router/__init__.py,sha256=cAFWtCWJx0WjIe1w2JReCf6WlAZjrXYA4jZ8l3zqxMs,14915
|
|
32
32
|
lollms_client/llm_bindings/openai/__init__.py,sha256=J8v7XU9TrvXJd1ffwhYkya5YeXxWnNiFuNBAwRfoHDk,26066
|
|
33
33
|
lollms_client/llm_bindings/openllm/__init__.py,sha256=RC9dVeopslS-zXTsSJ7VC4iVsKgZCBwfmccmr_LCHA0,29971
|
|
@@ -47,9 +47,9 @@ lollms_client/stt_bindings/lollms/__init__.py,sha256=9Vmn1sQQZKLGLe7nZnc-0LnNeSY
|
|
|
47
47
|
lollms_client/stt_bindings/whisper/__init__.py,sha256=1Ej67GdRKBy1bba14jMaYDYHiZkxJASkWm5eF07ztDQ,15363
|
|
48
48
|
lollms_client/stt_bindings/whispercpp/__init__.py,sha256=xSAQRjAhljak3vWCpkP0Vmdb6WmwTzPjXyaIB85KLGU,21439
|
|
49
49
|
lollms_client/tti_bindings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
50
|
-
lollms_client/tti_bindings/dalle/__init__.py,sha256=
|
|
51
|
-
lollms_client/tti_bindings/diffusers/__init__.py,sha256=
|
|
52
|
-
lollms_client/tti_bindings/gemini/__init__.py,sha256=
|
|
50
|
+
lollms_client/tti_bindings/dalle/__init__.py,sha256=1nE36XamKEJOMpm6QUow8OyM1KdpejCLM0KUSXlcePo,24135
|
|
51
|
+
lollms_client/tti_bindings/diffusers/__init__.py,sha256=oQzvV0MSbLUEqWrercgB_npKJXzpylXqbqSP1E18its,30296
|
|
52
|
+
lollms_client/tti_bindings/gemini/__init__.py,sha256=f9fPuqnrBZ1Z-obcoP6EVvbEXNbNCSg21cd5efLCk8U,16707
|
|
53
53
|
lollms_client/tti_bindings/lollms/__init__.py,sha256=5Tnsn4b17djvieQkcjtIDBm3qf0pg5ZWWov-4_2wmo0,8762
|
|
54
54
|
lollms_client/ttm_bindings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
55
55
|
lollms_client/ttm_bindings/audiocraft/__init__.py,sha256=a0k6wTrHth6GaVOiNnVboeFY3oKVvCQPbQlqO38XEyc,14328
|
|
@@ -62,8 +62,8 @@ lollms_client/tts_bindings/piper_tts/__init__.py,sha256=0IEWG4zH3_sOkSb9WbZzkeV5
|
|
|
62
62
|
lollms_client/tts_bindings/xtts/__init__.py,sha256=FgcdUH06X6ZR806WQe5ixaYx0QoxtAcOgYo87a2qxYc,18266
|
|
63
63
|
lollms_client/ttv_bindings/__init__.py,sha256=UZ8o2izQOJLQgtZ1D1cXoNST7rzqW22rL2Vufc7ddRc,3141
|
|
64
64
|
lollms_client/ttv_bindings/lollms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
65
|
-
lollms_client-1.
|
|
66
|
-
lollms_client-1.
|
|
67
|
-
lollms_client-1.
|
|
68
|
-
lollms_client-1.
|
|
69
|
-
lollms_client-1.
|
|
65
|
+
lollms_client-1.1.1.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
66
|
+
lollms_client-1.1.1.dist-info/METADATA,sha256=yIpolI5PhLK1ETh8MVA1JKk1itCOUrrJYvErDa07E9c,58549
|
|
67
|
+
lollms_client-1.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
68
|
+
lollms_client-1.1.1.dist-info/top_level.txt,sha256=Bk_kz-ri6Arwsk7YG-T5VsRorV66uVhcHGvb_g2WqgE,14
|
|
69
|
+
lollms_client-1.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|