From fe4d1170553c88e0c3707dfb52b42705dad04507 Mon Sep 17 00:00:00 2001 From: grencez Date: Sun, 21 Jun 2026 20:01:18 -0700 Subject: [PATCH] feat: add --prompt-file and --negative-prompt-file flags as an alternative to passing long strings to the --prompt and --negative-prompt flags. --- examples/common/common.cpp | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/examples/common/common.cpp b/examples/common/common.cpp index ad3f97a08..ba6ae67ff 100644 --- a/examples/common/common.cpp +++ b/examples/common/common.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -1415,6 +1416,42 @@ ArgOptions SDGenerationParams::get_options() { return 1; }; + auto on_prompt_file_arg = [&](int argc, const char** argv, int index) { + if (++index >= argc) { + return -1; + } + const char* arg = argv[index]; + std::ifstream f(arg, std::ios::binary); + try { + prompt = std::string(std::istreambuf_iterator{f}, {}); + } catch (const std::ios_base::failure&) { + f.setstate(std::ios_base::failbit); + } + if (f.fail()) { + LOG_ERROR("error: failed to read prompt file '%s'\n", arg); + return -1; + } + return 1; + }; + + auto on_negative_prompt_file_arg = [&](int argc, const char** argv, int index) { + if (++index >= argc) { + return -1; + } + const char* arg = argv[index]; + std::ifstream f(arg, std::ios::binary); + try { + negative_prompt = std::string(std::istreambuf_iterator{f}, {}); + } catch (const std::ios_base::failure&) { + f.setstate(std::ios_base::failbit); + } + if (f.fail()) { + LOG_ERROR("error: failed to read negative prompt file '%s'\n", arg); + return -1; + } + return 1; + }; + options.manual_options = { {"-s", "--seed", @@ -1478,6 +1515,14 @@ ArgOptions SDGenerationParams::get_options() { "--vae-relative-tile-size", "relative tile size for vae tiling, format [X]x[Y], in fraction of image size if < 1, in number of tiles per dim if >=1 (overrides --vae-tile-size)", on_relative_tile_size_arg}, + {"", + "--prompt-file", + "path to the file containing the prompt to render", + on_prompt_file_arg}, + {"", + "--negative-prompt-file", + "path to the file containing the negative prompt", + on_negative_prompt_file_arg}, };