ComfyUI Node

MTCLIPEncode

Type your prompt in your own language — MTCLIPEncode translates it, and Ollama makes it pretty

By Marksusu·Created 2 years ago·Updated about a year ago· 9
MTCLIPEncode
  • clip
  • CONDITIONING
  • STRING
checkpointopus-mt-zh-en
text prefix | translate_part | suffix
ollama_urlhttp://127.0.0.1:11434
ollama_modelmistral-nemo:latest

The honest pitch is one sentence: MTCLIPEncode is a drop-in replacement for the stock CLIPTextEncode that translates your prompt into English first, and optionally hands it to a local Ollama LLM to make the English prettier. Type 活泼的女孩 in, get a proper English prompt encoded into conditioning - without breaking the LoRA tags you wanted kept fixed.

If you already prompt in English, this node is a pass-through and you can stop reading. It does nothing without its markers. Its real home is two places: CLIP-era models (SD 1.5/SDXL/Illustrious, where English tags are what the encoder actually understands), and Krita AI Diffusion, which is literally what the author built it for. Krita's preset style prompts come with a fixed prefix and suffix of LoRA tags and style phrases; a naive translator would chew those up. This node's whole design is about not doing that.

How it works

Two local models, one per job. MarianMT (the Helsinki-NLP opus-mt-* family) does the translation - a purpose-built neural machine translation model, not an LLM. That's the point: it's deterministic and boring, so you won't get an LLM that "translates" your Chinese into confident-sounding gibberish. Ollama does the embellishment, fed a "you are a prompt engineer, enclose your output in # symbols" prompt.

The text field is the interface, and it has a tiny grammar. The default value is literally prefix | translate_part | suffix - a hint, not filler. The rules:

  • |...| wraps the part to translate. Prefix and suffix pass through untouched.
  • ! invokes Ollama. One ! with no || → the whole prompt gets "optimized." Two ! → only what's between them. A ! inside the || → only the translated part gets enhanced, then recombined with your intact prefix/suffix. A ! outside the || → everything gets enhanced after reassembly.

Both run locally and talk to nothing in the cloud. The Marian model downloads from HuggingFace on first use (a few hundred MB per language, on CPU), and Ollama is a separate program you must keep running.

The inputs and outputs that matter

Only a handful, and three of them have sane defaults:

  • text (multiline) - your prompt plus the | / ! markers. This is the one you actually type.
  • checkpoint - which translation model; 15 language pairs in a dropdown, default opus-mt-zh-en. Pick e.g. opus-mt-ru-en for Russian.
  • ollama_url / ollama_model - default to http://127.0.0.1:11434 and mistral-nemo:latest. Only touch these if you changed Ollama's setup or want a different model.
  • clip - wire from your checkpoint loader, same as stock CLIPTextEncode.

Outputs: a CONDITIONING that plugs into the sampler exactly like the stock node's (it even returns pooled output, so SDXL-lineage models behave), plus a STRING of the final processed prompt. That second output is worth wiring to a text preview: what you typed is almost never what actually gets encoded.

Installing it

ComfyUI Manager (search "ComfyUI_MTCLIPEncode"), or the old-fashioned way:

cd ComfyUI/custom_nodes
git clone https://github.com/Marksusu/ComfyUI_MTCLIPEncode

Restart ComfyUI. It needs transformers, requests, and ollama (from the pack's requirements.txt) - and if you want the ! features, a running Ollama: ollama pull mistral-nemo:latest. First translation run downloads the model; that's the "why is my queue stuck" moment.

To use it inside Krita AI Diffusion, the README's instructions are to edit pykrita/ai_diffusion/comfy_workflow.py and swap self.add("CLIPTextEncode", ...) for self.add("MTCLIPEncode", ...) with the checkpoint and ollama args. That's the design intent, borrowed from a krita-ai-diffusion discussion (#867).

Where people get burned

The author is unusually honest about the main failure mode: Ollama is flaky. Some models return empty responses or answer in the wrong language, and the README has a screenshot of exactly that. The node's parser also expects the #...# wrapping the system prompt asks for; a model that ignores the convention returns raw text that can be messy. mistral-nemo is the tested default - if you switch, test the output once before trusting it.

Two quieter traps. If Ollama isn't running, the enhancement doesn't crash the node - it silently falls back to translation-only and logs Failed to optimize prompt with Ollama in the console. Easy to miss. And if you put only short English words between the ||, the node decides there's nothing to translate and just stitches prefix + suffix, dropping the middle. The |/! grammar is fiddly - you will paste the README's example table into your own chat - but it exists because Krita's preset prompts genuinely must not be rewritten. Annoying, yes. Pointless, no.

CategoryMTCLIPEncode

Inputs (5)

NameTypeDefaultDescription
clipCLIP
checkpointCOMBOopus-mt-zh-en15 options: opus-mt-zh-en, opus-mt-ru-en, opus-mt-th-en, opus-mt-es-en, opus-mt-fr-en, opus-mt-ar-en, +9
textSTRING prefix | translate_part | suffix
ollama_urlSTRINGhttp://127.0.0.1:11434
ollama_modelSTRINGmistral-nemo:latest

Outputs (2)

NameTypeDescription
CONDITIONINGCONDITIONING
STRINGSTRING