$ cat node-template.py
T
Text Transform
// Transform a text using a custom prompt via an LLM. Input text plus instructions, output the elaborated text.
Process
LLM
#llm#text#transform
template.py
1"""2Text Transform34Take an input text and a prompt; ask the LLM to apply the prompt to the5text and return the elaborated result.6"""78from __future__ import annotations910import asyncio11import json12import sys13import traceback14from typing import Any1516from gais import Gais171819SYSTEM_PROMPT = (20 "You are a careful text-transformation assistant. "21 "Apply the user's instructions to the provided text and return ONLY the "22 "transformed text — no preamble, no commentary, no surrounding quotes."23)2425# Output-language directive (language-persistence workstream). Values are26# platform locale codes; legacy full names are accepted via the allowlist.27# Anything else (wired upstream output, free-form strings) falls back to28# auto: the value is interpolated into the system prompt, so unknown29# strings must never pass through.30LANGUAGE_NAMES = {31 "de": "German", "en": "English", "es": "Spanish", "fr": "French",32 "it": "Italian", "ja": "Japanese", "ko": "Korean", "nl": "Dutch",33 "pt": "Portuguese", "ru": "Russian", "zh": "Chinese",34}353637def resolve_language_name(language):38 """Full display name for an allowlisted language value, else None."""39 if not isinstance(language, str):40 return None41 value = language.strip()42 if not value or value == "auto":43 return None44 if value in LANGUAGE_NAMES:45 return LANGUAGE_NAMES[value]46 if value in LANGUAGE_NAMES.values():47 return value48 print(f"[language] unrecognized value {value!r} ignored - using auto", file=sys.stderr)49 return None505152async def transform(input_text: str, prompt: str, model_id: str, language: str = "auto") -> str:53 system_prompt = SYSTEM_PROMPT54 lang_name = resolve_language_name(language)55 if lang_name:56 system_prompt += (57 f"\n\nOUTPUT LANGUAGE: {lang_name}. Write the transformed text in "58 f"{lang_name} regardless of the source text's language. This "59 "OVERRIDES any language stated in the instructions or implied by "60 "the source text. Keep proper nouns and verbatim quotes in their "61 "original language."62 )63 user_message = (64 f"<instructions>{prompt}</instructions>\n\n"65 f"<text>{input_text}</text>"66 )67 messages = [68 {"role": "system", "content": system_prompt},69 {"role": "user", "content": user_message},70 ]71 response = await Gais.llm.chat_async(messages, model_id=model_id, temperature=0, thinking=False)72 return response.text.strip()737475def main() -> None:76 try:77 envelope = json.loads(sys.stdin.read() or "{}")78 inputs: dict[str, Any] = envelope.get("inputs", {}) if isinstance(envelope, dict) else {}7980 input_text = inputs.get("input_text")81 prompt = inputs.get("prompt")82 llm_model_id = inputs.get("llmModelId")83 language = inputs.get("language", "auto")8485 if not input_text:86 raise ValueError("Required input 'input_text' not provided")87 if not prompt:88 raise ValueError("Required input 'prompt' not provided")89 if not llm_model_id:90 raise ValueError("Required input 'llmModelId' not provided")9192 print(93 f"[text-transform] model_id={llm_model_id} input_chars={len(input_text)}",94 file=sys.stderr,95 )9697 output_text = asyncio.run(transform(input_text, prompt, llm_model_id, language))9899 print(100 f"[text-transform] done output_chars={len(output_text)}",101 file=sys.stderr,102 )103104 json.dump({"output_text": output_text}, sys.stdout)105 except Exception as e:106 error = {107 "error": str(e),108 "errorType": type(e).__name__,109 "traceback": traceback.format_exc(),110 }111 print(json.dumps(error), file=sys.stderr)112 sys.exit(1)113114115if __name__ == "__main__":116 main()$ git log --oneline
v1.3.0
HEAD
2026-08-18v1.2.12026-06-27
v1.2.02026-06-24
v1.0.02026-05-22