$ 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)242526async def transform(input_text: str, prompt: str, model: str) -> str:27    user_message = (28        f"<instructions>{prompt}</instructions>\n\n"29        f"<text>{input_text}</text>"30    )31    messages = [32        {"role": "system", "content": SYSTEM_PROMPT},33        {"role": "user", "content": user_message},34    ]35    response = await Gais.llm.chat_async(messages, model=model, temperature=0)36    return response.text.strip()373839def main() -> None:40    try:41        envelope = json.loads(sys.stdin.read() or "{}")42        inputs: dict[str, Any] = envelope.get("inputs", {}) if isinstance(envelope, dict) else {}4344        input_text = inputs.get("input_text")45        prompt = inputs.get("prompt")46        llm_model = inputs.get("llmModel")4748        if not input_text:49            raise ValueError("Required input 'input_text' not provided")50        if not prompt:51            raise ValueError("Required input 'prompt' not provided")52        if not llm_model:53            raise ValueError("Required input 'llmModel' not provided")5455        print(56            f"[text-transform] model={llm_model} input_chars={len(input_text)}",57            file=sys.stderr,58        )5960        output_text = asyncio.run(transform(input_text, prompt, llm_model))6162        print(63            f"[text-transform] done output_chars={len(output_text)}",64            file=sys.stderr,65        )6667        json.dump({"output_text": output_text}, sys.stdout)68    except Exception as e:69        error = {70            "error": str(e),71            "errorType": type(e).__name__,72            "traceback": traceback.format_exc(),73        }74        print(json.dumps(error), file=sys.stderr)75        sys.exit(1)767778if __name__ == "__main__":79    main()

$ git log --oneline

v1.0.0
HEAD
2026-05-22