Nodes/ComfyUI_LiteLLM/ModifyModelKwargs
ComfyUI Node

ModifyModelKwargs

ModifyModelKwargs tweaks your model call

By Hopping-Mad-Games·Created 2 years ago·Updated 11 months ago· 7
ModifyModelKwargs
  • model
  • kwargs
  • Litellm model
json_str_of_kwargs{}

Picking the model is only half the setup. The other half is the per-call settings - temperature, max tokens, top_p, and the rest - and that's where ModifyModelKwargs comes in. It sits between your model provider and your completion node, letting you inject or override those settings on a LITELLM_MODEL as it flows through the graph.

Think of the LITELLM_MODEL value as a little envelope that carries both "which model" and "what settings." This node is how you stuff extra settings into that envelope without hand-editing JSON inside the completion node.

How it works

Three inputs, one real output:

  • model (required, LITELLM_MODEL) - the envelope you're modifying, straight from LiteLLMModelProvider.
  • kwargs (optional, DICT) - a dict of settings, if another node hands you one.
  • json_str_of_kwargs (optional, STRING, multiline, default {}) - the same settings as a JSON string, which is the format you'll actually type most of the time.

The output Litellm model (LITELLM_MODEL) is your modified envelope, ready for a completion node.

Mechanically: if json_str_of_kwargs isn't "{}", it's parsed as JSON and replaces the kwargs input entirely (the JSON wins - keep that in mind if both are connected). The merged settings land in the model's kwargs, and there's a small bonus: if logit_bias is passed as a list of (token_id, bias) pairs, it's converted to the dict format the OpenAI-style APIs expect.

So, concretely:

LiteLLMModelProvider → ModifyModelKwargs (json_str_of_kwargs: {"temperature": 0.7, "max_tokens": 512}) → LiteLLMCompletion

What you'd actually set

  • temperature - lower for predictable caption/structured output, higher for creative writing.
  • max_tokens - cap the reply length.
  • top_p, frequency_penalty, presence_penalty - the usual LLM sampler dials, passed through to whatever provider the model string names.

Which keys are honored depends on the provider behind the model - Anthropic and OpenAI accept slightly different sets, and LiteLLM does its best to translate. Unknown keys generally get ignored or warn rather than hard-fail, but don't assume a key works everywhere.

Where people trip

  • The JSON wins. Wire both inputs and the string silently overrides the dict. If your settings aren't taking effect, check whether json_str_of_kwargs is still holding a default you forgot about.
  • Default {} isn't "empty" in the override check. The node checks whether the string equals "{}" exactly. Set it to {} with whitespace ({ }) or a trailing newline and it counts as a real value that wipes your kwargs dict. Minor, but it's bitten people.
  • Order matters for chaining. You can daisy-chain multiple ModifyModelKwargs nodes to override specific settings per branch - later ones in the chain update the same kwargs dict. Handy for fan-out workflows where one branch wants temperature 0 and another wants 1.2.

Installing

Pack-level install as always: ComfyUI Manager → search "LiteLLM" (repo Hopping-Mad-Games/ComfyUI_LiteLLM) → Install → Restart, or clone into ComfyUI/custom_nodes and pip install -r requirements.txt. The requirements pull in litellm, boto3, sentence-transformers and a LightRAG fork, so expect a heavy first install. No API keys needed here - the keys are consumed downstream by the completion node.

Bottom line

It's the "settings node" the pack needs because the model envelope is otherwise opaque. If you're the kind of person who tweaks temperature per workflow, this is where you'll live. Just remember the JSON-wins rule and the exact-{} check, and it'll do what you expect.

CategoryETK/LLM/LiteLLM

Inputs (3)

NameTypeDefaultDescription
modelLITELLM_MODELanthropic/claude-3-haiku-20240307
kwargsoptDICT[object Object]
json_str_of_kwargsoptSTRING{}

Outputs (1)

NameTypeDescription
Litellm modelLITELLM_MODEL