ComfyUI Node

LM Studio Query

Turn your local LLM into a prompt-writer and image captioner, no API key required

By Pirog17000·Created about a year ago·Updated 10 months ago· 3
LM Studio Query
  • images
  • generated_texts
  • model_ref
system_promptYou are a helpful assistant.
user_promptDescribe this image in detail.
model_name
server_urlhttp://localhost:1234
temperature0.70
max_tokens256
top_p0.90
seed0
prompts_number1
unload_after_usefalse

Want an LLM inside your workflow without paying for an API? LM Studio Query talks to a local LM Studio server - which is just your own GPU running an OpenAI-compatible endpoint at http://localhost:1234 - and can do two genuinely useful things. First, pure text generation: feed it a template prompt and it writes a finished prompt for your sampler. Second, vision: attach images and it describes them, which makes it a batch captioner for training data or a "what did it actually generate" inspector. No key, no cloud, no monthly bill.

How it works

The node hits LM Studio's /v1/models endpoint to list what's loaded and available, then sends your system_prompt and user_prompt to the chat completions endpoint. If you give model_name (full or partial), it loads that model first; leave it blank and it uses whatever's currently loaded. Images get base64-encoded and sent along, so a vision-capable model can describe them. prompts_number runs the query multiple times with different seeds - handy for getting several prompt drafts to pick from - and unload_after_use frees the model from memory when done.

The inputs that matter

  • system_prompt / user_prompt - the usual LLM pair. The defaults ("You are a helpful assistant." / "Describe this image in detail.") are fine starting points.
  • server_url - http://localhost:1234 unless you changed LM Studio's port.
  • model_name - leave empty for the loaded model; otherwise a name or substring to load.
  • temperature, top_p, max_tokens, seed - standard sampling knobs. 0.7 / 0.9 / 256 defaults are sensible.
  • prompts_number - how many generations (1–10).
  • images - optional IMAGE input; supports batches, so you can caption several images in one run.

Outputs: generated_texts (the responses, as a list if you asked for more than one) and model_ref (the model that actually ran - handy if you want to feed it into the unload node).

Installing it

Install the pack, and make sure LM Studio is actually serving:

cd ComfyUI/custom_nodes
git clone https://github.com/Pirog17000/Pirogs-Nodes
pip install -r Pirogs-Nodes/requirements.txt

In LM Studio: enable the local server (Settings → Server, default port 1234) and load a model. The lmstudio package in requirements.txt is technically only needed for unloading; the query node itself just needs requests.

Gotchas

Most failures here are "LM Studio isn't actually running" - the node errors out if it can't reach /v1/models in a couple of seconds. If you specified a model name and it's not in the server's list, you get a "not found" error. Vision queries silently degrade if your model isn't multimodal, so check which model you loaded. And remember the output is text: you still need to wire generated_texts into your prompt or a text-encode node - this node writes prompts, it doesn't apply them.

Categorypirog/ai

Inputs (11)

NameTypeDefaultDescription
system_promptSTRINGYou are a helpful assistant.System prompt to set the AI's behavior and role
user_promptSTRINGDescribe this image in detail.User prompt for the query. Use with images for descriptions or standalone for text generation.
model_nameSTRINGModel name or partial name to search for. Leave empty to use currently loaded model.
server_urlSTRINGhttp://localhost:1234LM Studio server URL
temperatureFLOAT0.700–2Sampling temperature (0.0 = deterministic, 2.0 = very random)
max_tokensINT2561–4096Maximum number of tokens to generate
top_pFLOAT0.900–1Nucleus sampling parameter
seedINT00–18446744073709550000Random seed for reproducible results. 0 = random each time.
prompts_numberINT11–10Number of prompts to generate with different seeds
unload_after_useBOOLEANfalseUnload the model after processing to free memory
imagesoptIMAGEOptional images for visual queries (batch processing supported)

Outputs (2)

NameTypeDescription
generated_textsSTRINGArray of generated text responses
model_refSTRINGReference to the loaded model name