Whitepaper
Docs
Sign In
Function
Function
action
v0.1.0
Draw Image with Siliconflow
Function ID
draw_image_with_siliconflow
Creator
@focuses
Downloads
22+
Draw images follow the assistant's response by Siliconflow API
Get
README
No README available
Function Code
Show
""" title: Siliconflow_draw description: A action can draw images with Siliconflow_draw API. author: focuses icon_url: data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyBjbGFzcz0iaWNvbiIgd2lkdGg9IjIwMHB4IiBoZWlnaHQ9IjIwMC4wMHB4IiB2aWV3Qm94PSIwIDAgMTAyNCAxMDI0IiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTU0NCA2NjEuMzMzMzMzYTMyIDMyIDAgMCAxLTY0IDBWMzYyLjY2NjY2N2EzMiAzMiAwIDAgMSA2NCAwdjI5OC42NjY2NjZ6IG0xNjAgMGEzMiAzMiAwIDAgMS02NCAwVjQ5MC42NjY2NjdhMzIgMzIgMCAwIDEgNjQgMHYxNzAuNjY2NjY2eiBtLTMyMCAwYTMyIDMyIDAgMCAxLTY0IDBWNDQ4YTMyIDMyIDAgMCAxIDY0IDB2MjEzLjMzMzMzM3pNMjAyLjY2NjY2NyAxMzguNjY2NjY3aDYxOC42NjY2NjZjNjQuOCAwIDExNy4zMzMzMzMgNTIuNTMzMzMzIDExNy4zMzMzMzQgMTE3LjMzMzMzM3Y1MTJjMCA2NC44LTUyLjUzMzMzMyAxMTcuMzMzMzMzLTExNy4zMzMzMzQgMTE3LjMzMzMzM0gyMDIuNjY2NjY3Yy02NC44IDAtMTE3LjMzMzMzMy01Mi41MzMzMzMtMTE3LjMzMzMzNC0xMTcuMzMzMzMzVjI1NmMwLTY0LjggNTIuNTMzMzMzLTExNy4zMzMzMzMgMTE3LjMzMzMzNC0xMTcuMzMzMzMzeiBtMCA2NGE1My4zMzMzMzMgNTMuMzMzMzMzIDAgMCAwLTUzLjMzMzMzNCA1My4zMzMzMzN2NTEyYTUzLjMzMzMzMyA1My4zMzMzMzMgMCAwIDAgNTMuMzMzMzM0IDUzLjMzMzMzM2g2MTguNjY2NjY2YTUzLjMzMzMzMyA1My4zMzMzMzMgMCAwIDAgNTMuMzMzMzM0LTUzLjMzMzMzM1YyNTZhNTMuMzMzMzMzIDUzLjMzMzMzMyAwIDAgMC01My4zMzMzMzQtNTMuMzMzMzMzSDIwMi42NjY2Njd6IiBmaWxsPSIjMDAwMDAwIiAvPjwvc3ZnPg== version: 0.1.0 required_open_webui_version: 0.3.9 usage: select this in any model, and click the icon for the assitant response to generate pictures """ from pydantic import BaseModel, Field from typing import Optional import asyncio import aiohttp class Action: class Valves(BaseModel): priority: int = Field( default=0, description="Priority level for the filter operations.", ) api_url: str = Field( default="https://api.siliconflow.cn/v1", description="Base URL for the Siliconflow API.", ) api_key: str = Field( default="", description="API Key for the Siliconflow API.", ) class UserValves(BaseModel): size: str = Field( default="1024x1024", description="1024x1024, 512x1024, 768x512, 768x1024, 1024x576, 576x1024.", ) steps: int = Field( default=20, description="The number of inference steps to be performed (1-100).", ) model: str = Field( default="black-forest-labs/FLUX.1-schnell", description="The name of the model.", ) pnum: int = Field( default=1, description="The number of pictures.", ) seed: Optional[int] = Field( default=None, description="The seed.", ) def __init__(self): self.valves = self.Valves() async def request(self, prompt, __user__): url = f"{self.valves.api_url}/image/generations" headers = { "accept": "application/json", "content-type": "application/json", "authorization": f"Bearer {self.valves.api_key}", } payload = { "prompt": prompt, "model": __user__["valves"].model, "image_size": __user__["valves"].size, "num_inference_steps": __user__["valves"].steps, } if seed := __user__["valves"].seed: payload["seed"] = seed pnum = __user__["valves"].pnum async with aiohttp.ClientSession() as sess: tasks = [sess.post(url, json=payload, headers=headers) for _ in range(pnum)] res = await asyncio.gather(*tasks) ret = [] for i, r in enumerate(res): if (s := r.status) == 200: json = await r.json() url = json["images"][0]["url"] ret.append(f"") else: text = await r.text() ret.append(f"> The {i} request failed ({s}): {text}.") return ret async def action( self, body: dict, __user__=None, __event_emitter__=None, __event_call__=None, ) -> Optional[dict]: print(f"action:{__name__}") if "messages" in body and body["messages"] and __user__ and "id" in __user__: await __event_emitter__( { "type": "status", "data": { "description": "Start generation images", "done": False, }, } ) last = body["messages"][-1] res = await self.request(last["content"], __user__) await __event_emitter__( { "type": "status", "data": { "description": "Generated images", "done": True, }, } ) # print(res) for r in res: await __event_emitter__( { "type": "message", "data": {"content": f"\n{r}"}, } ) await asyncio.sleep(0) # print(r)