ComfyUI Node

FEGenStringGPT

Generate prompts from any OpenAI-compatible API

By fexli·Created 3 years ago·Updated about a year ago· 3
FEGenStringGPT
    • prompt
    • generate_ctx
    system_promptYou are ChatGPT, a large language model trained by OpenAI.
    user_promptHello World!
    modelgpt-4
    api
    temperature1.00
    presence_penalty0.00
    max_tokens2048
    async_inferNO

    The name says GPT, but the honest description is "LLM prompt generation for anyone." FEGenStringGPT takes a system prompt and a user prompt, calls a chat/completions endpoint, and streams back a full prompt string you can drop straight into a CLIP text encode. LLM-assisted prompt writing has been a ComfyUI staple since the first "Custom Prompt Generation Node using ChatGPT" appeared in late 2023, and this is that idea done cleanly - the key being that the endpoint is configurable, not glued to OpenAI.

    The api dropdown is actually built from your config.yaml - the openai_host list. That's the detail that makes this node more useful than it looks: any OpenAI-compatible server works. LM Studio, Ollama's OpenAI shim, vLLM, a proxy, or the real OpenAI API are all just entries in that list, and the node's dropdown fills itself from it. Same for the key: openai_key in the config becomes the Authorization header, and if it's empty, no header is sent - which is exactly right for local servers that don't want one. Real OpenAI needs a key; your local model doesn't.

    The inputs that matter

    • system_prompt - the instructions, defaulting to the stock "You are ChatGPT…". This is where you tell the model how to write image prompts.
    • user_prompt - your raw idea.
    • model - a free-text string, default gpt-4; type whatever your endpoint supports.
    • api - the dropdown from openai_host in config.yaml.
    • temperature (default 1.0), presence_penalty, max_tokens (2048).
    • async_infer - YES/NO; NO blocks and streams the full reply, YES returns an empty string plus a generate_ctx (GPT_GEN_CTX) for deferred handling.

    Outputs: prompt (STRING) and generate_ctx.

    Setting it up

    Create config.yaml in the pack's config/ folder (the pack copies the example automatically on first load) and restart:

    openai_key: <your key, or leave blank for local servers>
    openai_host:
      - https://api.openai.com/v1/chat/completions
      - http://127.0.0.1:1234/v1/chat/completions   # e.g. LM Studio
    

    Then install the pack the usual way (ComfyUI Manager → search fexli-util-node-comfyui, or git clone into custom_nodes + pip install -r requirements.txt), restart, and the new hosts show up in the dropdown.

    Where people get burned: config edits require a restart - the config is read once at import, so adding a host while ComfyUI is running does nothing until you relaunch. And streaming replies mean the node blocks your queue for the duration of the generation; if your server is slow, the whole graph waits. That's also why async_infer exists. Watch the ComfyUI console, too - that's where retry/error tracebacks land, not in the UI.

    It's the node from this pack I'd actually put in a workflow: real LLM prompt expansion against whatever server you already run, no lock-in. The "BC" nodes are tied to the author's infra; this one works with yours.

    Categoryfexli/generate

    Inputs (8)

    NameTypeDefaultDescription
    system_promptSTRINGYou are ChatGPT, a large language model trained by OpenAI.
    user_promptSTRINGHello World!
    modelSTRINGgpt-4
    apiCOMBO1 options: https://api.openai.com/v1/chat/completions
    temperatureFLOAT1.000–2
    presence_penaltyFLOAT0.000–10
    max_tokensINT20480–2048
    async_inferCOMBONO2 options: YES, NO

    Outputs (2)

    NameTypeDescription
    promptSTRING
    generate_ctxGPT_GEN_CTX