Nodes/ComfyUI-String-Function/LM Studio Prompt Generator
ComfyUI Node

LM Studio Prompt Generator

Three words in, a finished prompt out, nothing leaves your machine

By TakkunRed·Created 5 months ago·Updated 15 days ago· 1
LM Studio Prompt Generator
    • prompt
    • negative_prompt
    • raw_text
    • method_used
    • success
    ◄theme►
    ◄system_promptあなたは画像生成AI用のプロンプトを作るアシスタントです。 - 与えられたテーマから、画像生成プロンプトを英語で1つ作成してください。 - 毎回異なるプロンプトを生成してください。 - 再現性を高めるため、被写体・構図・照明・色彩・質感・画風・カメラ/レンズなど、細部に至るまで可能な限り詳細に記述してください。 - 思考過程・説明・前置きは絶対に出力しないでください。►
    ◄model_key►
    ◄structured_outputtrue►
    ◄generate_negativetrue►
    ◄seed-1►
    ◄max_tokens4096►
    ◄temperature0.70►
    ◄auto_unloadfalse►
    ◄unload_delay0►
    ◄timeout_seconds300►
    ◄strip_thinkingtrue►
    ◄debugfalse►

    You type "rain-soaked Tokyo alley, 3am" into a box. A language model turns it into a 90-word prompt with lens, film stock and lighting spelled out, and it lands in your positive CLIPTextEncode. No API key, no credits. The model runs in LM Studio on your own hardware, and this node is the wire between the two.

    The name is honest: it needs LM Studio. But it's an HTTP client pointed at localhost:1234 or a box on your LAN - offline, uncensored, free per call.

    How it works

    LLM-in-the-graph prompting isn't fringe - "prompt enhancer" went from 12 mentions in 2023 to 253 by mid-2026. It has a bad reputation for one reason: a chat model answers "Sure! Here's your prompt:" and the preamble becomes literal tokens in your conditioning. This node stops the model writing prose at all.

    It POSTs to LM Studio's OpenAI-compatible /v1/chat/completions with plain urllib, zero third-party deps, and with structured_output on it attaches response_format: json_schema with strict: true, so the server constrains decoding: you get a JSON object with prompt (plus negative_prompt if requested) and nothing else. The output then rides the pack's String Extract Prompt extractor: thinking blocks, gpt-oss channel markers and LM Studio's own synthetic-reasoning markers get stripped, then JSON / label / comma-density heuristics run in order. Turn structured_output off and the node appends a PROMPT: / NEGATIVE: hint to your system prompt instead - the right setting for gpt-oss models, whose channel format fights JSON schema.

    Leave model_key empty and it asks LM Studio's /api/v0/models which model is loaded, then uses it. The base URL lives in a .env next to the node code and is re-read on every call, so you can change servers mid-session without restarting ComfyUI.

    The inputs that matter

    theme is your user message, the only thing you type per run. system_prompt is the real control: the default (Japanese, asking for an English, detail-dense prompt with no preamble) is a fine start - don't add output-format instructions, the node appends those. On a tag model like Illustrious or Pony, this is where you demand comma-separated booru tags; sentences are the model's habit otherwise.

    seed at -1 means random every run, and the node declares itself always-changed so it re-fires on each queue. Pin it to a number and ComfyUI's caching may hand you the previous prompt until something upstream shifts - the usual cause of a stuck, repeating prompt. generate_negative is on by default; temperature 0.7 is fine for variety, drop to ~0.3 if a theme keeps wandering. The rest - max_tokens (4096), timeout_seconds (300), auto_unload / unload_delay, strip_thinking, and debug, which dumps the raw request/response to console - leave alone until something misbehaves.

    Wiring the outputs

    prompt goes to your positive CLIPTextEncode; negative_prompt to the negative one - but on guidance-distilled models run at CFG 1, ComfyUI doesn't compute the negative pass at all, so generating one wastes tokens. Turn generate_negative off on Z-Image Turbo and the Klein distilled checkpoints. raw_text is the model's real output and pairs with the pack's Prompt Preview node when extraction goes sideways. method_used reports which path won; success is your gate.

    Install

    ComfyUI Manager → search "String Function", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TakkunRed/ComfyUI-String-Function
    

    Restart ComfyUI. There's no requirements.txt and nothing to pip install - a genuine relief around here. Then start LM Studio's server (Developer → Start Server, port 1234) and drop a .env in the pack folder:

    cd ComfyUI/custom_nodes/ComfyUI-String-Function
    cp .env.example .env
    # LMSTUDIO_BASE_URL=http://192.168.1.10:1234   # remote LM Studio
    

    For a remote box, enable Serve on Local Network in LM Studio and open the port. One optional dependency: the lmstudio Python SDK, only if you want instant unload with model_key empty; the TTL path doesn't need it.

    Where people get burned

    Connection failures and timeouts raise and stop the workflow, deliberately, so an empty prompt never reaches the sampler. A blank theme, though, returns an empty prompt with success=False and does not raise - if you're feeding it from a file or wildcard node, gate on success or you'll quietly render nothing.

    An HTTP 400 with the model's complaint usually means it doesn't do JSON-schema output; switch structured_output off and let the extractor carry it. VRAM is the other one: an LLM plus a checkpoint on one card is a real budget, and people co-running the two have reported a lingering LM Studio process causing an OOM afterwards. auto_unload=True with unload_delay=120 is the automated version of "close it when you're done".

    Expectation-setting: enhancement is a blank-page cure, not a quality upgrade - it writes more, not better. It earns its keep on bases that reward long descriptive prompts (Z-Image, Klein, Flux 2) and is close to pointless on a tag model where you know the tags.

    CategoryString Function

    Inputs (13)

    NameTypeDefaultDescription
    themeSTRINGユーザーメッセージ。生成したい画像のテーマ
    system_promptSTRINGあなたは画像生成AI用のプロンプトを作るアシスタントです。 - 与えられたテーマから、画像生成プロンプトを英語で1つ作成してください。 - 毎回異なるプロンプトを生成してください。 - 再現性を高めるため、被写体・構図・照明・色彩・質感・画風・カメラ/レンズなど、細部に至るまで可能な限り詳細に記述してください。 - 思考過程・説明・前置きは絶対に出力しないでください。LLMへの指示。出力形式の指定は不要(ノードが自動で付与する)
    model_keySTRINGLM Studio のモデルキー。空欄ならロード済みモデルを使用
    structured_outputBOOLEANtrueTrue=JSON Schema で出力形式を強制(推奨)/ False=テキスト出力から抽出
    generate_negativeBOOLEANtrueTrue=negative_prompt も生成させる
    seedINT-1-1–18446744073709550000-1 = 実行のたびにランダム
    max_tokensoptINT40961–131072—
    temperatureoptFLOAT0.700–2—
    auto_unloadoptBOOLEANfalse生成後にモデルをアンロードする(unload_delay=0 のとき即時)
    unload_delayoptINT00–3600auto_unload 有効時、最後の利用からこの秒数後にアンロード(TTL)。0=即時
    timeout_secondsoptINT30010–3600—
    strip_thinkingoptBOOLEANtrueraw_text から思考ブロックを除去する
    debugoptBOOLEANfalse—

    Outputs (5)

    NameTypeDescription
    promptSTRING—
    negative_promptSTRING—
    raw_textSTRING—
    method_usedSTRING—
    successBOOLEAN—