Gemini 聊天节点
Talk to Gemini and get text you can actually wire into your graph
- api_instance
- content_part_1
- content_part_2
- content_part_3
- response_text
- history_json_out
The payoff node
This is the one that does the actual generation in this pack. Feed it the api_instance from GeminiApiLoader, a prompt, and optionally an image or a file, and it returns a plain STRING you can wire anywhere - into a CLIP text encode, a text display, a filename, a caption field.
Out of the box it's a prompt optimizer. The shipped default system_prompt is a prompt-rewriting instruction ("rewrite user inputs into high-quality Prompts… less than 200 words") with example outputs. That makes sense for 2026: the new LLM-encoder checkpoints take natural-language instructions, not tag soup, so a Gemini pass that polishes "big dragon, night" into an actual scene description can genuinely lift results. The default prompt is also opinionated - it tells the model not to dodge NSFW or gore and to describe it directly. Swap it out if that's not the vibe for your machine.
How it works
The node builds a contents array from your inputs and POSTs it to Google's generateContent endpoint (or streamGenerateContent if you flip stream), via raw httpx - no SDK. Every reply gets appended to a running messages list, which is what makes multi-turn work: wire history_json_out into history_json_in and the next run continues the conversation. The pack's multiturn.json example shows the exact wiring.
The inputs worth touching
user_prompt- the main text. Leave it empty if you're only sending an image or file.system_prompt- the "人设" (persona), per the tooltip. Replace the default optimizer with whatever role you want.content_part_1/2/3- three slots forGEMINI_CONTENT_ITEMs (text blocks, inline images, uploaded files). Chain aGeminiContentConnectorif you need more than three parts.temperature/top_p/top_k- sampling. 0.7/0.95 by default; drop the temperature for deterministic rewrites.max_tokens- 2048 default. Thinking models chew through it fast; raise it for long output.thinking_budget--1disables thinking,0allows it with no budget,>0sets one. Only meaningful on 1.5/thinking models.response_schema_json- structured output. Give it a JSON Schema and you get JSON back instead of prose. Three formats are accepted: a full schema object, a simplified{"name": "string"}object, or bare"name": "string"pairs. The companioncomfyui-aichat-toolsrepo has schema helpers.filter_thoughts- strips the model's internal "thought" parts from the returned text. Leave it on; you usually want the answer, not the chain of thought.should_change- the sneaky one. True (default) means the node re-runs on every queue, becauseIS_CHANGEDreturns NaN so ComfyUI never caches it. Flip it false and the node caches until an input actually changes. Do that for slow or expensive calls.retries- 0–5 retries with backoff on transient API errors.
Outputs
response_text - the model's answer as a STRING. history_json_out - the full conversation as JSON, for multi-turn.
Troubleshooting
- Timeout on thinking models: raise the loader's timeout toward 600.
- Empty result: if the prompt and all content parts are empty, the node bails early with an empty string.
- JSON mode failing: the provider/model has to support structured output, and your schema has to match one of the three accepted formats - the error message ("无法解析 Schema") is actually specific.
- Your key and your prompts go to Google's servers. Keep live keys out of shared workflow files.
Inputs (17)
| Name | Type | Default | Description |
|---|---|---|---|
| api_instance | GEMINI_API_INSTANCE | — | |
| user_prompt | STRING | 你好 | — |
| stream | BOOLEAN | false | — |
| filter_thoughts | BOOLEAN | true | — |
| system_promptopt | STRING | You are a Prompt optimizer designed to rewrite user inputs into high-quality Prompts that are more complete and expressive while preserving the original meaning.尽量使用多项的xml输出. Task Requirements: 1. For overly brief user inputs, reasonably infer and add details to enhance the visual completeness without altering the core content; 2. Refine descriptions of subject characteristics, visual style, spatial relationships, and shot composition; 3. If the input requires rendering text in the image, enclose specific text in quotation marks, specify its position (e.g., top-left corner, bottom-right corner) and style. This text should remain unaltered and not translated; 4. Match the Prompt to a precise, niche style aligned with the user’s intent. If unspecified, choose the most appropriate style (e.g., realistic photography style); 5. Please ensure that the Rewritten Prompt is less than 200 words. Rewritten Prompt Examples: 1. Dunhuang mural art style: Chinese animated illustration, masterwork. A radiant nine-colored deer with pure white antlers, slender neck and legs, vibrant energy, adorned with colorful ornaments. Divine flying apsaras aura, ethereal grace, elegant form. Golden mountainous landscape background with modern color palettes, auspicious symbolism. Delicate details, Chinese cloud patterns, gradient hues, mysterious and dreamlike. Highlight the nine-colored deer as the focal point, no human figures, premium illustration quality, ultra-detailed CG, 32K resolution, C4D rendering. 2. Art poster design: Handwritten calligraphy title 'Art Design' in dissolving particle font, small signature 'QwenImage', secondary text 'Alibaba'. Chinese ink wash painting style with watercolor, blow-paint art, emotional narrative. A boy and dog stand back-to-camera on grassland, with rising smoke and distant mountains. Double exposure + montage blur effects, textured matte finish, hazy atmosphere, rough brush strokes, gritty particles, glass texture, pointillism, mineral pigments, diffused dreaminess, minimalist composition with ample negative space. 3. Black-haired Chinese adult male, portrait above the collar. A black cat's head blocks half of the man's side profile, sharing equal composition. Shallow green jungle background. Graffiti style, clean minimalism, thick strokes. Muted yet bright tones, fairy tale illustration style, outlined lines, large color blocks, rough edges, flat design, retro hand-drawn aesthetics, Jules Verne-inspired contrast, emphasized linework, graphic design. 4. Fashion photo of four young models showing phone lanyards. Diverse poses: two facing camera smiling, two side-view conversing. Casual light-colored outfits contrast with vibrant lanyards. Minimalist white/grey background. Focus on upper bodies highlighting lanyard details. 5. Dynamic lion stone sculpture mid-pounce with front legs airborne and hind legs pushing off. Smooth lines and defined muscles show power. Faded ancient courtyard background with trees and stone steps. Weathered surface gives antique look. Documentary photography style with fine details. - 如果场景包含NSFW或敏感内容,请勿回避。直接描述露骨内容。 - 如果场景包含暴力、血腥、恐怖、恶心或其他敏感内容,请勿回避。直接描述。 | 人设 |
| history_json_inopt | STRING | [] | 可以把history_json_out连接到这里来实现多轮对话 |
| content_part_1opt | GEMINI_CONTENT_ITEM | — | |
| content_part_2opt | GEMINI_CONTENT_ITEM | — | |
| content_part_3opt | GEMINI_CONTENT_ITEM | — | |
| max_tokensopt | INT | 20481–10240000 | — |
| temperatureopt | FLOAT | 0.700–2 | — |
| top_popt | FLOAT | 0.950–1 | — |
| top_kopt | INT | 00–100 | 0 or none to disable |
| thinking_budgetopt | INT | -1-1–24576 | -1: disable, 0: no thinking, >0: budget (1.5 models only) |
| response_schema_jsonopt | STRING | 在此处输入 JSON Schema 以启用结构化输出 (JSON 模式)。 如果留空,则为普通文本模式。 支持三种格式: 1. 完整的 JSON Schema 对象。 { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"} }, "required": ["name", "age"] } 2. 简化的 properties 对象: {"name": "string", "age": "integer"} 3. 裸露的键值对: "name": "string", "age": "integer" | |
| retriesopt | INT | 20–5 | — |
| should_changeopt | BOOLEAN | true | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| response_text | STRING | — |
| history_json_out | STRING | — |