From 80f4d2bf6c4489636bcad9a338ceffb80e37ba32 Mon Sep 17 00:00:00 2001 From: Dreaming Computers Date: Sun, 1 Feb 2026 15:39:33 +0700 Subject: [PATCH] chore: rename raw_json outputs to data --- example_workflows/Kie-AI-Nodes.json | 4 ++-- kie_api/credits.py | 4 ++-- kie_api/gemini3_pro_llm.py | 15 ++++++++++++--- kie_api/suno_music.py | 20 ++++++++++++++++++-- nodes.py | 15 ++++++++------- web/docs/KIE_Suno_Music_Advanced.md | 2 +- web/docs/KIE_Suno_Music_Basic.md | 2 +- 7 files changed, 44 insertions(+), 18 deletions(-) diff --git a/example_workflows/Kie-AI-Nodes.json b/example_workflows/Kie-AI-Nodes.json index 2e70e58..e4f2565 100644 --- a/example_workflows/Kie-AI-Nodes.json +++ b/example_workflows/Kie-AI-Nodes.json @@ -1808,7 +1808,7 @@ "inputs": [], "outputs": [ { - "name": "raw_json", + "name": "data", "type": "STRING", "links": null }, @@ -2963,4 +2963,4 @@ "VHS_KeepIntermediate": true }, "version": 0.4 -} \ No newline at end of file +} diff --git a/kie_api/credits.py b/kie_api/credits.py index 4bd8321..348d8ef 100644 --- a/kie_api/credits.py +++ b/kie_api/credits.py @@ -15,7 +15,6 @@ def _fetch_remaining_credits(api_key: str) -> Tuple[str, int]: except requests.RequestException as exc: raise RuntimeError(f"Failed to call remaining credits endpoint: {exc}") from exc - raw_text = response.text try: payload: Any = response.json() except json.JSONDecodeError as exc: @@ -33,7 +32,8 @@ def _fetch_remaining_credits(api_key: str) -> Tuple[str, int]: except (TypeError, ValueError) as exc: raise RuntimeError("Remaining credits value is not an integer.") from exc - return raw_text, credits_remaining + formatted_json = json.dumps(payload, indent=2, ensure_ascii=False) + return formatted_json, credits_remaining def _log_remaining_credits(log: bool, record_data: dict[str, Any], api_key: str, log_fn) -> None: diff --git a/kie_api/gemini3_pro_llm.py b/kie_api/gemini3_pro_llm.py index ca27cec..301ba4b 100644 --- a/kie_api/gemini3_pro_llm.py +++ b/kie_api/gemini3_pro_llm.py @@ -33,6 +33,15 @@ def _parse_json_optional(raw: str | None, label: str) -> Any | None: raise RuntimeError(f"{label} is not valid JSON.") from exc +def _format_json_for_output(payload: Any) -> str: + if payload is None: + return "" + try: + return json.dumps(payload, indent=2, ensure_ascii=False) + except TypeError: + return json.dumps(payload, indent=2, ensure_ascii=False, default=str) + + def _normalize_messages( prompt: str, messages_json: str | None, @@ -88,7 +97,7 @@ def run_gemini3_pro_chat( """Run a Gemini 3 Pro chat completion request. Returns: - (content_text, reasoning_text, raw_json) + (content_text, reasoning_text, data_json) """ if model not in CHAT_COMPLETIONS_URLS: raise RuntimeError("Invalid model. Use the pinned enum options.") @@ -198,7 +207,7 @@ def run_gemini3_pro_chat( message = (choices[0].get("message") or {}) content = message.get("content") or "" reasoning = message.get("reasoning_content") or "" - return (str(content), str(reasoning), json.dumps(payload_json)) + return (str(content), str(reasoning), _format_json_for_output(payload_json)) content_parts: list[str] = [] reasoning_parts: list[str] = [] @@ -233,7 +242,7 @@ def run_gemini3_pro_chat( content_text = "".join(content_parts) reasoning_text = "".join(reasoning_parts) - raw_json = json.dumps(last_payload) if last_payload is not None else "" + raw_json = _format_json_for_output(last_payload) if last_payload is not None else "" if log: _log(log, f"{model} response length: {len(content_text)} chars") diff --git a/kie_api/suno_music.py b/kie_api/suno_music.py index eec13ab..d8ee816 100644 --- a/kie_api/suno_music.py +++ b/kie_api/suno_music.py @@ -23,6 +23,22 @@ FAIL_STATES = { } +def _format_record_for_output(record: dict[str, Any]) -> str: + try: + record_copy = json.loads(json.dumps(record)) + except TypeError: + record_copy = dict(record) + + param_value = record_copy.get("param") + if isinstance(param_value, str): + try: + record_copy["param"] = json.loads(param_value) + except json.JSONDecodeError: + record_copy["param"] = param_value + + return json.dumps(record_copy, indent=2, ensure_ascii=False, default=str) + + def _validate_length(field_name: str, value: str | None, max_len: int) -> None: if value is None: return @@ -163,7 +179,7 @@ def run_suno_generate( timeout_s: int = 1800, log: bool = True, ) -> tuple[dict, str]: - """Create a Suno music generation task and return audio output + raw record-info JSON.""" + """Create a Suno music generation task and return audio output + formatted record-info JSON.""" if model not in MODEL_OPTIONS: raise RuntimeError("Invalid model. Use the pinned enum options.") if vocal_gender and vocal_gender not in VOCAL_GENDER_OPTIONS: @@ -280,4 +296,4 @@ def run_suno_generate( waveform = audio_output.get("waveform") shape = getattr(waveform, "shape", None) _log(log, f"Suno audio waveform shape: {shape}") - return audio_output, json.dumps(record) + return audio_output, _format_record_for_output(record) diff --git a/nodes.py b/nodes.py index fa793b6..c4fa0f9 100644 --- a/nodes.py +++ b/nodes.py @@ -69,6 +69,7 @@ Inputs: - (none) Outputs: +- STRING: data - INT: Remaining credits Notes: - If your key is missing/invalid, this node errors. @@ -78,7 +79,7 @@ Notes: return {"required": {"log": ("BOOLEAN", {"default": True})}} RETURN_TYPES = ("STRING", "INT") - RETURN_NAMES = ("raw_json", "credits_remaining") + RETURN_NAMES = ("data", "credits_remaining") FUNCTION = "get_remaining_credits" CATEGORY = "kie/api" @@ -659,7 +660,7 @@ Inputs: Outputs: - STRING: Assistant response text - STRING: Reasoning text (empty if include_thoughts is false) -- STRING: Raw JSON from last response chunk +- STRING: data (formatted JSON from last response chunk) """ @classmethod @@ -685,7 +686,7 @@ Outputs: } RETURN_TYPES = ("STRING", "STRING", "STRING") - RETURN_NAMES = ("text", "reasoning", "raw_json") + RETURN_NAMES = ("text", "reasoning", "data") FUNCTION = "generate" CATEGORY = "kie/api" @@ -744,7 +745,7 @@ Optional: Outputs: - AUDIO: Generated audio -- STRING: raw_json +- STRING: data """ @classmethod @@ -766,7 +767,7 @@ Outputs: } RETURN_TYPES = ("AUDIO", "STRING") - RETURN_NAMES = ("audio", "raw_json") + RETURN_NAMES = ("audio", "data") FUNCTION = "generate" CATEGORY = "kie/api" @@ -819,7 +820,7 @@ Optional: Outputs: - AUDIO: Generated audio -- STRING: raw_json +- STRING: data """ @classmethod @@ -844,7 +845,7 @@ Outputs: } RETURN_TYPES = ("AUDIO", "STRING") - RETURN_NAMES = ("audio", "raw_json") + RETURN_NAMES = ("audio", "data") FUNCTION = "generate" CATEGORY = "kie/api" diff --git a/web/docs/KIE_Suno_Music_Advanced.md b/web/docs/KIE_Suno_Music_Advanced.md index 6c732b1..74ec26c 100644 --- a/web/docs/KIE_Suno_Music_Advanced.md +++ b/web/docs/KIE_Suno_Music_Advanced.md @@ -19,7 +19,7 @@ Optional: ## Outputs - **audio** (AUDIO): Generated audio. -- **raw_json** (STRING): Full API response JSON. +- **data** (STRING): Full API response JSON (formatted). ## Notes - Non-custom mode expects **prompt only** (500 chars max); other fields should be empty. diff --git a/web/docs/KIE_Suno_Music_Basic.md b/web/docs/KIE_Suno_Music_Basic.md index a654a69..fbddc72 100644 --- a/web/docs/KIE_Suno_Music_Basic.md +++ b/web/docs/KIE_Suno_Music_Basic.md @@ -17,7 +17,7 @@ Optional: ## Outputs - **audio** (AUDIO): Generated audio. -- **raw_json** (STRING): Full API response JSON. +- **data** (STRING): Full API response JSON (formatted). ## Notes - Non-custom mode expects **prompt only** (500 chars max); other fields should be empty.