diff --git a/Nodes/Uniapi.py b/Nodes/Uniapi.py index 13a811e..b61b427 100644 --- a/Nodes/Uniapi.py +++ b/Nodes/Uniapi.py @@ -138,9 +138,7 @@ class PrimereApiProcessor: if debug_mode: img_binary_api = 'Reference images off. Please check the source.' - selected_parameters = {"prompt": prompt} - selected_parameters = {"width": width} - selected_parameters = {"height": height} + selected_parameters = {"prompt": prompt, "width": width, "height": height} local_inputs = locals() required_keys = set(self.required_inputs.keys()) if isinstance(getattr(self, "required_inputs", None), dict) else set() @@ -232,7 +230,7 @@ class PrimereApiProcessor: if debug_mode: return (reference_images, loaded_client, api_provider, schema, rendered_payload, used_values_output, api_result, None) - api_result = external_api_backend.execute_sdk_request(rendered, context, allowed_roots) + api_result = external_api_backend.execute_sdk_request(rendered, context, allowed_roots, match_context=used_values) else: import requests diff --git a/components/API/api_json_to_requestbody.py b/components/API/api_json_to_requestbody.py index 9f0255c..41a93bd 100644 --- a/components/API/api_json_to_requestbody.py +++ b/components/API/api_json_to_requestbody.py @@ -200,6 +200,11 @@ def render_from_schema(spec: dict[str, Any], values: dict[str, Any] | None = Non filtered_used_values = _filter_used_values_from_template(spec, used_values, matched_remove_paths) filtered_used_values = {k: v for k, v in filtered_used_values.items() if v is not None} + if matched_remove_paths and isinstance(rendered.sdk_call, dict): + sdk_kwargs = rendered.sdk_call.get("kwargs") + if isinstance(sdk_kwargs, dict): + request_exceptions.apply_remove_paths(sdk_kwargs, matched_remove_paths, use_kwargs_fallback=True) + rendered.headers = _remove_none_values(rendered.headers) if isinstance(rendered.headers, dict) else rendered.headers rendered.query = _remove_none_values(rendered.query) if isinstance(rendered.query, dict) else rendered.query rendered.body = _remove_none_values(rendered.body) diff --git a/components/API/external_api_backend.py b/components/API/external_api_backend.py index 152304a..798a869 100644 --- a/components/API/external_api_backend.py +++ b/components/API/external_api_backend.py @@ -322,13 +322,13 @@ def _apply_auth_header_fallback(kwargs: dict[str, Any], context: dict[str, Any]) if headers.get(auth_key) in (None, "", "null"): headers[auth_key] = provider_api_key -def execute_sdk_request(rendered: RenderResult, context: dict[str, Any], allowed_roots: set[str] | None = None) -> Any: +def execute_sdk_request(rendered: RenderResult, context: dict[str, Any], allowed_roots: set[str] | None = None, match_context: dict[str, Any] | None = None) -> Any: if rendered.method.upper() != "SDK": raise ExternalAPIError("execute_sdk_request expects SDK method") roots = allowed_roots or set(context.keys()) fn = _resolve_dotted_from_context(str(rendered.endpoint), context, roots) args, kwargs = normalize_sdk_call(rendered.sdk_call) - filtered_args, filtered_kwargs = request_exceptions.apply_sdk_request_exclusions(args=list(args), kwargs=dict(kwargs), exclusions=rendered.request_exclusions) + filtered_args, filtered_kwargs = request_exceptions.apply_sdk_request_exclusions(args=list(args), kwargs=dict(kwargs), exclusions=rendered.request_exclusions, match_context=match_context) safe_args = [_materialize_sdk_value(a, context, roots) for a in filtered_args] safe_kwargs = {k: _materialize_sdk_value(v, context, roots) for k, v in filtered_kwargs.items()} _apply_auth_header_fallback(safe_kwargs, context) diff --git a/components/API/references/BlackForest.py b/components/API/references/BlackForest.py index 855cefd..e342299 100644 --- a/components/API/references/BlackForest.py +++ b/components/API/references/BlackForest.py @@ -17,28 +17,21 @@ def _encode_tensor_to_base64(image_tensor: Any) -> str | None: img_byte_arr_bf = BytesIO() img_bf.save(img_byte_arr_bf, format="PNG") img_byte_arr_bf.seek(0) - encoded_string = base64.b64encode(img_byte_arr_bf.read()) - return encoded_string.decode("ascii") + return base64.b64encode(img_byte_arr_bf.read()).decode("ascii") -def handle_reference_images(source_images: Any = None, **_: Any): +def handle_reference_images(img_binary_api: Any = None, source_images: Any = None, **_: Any): if not isinstance(source_images, list) or len(source_images) == 0: return [] - encoded_images: list[str] = [] + payload: dict[str, str] = {} for source_image in source_images: encoded = _encode_tensor_to_base64(source_image) if encoded: - encoded_images.append(encoded) - if len(encoded_images) >= 8: + index = len(payload) + 1 + key_name = "input_image" if index == 1 else f"input_image_{index}" + payload[key_name] = encoded + if len(payload) >= 8: break - if len(encoded_images) == 0: - return [] - - payload: dict[str, str] = {} - for index, encoded in enumerate(encoded_images, start=1): - key_name = "input_image" if index == 1 else f"input_image_{index}" - payload[key_name] = encoded - - return payload + return payload if payload else [] diff --git a/components/API/references/OpenAI.py b/components/API/references/OpenAI.py index e8c4df8..1a346aa 100644 --- a/components/API/references/OpenAI.py +++ b/components/API/references/OpenAI.py @@ -6,34 +6,19 @@ from PIL import Image import io import numpy as np -def handle_reference_images(source_images: Any = None, temp_file_ref: str = "", loaded_client_for_upload: Any = None, **_: Any): - output = source_images if isinstance(source_images, list) else [] - if not isinstance(source_images, list) or len(source_images) == 0: - return [] +def handle_reference_images(img_binary_api: Any = None, single_image: Any = None, temp_file_ref: str = "", loaded_client_for_upload: Any = None, **_: Any): + output = img_binary_api if isinstance(img_binary_api, list) else [] - print('----------------------') - print(len(source_images)) - print(type(source_images).__name__) + if single_image is None or type(single_image).__name__ != "Tensor": + return output - for single_image in source_images: - if single_image is not None and type(single_image).__name__ == "Tensor": - # print(type(single_image).__name__) - # print(type(single_image[0]).__name__) - # raise RuntimeError(f"OAI test") - r1 = random.randint(10000, 99999) - image_np = (single_image[0].numpy() * 255).astype(np.uint8) - img = Image.fromarray(image_np) - img_byte_arr = io.BytesIO() - img.save(img_byte_arr, format="PNG") - img_byte_arr.seek(0) - img_binary = img_byte_arr - img_binary.name = f"image_{r1}.png" - print(img_binary) - output.append(img_binary) - - print('----------------------') - print(len(output)) - print(type(output).__name__) - print('----------------------') + r1 = random.randint(10000, 99999) + image_np = (single_image[0].numpy() * 255).astype(np.uint8) + img = Image.fromarray(image_np) + img_byte_arr = io.BytesIO() + img.save(img_byte_arr, format="PNG") + img_byte_arr.seek(0) + img_byte_arr.name = f"image_{r1}.png" + output.append(img_byte_arr) return output \ No newline at end of file diff --git a/components/API/request_exceptions.py b/components/API/request_exceptions.py index 99d4d5d..d4798e9 100644 --- a/components/API/request_exceptions.py +++ b/components/API/request_exceptions.py @@ -253,6 +253,7 @@ def apply_sdk_request_exclusions( args: list[Any], kwargs: dict[str, Any], exclusions: list[dict[str, Any]] | None, + match_context: dict[str, Any] | None = None, ) -> tuple[list[Any], dict[str, Any]]: """Apply schema-driven exclusion rules to SDK kwargs.""" if not isinstance(kwargs, dict): @@ -263,5 +264,6 @@ def apply_sdk_request_exclusions( exclusions, use_kwargs_fallback=True, canonicalize_key=None, + match_context=match_context, ) return args, filtered_kwargs