pass in style - fix placeholder

This commit is contained in:
welabbar 2025-02-13 05:10:37 +00:00
parent c1d9da00a7
commit be2e5eefb5

View file

@ -3,7 +3,7 @@ title: LiteLLM Stable Diffusion Image Generation Action
author: Wanis Elabbar author: Wanis Elabbar
author_url: https://github.com/elabbarw author_url: https://github.com/elabbarw
date: 2025-02-12 date: 2025-02-12
version: 0.1.1 version: 0.1.2
license: MIT license: MIT
description: This action generates an image using SD models deployed on AWS Bedrock and presented via LiteLLM. description: This action generates an image using SD models deployed on AWS Bedrock and presented via LiteLLM.
""" """
@ -31,7 +31,7 @@ class Action:
default="your_api_key_here", description="Required API key for LiteLLM" default="your_api_key_here", description="Required API key for LiteLLM"
) )
LITELLM_IMAGE_URL: str = Field( LITELLM_IMAGE_URL: str = Field(
default="https://[your litellm gateway].com/image/generations", default="https://[your litellm gateway].com/images/generations",
description="LiteLLM Endpoint image generation", description="LiteLLM Endpoint image generation",
) )
pass pass
@ -44,11 +44,11 @@ class Action:
### Put LiteLLM names here ### Put LiteLLM names here
self.modelnames = { self.modelnames = {
"sdxl": "", "sdxl": "eit_sdxl",
"core": "", "core": "eit_sdcore",
"large3": "", "large3": "eit_sd3large",
"ultra": "", "ultra": "eit_sdultra",
"large35": "", "large35": "eit_sd35large",
} }
pass pass
@ -96,7 +96,7 @@ class Action:
"type": "input", "type": "input",
"data": { "data": {
"title": "Enter the SD Model (sdxl, core, large3, ultra, large35)", "title": "Enter the SD Model (sdxl, core, large3, ultra, large35)",
"message": "$0.002, $0.03, $0.06, $0.08, $0.08", "message": "$0.04, $0.04, $0.08, $0.08, $0.14",
"placeholder": "Enter the model name", "placeholder": "Enter the model name",
}, },
} }
@ -130,25 +130,49 @@ class Action:
last_message = body["messages"][-1] last_message = body["messages"][-1]
prompt = last_message["content"] prompt = last_message["content"]
# Regular expression to capture text after 'NEGATIVE:' (if any) # Regular expression to capture text after 'NEGATIVE:' (if any)
negmatch = re.search(r"(?i)negative:?\s*(.*)", prompt) negmatch = re.search(r"(?i)negative:?\s*(.*)", prompt)
negmatch_string = None negmatch_string = None
if negmatch: if negmatch:
negmatch_string = negmatch.group(1).strip() negmatch_string = negmatch.group(1).strip()
# Regular expression to capture text after 'STYLE:' (if any)
stylematch = re.search(r"(?i)style:?\s*(.*)", prompt)
stylematch_string = None
if stylematch:
stylematch_string = negmatch.group(1).strip()
headers = { headers = {
"X-API-KEY": self.valves.LITELLM_API_KEY, "X-API-KEY": self.valves.LITELLM_API_KEY,
"Content-Type": "application/json", "Content-Type": "application/json",
} }
if "sdxl" in modelchoice:
payload = { payload = {
"prompt": prompt, "prompt": str(prompt),
"negative_prompt": negmatch_string, "style_preset": str(stylematch_string),
"cfg_scale": 7,
"height": 1024,
"width": 1024,
"samples": 1,
"steps": 30,
"response_format": "b64_json",
"model": str(modelchoice)
}
else:
payload = {
"prompt": str(prompt),
"negative_prompt": str(negmatch_string),
"mode": "text-to-image", "mode": "text-to-image",
"model": modelchoice, "model": str(modelchoice),
"aspect_ratio": "1:1", "aspect_ratio": "1:1",
"response_format": "b64_json", "response_format": "b64_json",
"output_format": "jpeg", "style_preset": str(stylematch_string),
"metadata": { }
payload.update(
{"metadata": {
"tags": [ "tags": [
"openwebui", "openwebui",
str(modelchoice), str(modelchoice),
@ -163,8 +187,8 @@ class Action:
else "unknown" else "unknown"
), ),
] ]
}, }}
} )
response = await asyncio.to_thread( response = await asyncio.to_thread(
requests.post, requests.post,