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",
}, },
} }
@ -129,6 +129,7 @@ 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)
@ -136,35 +137,58 @@ class Action:
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",
} }
payload = {
"prompt": prompt, if "sdxl" in modelchoice:
"negative_prompt": negmatch_string, payload = {
"mode": "text-to-image", "prompt": str(prompt),
"model": modelchoice, "style_preset": str(stylematch_string),
"aspect_ratio": "1:1", "cfg_scale": 7,
"response_format": "b64_json", "height": 1024,
"output_format": "jpeg", "width": 1024,
"metadata": { "samples": 1,
"tags": [ "steps": 30,
"openwebui", "response_format": "b64_json",
str(modelchoice), "model": str(modelchoice)
( }
__user__["email"] else:
if __user__ and "email" in __user__ payload = {
else "unknown" "prompt": str(prompt),
), "negative_prompt": str(negmatch_string),
( "mode": "text-to-image",
__user__["name"] "model": str(modelchoice),
if __user__ and "name" in __user__ "aspect_ratio": "1:1",
else "unknown" "response_format": "b64_json",
), "style_preset": str(stylematch_string),
] }
},
} payload.update(
{"metadata": {
"tags": [
"openwebui",
str(modelchoice),
(
__user__["email"]
if __user__ and "email" in __user__
else "unknown"
),
(
__user__["name"]
if __user__ and "name" in __user__
else "unknown"
),
]
}}
)
response = await asyncio.to_thread( response = await asyncio.to_thread(
requests.post, requests.post,