Nodes/ComfyUI-A5Nodes/A5lmstudio_prompt_enhancer
ComfyUI Node

A5lmstudio_prompt_enhancer

A local LLM enhancer that gets out of your VRAM's way

By A5Projects·Created 3 days ago·Updated 3 days ago· 1
A5lmstudio_prompt_enhancer
  • image
  • enhanced_prompt
system_promptEnhance the user's image-generation prompt. Keep the core idea, add useful visual details, and return only the improved prompt.
input_promptA cinematic portrait of a fox in a rainy neon city
run_modeAuto bypass if unchanged
unload_comfy_models_before_llm_runtrue
last_generated_prompt
modelUse loaded default model
load_model_before_generationtrue
unload_model_after_generationtrue
server_urlhttp://localhost:1234/v1
api_token
max_tokens12000

Two models, one GPU. That's the whole problem with running a local LLM next to a diffusion model, and this node is built around solving it: it talks to LM Studio (or any OpenAI-compatible server) at localhost, and it unloads ComfyUI's models first so nothing has to share the card.

The name is refreshingly literal. It does not call a cloud API, and it needs no key for the basic job.

You give it a system prompt, a user prompt, and optionally an image. It POSTs a chat completion to your local server, strips thinking blocks out of the reply, and returns the text as enhanced_prompt - a STRING you wire into any text input in your graph.

Local, uncensored, free per call. An 8B model is not a better writer than a frontier API; it's one that runs offline and won't refuse your prompt. The job here is short structured rewriting, which is what small models are good at.

The three run modes (and the "intelligent" one)

run_mode gives you Always run LLM, Bypass - send last/manual prompt, and Auto bypass if unchanged.

Auto is the interesting one. The node fingerprints your system prompt, input prompt, the image if there is one, and the selected model, then stores that fingerprint next to the prompt it produced. Nothing changed? It skips the server and returns the stored text. Change any of those and the LLM runs again.

Bypass is a full stop: no request, just whatever's in last_generated_prompt. Because that field is a normal multiline widget, you can edit it by hand - and manual edits are ignored by the bypass check, which is why the author describes using it as his main prompt box. If all you want is a widget holding your last good prompt while you tweak it, bypass mode is a legitimate use of the node.

The VRAM switches

This is the part that made the node worth keeping.

  • unload_comfy_models_before_llm_run (on by default) calls ComfyUI's own unload_all_models() plus soft_empty_cache() - but only when a real LLM request is about to happen. Bypass modes skip it.
  • load_model_before_generation loads the selected LM Studio model first, and unload_model_after_generation evicts it once the answer comes back. Both default on. Both require LM Studio's API token, and both are ignored when model is set to Use loaded default model.

Leave the three on and the two models take turns instead of fighting. That's the pattern the good local-LLM nodes all converge on.

Inputs you'll actually set

  • server_url - defaults to http://localhost:1234/v1, which is LM Studio out of the box. The node normalizes it, so trailing paths and a pasted /chat/completions don't break it.
  • model - a dropdown of recent models, with the loaded-default option on top. Recent models are remembered across sessions.
  • api_token - the field shows XXXXXXXX once a token is saved. Only needed if your server requires one, but load/unload does require one, and LM Studio's own settings have to allow it.
  • max_tokens - 12000 by default. Thinking models count their thinking against this even though the node strips it from the output, so budget accordingly.
  • image (optional) - sends the picture with the prompt. That needs a vision model actually loaded; the list's [vision?] labels are an educated guess, not a fact.

Output is the single enhanced_prompt STRING.

Installing it

Same pack, nine nodes. Install once.

cd ComfyUI/custom_nodes
git clone https://github.com/A5Projects/ComfyUI-A5Nodes

Restart and refresh, or install A5 Custom Nodes from ComfyUI Manager - pick the numbered release, not Nightly. No Python dependencies, no downloaded weights; the LM Studio server is a separate application you run yourself. Because this node's whole value is its UI, take the README's Firefox note seriously: classic node mode in both browsers, and avoid Nodes 2.0 in Firefox unless you enjoy resizing nodes by accident.

Where it breaks

No model loaded, no answer. If LM Studio has nothing loaded and you're on the loaded-default option, the server returns an error. That's LM Studio's behavior, not the node's.

Other servers are second-class. Any OpenAI-compatible endpoint can serve the chat completion, but the load/unload calls use LM Studio's native API. Point this at Ollama or llama.cpp and the enhancement may work while the VRAM management quietly doesn't.

Your token is stored in plain text. The node masks it in the UI and writes it to a JSON file under ComfyUI's user directory (A5-Nodes/lmstudio_credentials.json). If you share your user folder, you shared your token.

Long waits look like hangs. The completion timeout is an hour, responses are non-streaming, so a big model on a small card looks frozen. There's an abort path in the UI that unloads the model instead of waiting it out.

One caveat that applies to every enhancer: local models drift on subject just as happily as hosted ones.

Categoryutils/LM Studio

Inputs (12)

NameTypeDefaultDescription
system_promptSTRINGEnhance the user's image-generation prompt. Keep the core idea, add useful visual details, and return only the improved prompt.
input_promptSTRINGA cinematic portrait of a fox in a rainy neon city
run_modeCOMBOAuto bypass if unchanged3 options: Always run LLM, Bypass - send last/manual prompt, Auto bypass if unchanged
unload_comfy_models_before_llm_runBOOLEANtrueUnload ComfyUI models from VRAM before a real LLM request. Bypass modes skip this.
last_generated_promptSTRINGPrompt returned by bypass modes; normal LLM runs overwrite it.
modelCOMBOUse loaded default modelRecent models listed first - For loading of models, except Loaded Default, LMStudio requires authentication with API token
load_model_before_generationBOOLEANtrueLoad the selected LM Studio model before generation. Requires API token. Ignored when Use loaded default model is selected.
unload_model_after_generationBOOLEANtrueUnload the selected LM Studio model after generation. Requires API token. Ignored when Use loaded default model is selected.
server_urlSTRINGhttp://localhost:1234/v1
api_tokenSTRINGOnly needed when LMStudio/Server is set to require it
max_tokensINT120001–32768Set higher for thinking models -thinking is cut but still counts
imageoptIMAGE

Outputs (1)

NameTypeDescription
enhanced_promptSTRING