mirror of
https://github.com/mudler/LocalAI.git
synced 2026-09-21 05:34:56 -04:00
feat(openai): add negative_prompt field to image generation request (#12031)
Expose a negative_prompt string parameter on the image endpoints, matching Stable Diffusion WebUI / vLLM-Omni conventions. When both the negative_prompt parameter and a '|'-suffixed negative prompt in the main prompt are present, they are joined with a comma so callers can keep a global negative prompt in negative_prompt and add per-image negative tags after '|'. Assisted-by: Pi: DeepSeek V4 Pro Signed-off-by: Fedor Zuev <Fedor.Zuev@gmail.com>
This commit is contained in:
3 files changed
+11
-4
No files matched your search
@@ -160,9 +160,12 @@ func ImageEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfi
|
||||
for range n {
|
||||
prompts := strings.Split(i, "|")
|
||||
positive_prompt := prompts[0]
|
||||
negative_prompt := ""
|
||||
negative_prompt := strings.TrimSpace(input.NegativePrompt)
|
||||
if len(prompts) > 1 {
|
||||
negative_prompt = prompts[1]
|
||||
if negative_prompt != "" {
|
||||
negative_prompt += ", "
|
||||
}
|
||||
negative_prompt += strings.TrimSpace(prompts[1])
|
||||
}
|
||||
|
||||
step := config.Step
|
||||
|
||||
@@ -210,6 +210,10 @@ type OpenAIRequest struct {
|
||||
Size string `json:"size,omitempty"`
|
||||
// Prompt is read only by completion/image API calls
|
||||
Prompt any `json:"prompt,omitempty" yaml:"prompt"`
|
||||
// NegativePrompt for image generation (matches Stable Diffusion WebUI /
|
||||
// vLLM-Omni conventions). Combined, comma-separated, with any "|"-suffixed
|
||||
// negative tags in Prompt.
|
||||
NegativePrompt string `json:"negative_prompt,omitempty" yaml:"negative_prompt"`
|
||||
|
||||
// Edit endpoint
|
||||
Instruction string `json:"instruction,omitempty" yaml:"instruction"`
|
||||
|
||||
@@ -24,9 +24,9 @@ curl http://localhost:8080/v1/images/generations -H "Content-Type: application/j
|
||||
}'
|
||||
```
|
||||
|
||||
Available additional parameters: `mode`, `step`.
|
||||
Available additional parameters: `mode`, `step`, `negative_prompt`.
|
||||
|
||||
Note: To set a negative prompt, you can split the prompt with `|`, for instance: `a cute baby sea otter|malformed`.
|
||||
To set a negative prompt you can either pass a separate `negative_prompt` field or split the prompt with `|`, e.g. `a cute baby sea otter|malformed`. When both are present they are joined with a comma (`negative_prompt` first, then the `|`-suffixed tags), so a global negative prompt can live in `negative_prompt` while per-image negatives are appended after `|`.
|
||||
|
||||
```bash
|
||||
curl http://localhost:8080/v1/images/generations -H "Content-Type: application/json" -d '{
|
||||
|
||||
Reference in new issue
Block a user