lfx-nightly 0.2.0.dev41__py3-none-any.whl → 0.2.1.dev7__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.
- lfx/_assets/component_index.json +1 -1
- lfx/base/agents/agent.py +1 -1
- lfx/base/agents/altk_tool_wrappers.py +1 -1
- lfx/base/agents/utils.py +4 -0
- lfx/base/composio/composio_base.py +78 -41
- lfx/base/data/cloud_storage_utils.py +156 -0
- lfx/base/data/docling_utils.py +130 -55
- lfx/base/datastax/astradb_base.py +75 -64
- lfx/base/embeddings/embeddings_class.py +113 -0
- lfx/base/models/__init__.py +11 -1
- lfx/base/models/google_generative_ai_constants.py +33 -9
- lfx/base/models/model_metadata.py +6 -0
- lfx/base/models/ollama_constants.py +196 -30
- lfx/base/models/openai_constants.py +37 -10
- lfx/base/models/unified_models.py +1123 -0
- lfx/base/models/watsonx_constants.py +36 -0
- lfx/base/tools/component_tool.py +2 -9
- lfx/cli/commands.py +3 -0
- lfx/cli/run.py +65 -409
- lfx/cli/script_loader.py +13 -3
- lfx/components/__init__.py +0 -3
- lfx/components/composio/github_composio.py +1 -1
- lfx/components/cuga/cuga_agent.py +39 -27
- lfx/components/data_source/api_request.py +4 -2
- lfx/components/docling/__init__.py +45 -11
- lfx/components/docling/docling_inline.py +39 -49
- lfx/components/elastic/opensearch_multimodal.py +1733 -0
- lfx/components/files_and_knowledge/file.py +384 -36
- lfx/components/files_and_knowledge/ingestion.py +8 -0
- lfx/components/files_and_knowledge/retrieval.py +10 -0
- lfx/components/files_and_knowledge/save_file.py +91 -88
- lfx/components/langchain_utilities/tool_calling.py +14 -6
- lfx/components/llm_operations/batch_run.py +64 -18
- lfx/components/llm_operations/lambda_filter.py +33 -6
- lfx/components/llm_operations/llm_conditional_router.py +39 -7
- lfx/components/llm_operations/structured_output.py +38 -12
- lfx/components/models/__init__.py +16 -74
- lfx/components/models_and_agents/agent.py +51 -203
- lfx/components/models_and_agents/embedding_model.py +171 -255
- lfx/components/models_and_agents/language_model.py +54 -318
- lfx/components/models_and_agents/mcp_component.py +58 -9
- lfx/components/ollama/ollama_embeddings.py +2 -1
- lfx/components/openai/openai_chat_model.py +1 -1
- lfx/components/vllm/__init__.py +37 -0
- lfx/components/vllm/vllm.py +141 -0
- lfx/components/vllm/vllm_embeddings.py +110 -0
- lfx/custom/custom_component/custom_component.py +8 -6
- lfx/graph/graph/base.py +4 -1
- lfx/graph/utils.py +64 -18
- lfx/graph/vertex/base.py +4 -1
- lfx/inputs/__init__.py +2 -0
- lfx/inputs/input_mixin.py +54 -0
- lfx/inputs/inputs.py +115 -0
- lfx/interface/initialize/loading.py +42 -12
- lfx/io/__init__.py +2 -0
- lfx/run/__init__.py +5 -0
- lfx/run/base.py +494 -0
- lfx/schema/data.py +1 -1
- lfx/schema/image.py +26 -7
- lfx/schema/message.py +19 -3
- lfx/services/mcp_composer/service.py +7 -1
- lfx/services/settings/base.py +7 -1
- lfx/services/settings/constants.py +2 -0
- lfx/services/storage/local.py +13 -8
- lfx/utils/constants.py +1 -0
- lfx/utils/validate_cloud.py +14 -3
- {lfx_nightly-0.2.0.dev41.dist-info → lfx_nightly-0.2.1.dev7.dist-info}/METADATA +5 -2
- {lfx_nightly-0.2.0.dev41.dist-info → lfx_nightly-0.2.1.dev7.dist-info}/RECORD +70 -61
- {lfx_nightly-0.2.0.dev41.dist-info → lfx_nightly-0.2.1.dev7.dist-info}/WHEEL +0 -0
- {lfx_nightly-0.2.0.dev41.dist-info → lfx_nightly-0.2.1.dev7.dist-info}/entry_points.txt +0 -0
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
from typing import Any
|
|
2
2
|
|
|
3
|
-
import requests
|
|
4
|
-
from ibm_watsonx_ai.metanames import EmbedTextParamsMetaNames
|
|
5
|
-
from langchain_openai import OpenAIEmbeddings
|
|
6
|
-
|
|
7
3
|
from lfx.base.embeddings.model import LCEmbeddingsModel
|
|
8
|
-
from lfx.base.models.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
from lfx.base.models.unified_models import (
|
|
5
|
+
get_api_key_for_provider,
|
|
6
|
+
get_embedding_classes,
|
|
7
|
+
get_embedding_model_options,
|
|
8
|
+
update_model_options_in_build_config,
|
|
13
9
|
)
|
|
10
|
+
from lfx.base.models.watsonx_constants import IBM_WATSONX_URLS
|
|
14
11
|
from lfx.field_typing import Embeddings
|
|
15
12
|
from lfx.io import (
|
|
16
13
|
BoolInput,
|
|
@@ -19,19 +16,9 @@ from lfx.io import (
|
|
|
19
16
|
FloatInput,
|
|
20
17
|
IntInput,
|
|
21
18
|
MessageTextInput,
|
|
19
|
+
ModelInput,
|
|
22
20
|
SecretStrInput,
|
|
23
21
|
)
|
|
24
|
-
from lfx.log.logger import logger
|
|
25
|
-
from lfx.schema.dotdict import dotdict
|
|
26
|
-
from lfx.utils.util import transform_localhost_url
|
|
27
|
-
|
|
28
|
-
# Ollama API constants
|
|
29
|
-
HTTP_STATUS_OK = 200
|
|
30
|
-
JSON_MODELS_KEY = "models"
|
|
31
|
-
JSON_NAME_KEY = "name"
|
|
32
|
-
JSON_CAPABILITIES_KEY = "capabilities"
|
|
33
|
-
DESIRED_CAPABILITY = "embedding"
|
|
34
|
-
DEFAULT_OLLAMA_URL = "http://localhost:11434"
|
|
35
22
|
|
|
36
23
|
|
|
37
24
|
class EmbeddingModelComponent(LCEmbeddingsModel):
|
|
@@ -42,15 +29,51 @@ class EmbeddingModelComponent(LCEmbeddingsModel):
|
|
|
42
29
|
name = "EmbeddingModel"
|
|
43
30
|
category = "models"
|
|
44
31
|
|
|
32
|
+
def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):
|
|
33
|
+
"""Dynamically update build config with user-filtered model options."""
|
|
34
|
+
# Update model options
|
|
35
|
+
build_config = update_model_options_in_build_config(
|
|
36
|
+
component=self,
|
|
37
|
+
build_config=build_config,
|
|
38
|
+
cache_key_prefix="embedding_model_options",
|
|
39
|
+
get_options_func=get_embedding_model_options,
|
|
40
|
+
field_name=field_name,
|
|
41
|
+
field_value=field_value,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# Show/hide provider-specific fields based on selected model
|
|
45
|
+
if field_name == "model" and isinstance(field_value, list) and len(field_value) > 0:
|
|
46
|
+
selected_model = field_value[0]
|
|
47
|
+
provider = selected_model.get("provider", "")
|
|
48
|
+
|
|
49
|
+
# Show/hide watsonx fields
|
|
50
|
+
is_watsonx = provider == "IBM WatsonX"
|
|
51
|
+
build_config["base_url_ibm_watsonx"]["show"] = is_watsonx
|
|
52
|
+
build_config["project_id"]["show"] = is_watsonx
|
|
53
|
+
build_config["truncate_input_tokens"]["show"] = is_watsonx
|
|
54
|
+
build_config["input_text"]["show"] = is_watsonx
|
|
55
|
+
if is_watsonx:
|
|
56
|
+
build_config["base_url_ibm_watsonx"]["required"] = True
|
|
57
|
+
build_config["project_id"]["required"] = True
|
|
58
|
+
|
|
59
|
+
return build_config
|
|
60
|
+
|
|
45
61
|
inputs = [
|
|
46
|
-
|
|
47
|
-
name="
|
|
48
|
-
display_name="Model
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
ModelInput(
|
|
63
|
+
name="model",
|
|
64
|
+
display_name="Embedding Model",
|
|
65
|
+
info="Select your model provider",
|
|
66
|
+
real_time_refresh=True,
|
|
67
|
+
required=True,
|
|
68
|
+
model_type="embedding",
|
|
69
|
+
input_types=["Embeddings"], # Override default to accept Embeddings instead of LanguageModel
|
|
70
|
+
),
|
|
71
|
+
SecretStrInput(
|
|
72
|
+
name="api_key",
|
|
73
|
+
display_name="API Key",
|
|
74
|
+
info="Model Provider API key",
|
|
52
75
|
real_time_refresh=True,
|
|
53
|
-
|
|
76
|
+
advanced=True,
|
|
54
77
|
),
|
|
55
78
|
MessageTextInput(
|
|
56
79
|
name="api_base",
|
|
@@ -58,15 +81,7 @@ class EmbeddingModelComponent(LCEmbeddingsModel):
|
|
|
58
81
|
info="Base URL for the API. Leave empty for default.",
|
|
59
82
|
advanced=True,
|
|
60
83
|
),
|
|
61
|
-
|
|
62
|
-
name="ollama_base_url",
|
|
63
|
-
display_name="Ollama API URL",
|
|
64
|
-
info=f"Endpoint of the Ollama API (Ollama only). Defaults to {DEFAULT_OLLAMA_URL}",
|
|
65
|
-
value=DEFAULT_OLLAMA_URL,
|
|
66
|
-
show=False,
|
|
67
|
-
real_time_refresh=True,
|
|
68
|
-
load_from_db=True,
|
|
69
|
-
),
|
|
84
|
+
# Watson-specific inputs
|
|
70
85
|
DropdownInput(
|
|
71
86
|
name="base_url_ibm_watsonx",
|
|
72
87
|
display_name="watsonx API Endpoint",
|
|
@@ -76,24 +91,6 @@ class EmbeddingModelComponent(LCEmbeddingsModel):
|
|
|
76
91
|
show=False,
|
|
77
92
|
real_time_refresh=True,
|
|
78
93
|
),
|
|
79
|
-
DropdownInput(
|
|
80
|
-
name="model",
|
|
81
|
-
display_name="Model Name",
|
|
82
|
-
options=OPENAI_EMBEDDING_MODEL_NAMES,
|
|
83
|
-
value=OPENAI_EMBEDDING_MODEL_NAMES[0],
|
|
84
|
-
info="Select the embedding model to use",
|
|
85
|
-
real_time_refresh=True,
|
|
86
|
-
refresh_button=True,
|
|
87
|
-
),
|
|
88
|
-
SecretStrInput(
|
|
89
|
-
name="api_key",
|
|
90
|
-
display_name="OpenAI API Key",
|
|
91
|
-
info="Model Provider API key",
|
|
92
|
-
required=True,
|
|
93
|
-
show=True,
|
|
94
|
-
real_time_refresh=True,
|
|
95
|
-
),
|
|
96
|
-
# Watson-specific inputs
|
|
97
94
|
MessageTextInput(
|
|
98
95
|
name="project_id",
|
|
99
96
|
display_name="Project ID",
|
|
@@ -107,10 +104,28 @@ class EmbeddingModelComponent(LCEmbeddingsModel):
|
|
|
107
104
|
"Only supported by certain models.",
|
|
108
105
|
advanced=True,
|
|
109
106
|
),
|
|
110
|
-
IntInput(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
IntInput(
|
|
108
|
+
name="chunk_size",
|
|
109
|
+
display_name="Chunk Size",
|
|
110
|
+
advanced=True,
|
|
111
|
+
value=1000,
|
|
112
|
+
),
|
|
113
|
+
FloatInput(
|
|
114
|
+
name="request_timeout",
|
|
115
|
+
display_name="Request Timeout",
|
|
116
|
+
advanced=True,
|
|
117
|
+
),
|
|
118
|
+
IntInput(
|
|
119
|
+
name="max_retries",
|
|
120
|
+
display_name="Max Retries",
|
|
121
|
+
advanced=True,
|
|
122
|
+
value=3,
|
|
123
|
+
),
|
|
124
|
+
BoolInput(
|
|
125
|
+
name="show_progress_bar",
|
|
126
|
+
display_name="Show Progress Bar",
|
|
127
|
+
advanced=True,
|
|
128
|
+
),
|
|
114
129
|
DictInput(
|
|
115
130
|
name="model_kwargs",
|
|
116
131
|
display_name="Model Kwargs",
|
|
@@ -133,221 +148,122 @@ class EmbeddingModelComponent(LCEmbeddingsModel):
|
|
|
133
148
|
),
|
|
134
149
|
]
|
|
135
150
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
151
|
+
def build_embeddings(self) -> Embeddings:
|
|
152
|
+
"""Build and return an embeddings instance based on the selected model."""
|
|
153
|
+
# If an Embeddings object is directly connected, return it
|
|
139
154
|
try:
|
|
140
|
-
|
|
141
|
-
params = {
|
|
142
|
-
"version": "2024-09-16",
|
|
143
|
-
"filters": "function_embedding,!lifecycle_withdrawn:and",
|
|
144
|
-
}
|
|
145
|
-
response = requests.get(endpoint, params=params, timeout=10)
|
|
146
|
-
response.raise_for_status()
|
|
147
|
-
data = response.json()
|
|
148
|
-
models = [model["model_id"] for model in data.get("resources", [])]
|
|
149
|
-
return sorted(models)
|
|
150
|
-
except Exception: # noqa: BLE001
|
|
151
|
-
logger.exception("Error fetching models")
|
|
152
|
-
return WATSONX_EMBEDDING_MODEL_NAMES
|
|
155
|
+
from langchain_core.embeddings import Embeddings as BaseEmbeddings
|
|
153
156
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
api_base = self.api_base
|
|
159
|
-
base_url_ibm_watsonx = self.base_url_ibm_watsonx
|
|
160
|
-
ollama_base_url = self.ollama_base_url
|
|
161
|
-
dimensions = self.dimensions
|
|
162
|
-
chunk_size = self.chunk_size
|
|
163
|
-
request_timeout = self.request_timeout
|
|
164
|
-
max_retries = self.max_retries
|
|
165
|
-
show_progress_bar = self.show_progress_bar
|
|
166
|
-
model_kwargs = self.model_kwargs or {}
|
|
157
|
+
if isinstance(self.model, BaseEmbeddings):
|
|
158
|
+
return self.model
|
|
159
|
+
except ImportError:
|
|
160
|
+
pass
|
|
167
161
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return OpenAIEmbeddings(
|
|
173
|
-
model=model,
|
|
174
|
-
dimensions=dimensions or None,
|
|
175
|
-
base_url=api_base or None,
|
|
176
|
-
api_key=api_key,
|
|
177
|
-
chunk_size=chunk_size,
|
|
178
|
-
max_retries=max_retries,
|
|
179
|
-
timeout=request_timeout or None,
|
|
180
|
-
show_progress_bar=show_progress_bar,
|
|
181
|
-
model_kwargs=model_kwargs,
|
|
182
|
-
)
|
|
162
|
+
# Safely extract model configuration
|
|
163
|
+
if not self.model or not isinstance(self.model, list):
|
|
164
|
+
msg = "Model must be a non-empty list"
|
|
165
|
+
raise ValueError(msg)
|
|
183
166
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
try:
|
|
189
|
-
from langchain_community.embeddings import OllamaEmbeddings
|
|
190
|
-
except ImportError:
|
|
191
|
-
msg = "Please install langchain-ollama: pip install langchain-ollama"
|
|
192
|
-
raise ImportError(msg) from None
|
|
167
|
+
model = self.model[0]
|
|
168
|
+
model_name = model.get("name")
|
|
169
|
+
provider = model.get("provider")
|
|
170
|
+
metadata = model.get("metadata", {})
|
|
193
171
|
|
|
194
|
-
|
|
172
|
+
# Get API key from user input or global variables
|
|
173
|
+
api_key = get_api_key_for_provider(self.user_id, provider, self.api_key)
|
|
195
174
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
"not the OpenAI-compatible API. The '/v1' suffix has been automatically removed. "
|
|
203
|
-
"If you want to use the OpenAI-compatible API, please use the OpenAI component instead. "
|
|
204
|
-
"Learn more at https://docs.ollama.com/openai#openai-compatibility"
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
return OllamaEmbeddings(
|
|
208
|
-
model=model,
|
|
209
|
-
base_url=transformed_base_url or "http://localhost:11434",
|
|
210
|
-
**model_kwargs,
|
|
175
|
+
# Validate required fields (Ollama doesn't require API key)
|
|
176
|
+
if not api_key and provider != "Ollama":
|
|
177
|
+
msg = (
|
|
178
|
+
f"{provider} API key is required. "
|
|
179
|
+
f"Please provide it in the component or configure it globally as "
|
|
180
|
+
f"{provider.upper().replace(' ', '_')}_API_KEY."
|
|
211
181
|
)
|
|
182
|
+
raise ValueError(msg)
|
|
212
183
|
|
|
213
|
-
if
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
except ImportError:
|
|
217
|
-
msg = "Please install langchain-ibm: pip install langchain-ibm"
|
|
218
|
-
raise ImportError(msg) from None
|
|
184
|
+
if not model_name:
|
|
185
|
+
msg = "Model name is required"
|
|
186
|
+
raise ValueError(msg)
|
|
219
187
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
188
|
+
# Get embedding class
|
|
189
|
+
embedding_class_name = metadata.get("embedding_class")
|
|
190
|
+
if not embedding_class_name:
|
|
191
|
+
msg = f"No embedding class defined in metadata for {model_name}"
|
|
192
|
+
raise ValueError(msg)
|
|
223
193
|
|
|
224
|
-
|
|
194
|
+
embedding_class = get_embedding_classes().get(embedding_class_name)
|
|
195
|
+
if not embedding_class:
|
|
196
|
+
msg = f"Unknown embedding class: {embedding_class_name}"
|
|
197
|
+
raise ValueError(msg)
|
|
225
198
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
raise ValueError(msg)
|
|
199
|
+
# Build kwargs using parameter mapping
|
|
200
|
+
kwargs = self._build_kwargs(model, metadata)
|
|
229
201
|
|
|
230
|
-
|
|
202
|
+
return embedding_class(**kwargs)
|
|
231
203
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
204
|
+
def _build_kwargs(self, model: dict[str, Any], metadata: dict[str, Any]) -> dict[str, Any]:
|
|
205
|
+
"""Build kwargs dictionary using parameter mapping."""
|
|
206
|
+
param_mapping = metadata.get("param_mapping", {})
|
|
207
|
+
if not param_mapping:
|
|
208
|
+
msg = "Parameter mapping not found in metadata"
|
|
209
|
+
raise ValueError(msg)
|
|
236
210
|
|
|
237
|
-
|
|
211
|
+
kwargs = {}
|
|
238
212
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
213
|
+
# Required parameters - handle both "model" and "model_id" (for watsonx)
|
|
214
|
+
if "model" in param_mapping:
|
|
215
|
+
kwargs[param_mapping["model"]] = model.get("name")
|
|
216
|
+
elif "model_id" in param_mapping:
|
|
217
|
+
kwargs[param_mapping["model_id"]] = model.get("name")
|
|
218
|
+
if "api_key" in param_mapping:
|
|
219
|
+
kwargs[param_mapping["api_key"]] = get_api_key_for_provider(
|
|
220
|
+
self.user_id,
|
|
221
|
+
model.get("provider"),
|
|
222
|
+
self.api_key,
|
|
249
223
|
)
|
|
250
224
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
build_config["api_key"]["required"] = True
|
|
263
|
-
build_config["api_key"]["show"] = True
|
|
264
|
-
build_config["api_base"]["display_name"] = "OpenAI API Base URL"
|
|
265
|
-
build_config["api_base"]["advanced"] = True
|
|
266
|
-
build_config["api_base"]["show"] = True
|
|
267
|
-
build_config["ollama_base_url"]["show"] = False
|
|
268
|
-
build_config["project_id"]["show"] = False
|
|
269
|
-
build_config["base_url_ibm_watsonx"]["show"] = False
|
|
270
|
-
build_config["truncate_input_tokens"]["show"] = False
|
|
271
|
-
build_config["input_text"]["show"] = False
|
|
272
|
-
elif field_value == "Ollama":
|
|
273
|
-
build_config["ollama_base_url"]["show"] = True
|
|
225
|
+
# Optional parameters with their values
|
|
226
|
+
provider = model.get("provider")
|
|
227
|
+
optional_params = {
|
|
228
|
+
"api_base": self.api_base if self.api_base else None,
|
|
229
|
+
"dimensions": int(self.dimensions) if self.dimensions else None,
|
|
230
|
+
"chunk_size": int(self.chunk_size) if self.chunk_size else None,
|
|
231
|
+
"request_timeout": float(self.request_timeout) if self.request_timeout else None,
|
|
232
|
+
"max_retries": int(self.max_retries) if self.max_retries else None,
|
|
233
|
+
"show_progress_bar": self.show_progress_bar if hasattr(self, "show_progress_bar") else None,
|
|
234
|
+
"model_kwargs": self.model_kwargs if self.model_kwargs else None,
|
|
235
|
+
}
|
|
274
236
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
build_config["model"]["value"] = ""
|
|
289
|
-
else:
|
|
290
|
-
build_config["model"]["options"] = []
|
|
291
|
-
build_config["model"]["value"] = ""
|
|
292
|
-
build_config["truncate_input_tokens"]["show"] = False
|
|
293
|
-
build_config["input_text"]["show"] = False
|
|
294
|
-
build_config["api_key"]["display_name"] = "API Key (Optional)"
|
|
295
|
-
build_config["api_key"]["required"] = False
|
|
296
|
-
build_config["api_key"]["show"] = False
|
|
297
|
-
build_config["api_base"]["show"] = False
|
|
298
|
-
build_config["project_id"]["show"] = False
|
|
299
|
-
build_config["base_url_ibm_watsonx"]["show"] = False
|
|
237
|
+
# Watson-specific parameters
|
|
238
|
+
if provider in {"IBM WatsonX", "IBM watsonx.ai"}:
|
|
239
|
+
# Map base_url_ibm_watsonx to "url" parameter for watsonx
|
|
240
|
+
if "url" in param_mapping:
|
|
241
|
+
url_value = (
|
|
242
|
+
self.base_url_ibm_watsonx
|
|
243
|
+
if hasattr(self, "base_url_ibm_watsonx") and self.base_url_ibm_watsonx
|
|
244
|
+
else "https://us-south.ml.cloud.ibm.com"
|
|
245
|
+
)
|
|
246
|
+
kwargs[param_mapping["url"]] = url_value
|
|
247
|
+
# Map project_id for watsonx
|
|
248
|
+
if hasattr(self, "project_id") and self.project_id and "project_id" in param_mapping:
|
|
249
|
+
kwargs[param_mapping["project_id"]] = self.project_id
|
|
300
250
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
build_config["api_key"]["show"] = True
|
|
307
|
-
build_config["api_base"]["show"] = False
|
|
308
|
-
build_config["ollama_base_url"]["show"] = False
|
|
309
|
-
build_config["base_url_ibm_watsonx"]["show"] = True
|
|
310
|
-
build_config["project_id"]["show"] = True
|
|
311
|
-
build_config["truncate_input_tokens"]["show"] = True
|
|
312
|
-
build_config["input_text"]["show"] = True
|
|
313
|
-
elif field_name == "base_url_ibm_watsonx":
|
|
314
|
-
build_config["model"]["options"] = self.fetch_ibm_models(base_url=field_value)
|
|
315
|
-
build_config["model"]["value"] = self.fetch_ibm_models(base_url=field_value)[0]
|
|
316
|
-
elif field_name == "ollama_base_url":
|
|
317
|
-
# # Refresh Ollama models when base URL changes
|
|
318
|
-
# if hasattr(self, "provider") and self.provider == "Ollama":
|
|
319
|
-
# Use field_value if provided, otherwise fall back to instance attribute
|
|
320
|
-
ollama_url = self.ollama_base_url
|
|
321
|
-
if await is_valid_ollama_url(url=ollama_url):
|
|
322
|
-
try:
|
|
323
|
-
models = await get_ollama_models(
|
|
324
|
-
base_url_value=ollama_url,
|
|
325
|
-
desired_capability=DESIRED_CAPABILITY,
|
|
326
|
-
json_models_key=JSON_MODELS_KEY,
|
|
327
|
-
json_name_key=JSON_NAME_KEY,
|
|
328
|
-
json_capabilities_key=JSON_CAPABILITIES_KEY,
|
|
329
|
-
)
|
|
330
|
-
build_config["model"]["options"] = models
|
|
331
|
-
build_config["model"]["value"] = models[0] if models else ""
|
|
332
|
-
except ValueError:
|
|
333
|
-
await logger.awarning("Failed to fetch Ollama embedding models.")
|
|
334
|
-
build_config["model"]["options"] = []
|
|
335
|
-
build_config["model"]["value"] = ""
|
|
251
|
+
# Ollama-specific parameters
|
|
252
|
+
if provider == "Ollama" and "base_url" in param_mapping:
|
|
253
|
+
# Map api_base to "base_url" parameter for Ollama
|
|
254
|
+
base_url_value = self.api_base if hasattr(self, "api_base") and self.api_base else "http://localhost:11434"
|
|
255
|
+
kwargs[param_mapping["base_url"]] = base_url_value
|
|
336
256
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
if
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
build_config["model"]["options"] = models
|
|
349
|
-
except ValueError:
|
|
350
|
-
await logger.awarning("Failed to refresh Ollama embedding models.")
|
|
351
|
-
build_config["model"]["options"] = []
|
|
257
|
+
# Add optional parameters if they have values and are mapped
|
|
258
|
+
for param_name, param_value in optional_params.items():
|
|
259
|
+
if param_value is not None and param_name in param_mapping:
|
|
260
|
+
# Special handling for request_timeout with Google provider
|
|
261
|
+
if param_name == "request_timeout":
|
|
262
|
+
if provider == "Google" and isinstance(param_value, (int, float)):
|
|
263
|
+
kwargs[param_mapping[param_name]] = {"timeout": param_value}
|
|
264
|
+
else:
|
|
265
|
+
kwargs[param_mapping[param_name]] = param_value
|
|
266
|
+
else:
|
|
267
|
+
kwargs[param_mapping[param_name]] = param_value
|
|
352
268
|
|
|
353
|
-
return
|
|
269
|
+
return kwargs
|