Repository navigation
feat(server): accept seed in OpenAI image requests #2527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,9 @@ static bool build_openai_generation_request(const httplib::Request& req, | |
| request.gen_params.width = width; | ||
| request.gen_params.height = height; | ||
| request.gen_params.batch_count = n; | ||
| if (j.contains("seed") && j["seed"].is_number_integer()) { | ||
| request.gen_params.seed = j["seed"].get<int64_t>(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seeds above A JSON
|
||
| } | ||
|
|
||
| std::string sd_cpp_extra_args_str = extract_and_remove_sd_cpp_extra_args(request.gen_params.prompt); | ||
| if (!sd_cpp_extra_args_str.empty() && !request.gen_params.from_json_str(sd_cpp_extra_args_str)) { | ||
|
|
@@ -119,6 +122,14 @@ static bool build_openai_edit_request(const httplib::Request& req, | |
| } | ||
| } | ||
|
|
||
| std::optional<int64_t> seed; | ||
| if (req.form.has_field("seed")) { | ||
| try { | ||
| seed = std::stoll(req.form.get_field("seed")); | ||
| } catch (...) { | ||
| } | ||
| } | ||
|
|
||
| std::string size = req.form.get_field("size"); | ||
| auto width = runtime.default_gen_params->width; | ||
| auto height = runtime.default_gen_params->height; | ||
|
|
@@ -152,6 +163,9 @@ static bool build_openai_edit_request(const httplib::Request& req, | |
| request.gen_params.width = width; | ||
| request.gen_params.height = height; | ||
| request.gen_params.batch_count = n; | ||
| if (seed.has_value()) { | ||
| request.gen_params.seed = seed; | ||
| } | ||
|
|
||
| std::string sd_cpp_extra_args_str = extract_and_remove_sd_cpp_extra_args(request.gen_params.prompt); | ||
| for (auto& bytes : images_bytes) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omitted
seeduses the server's--seedvalue, not random.When the server starts with
--seed Nand N is nonnegative, a request that omitsseedreuses N. The request copies the server defaults and keeps that value. The table says omitted means random, which is wrong for this configuration. The table must state the server default. A negative request value still requests a random seed.Suggested fix
Apply the same wording to the
seedrow of the edits table at line 483.