Commit e91ec77
Changed files (1)
src
llm
ali
src/llm/ali/text2img.py
@@ -1,7 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
+import json
from pathlib import Path
+from random import randint
from glom import glom
from httpx import AsyncClient
@@ -19,6 +21,8 @@ from utils import strings_list
async def ali_text2img(client: Client, message: Message, model_id: str, prompt: str, *, silent: bool = False, **kwargs) -> dict:
"""Ali text to image.
+ https://help.aliyun.com/zh/model-studio/flux-api-reference
+
Args:
client (Client): The Pyrogram client.
message (Message): The trigger message object.
@@ -39,7 +43,15 @@ async def ali_text2img(client: Client, message: Message, model_id: str, prompt:
kwargs["progress"] = (await send2tg(client, message, texts=f"🌠**{model_name}**:\n💬提示词: {prompt}", **kwargs))[0]
error = ""
succ = False
- payload = {"model": model_id, "input": {"prompt": prompt}}
+ payload = {
+ "model": model_id,
+ "input": {"prompt": prompt},
+ "parameters": {
+ "size": "1024*1024",
+ "steps": 50,
+ "seed": randint(0, 2147483647),
+ },
+ }
if "stable-diffusion" in model_id:
payload |= {"parameters": {"n": 4}}
for api_key in strings_list(TEXT2IMG.ALI_API_KEY, shuffle=True):
@@ -60,7 +72,7 @@ async def ali_text2img(client: Client, message: Message, model_id: str, prompt:
finished = await wait_for_response(resp["output"]["task_id"], api_key)
if images := finished.get("images"):
media = [{"photo": img} for img in images]
- await send2tg(client, message, texts=f"{prompt}\n(By **{model_name}**)", media=media, **kwargs)
+ await send2tg(client, message, texts=json.dumps(payload, ensure_ascii=False, indent=2), media=media, **kwargs)
succ = True
break
except Exception as e: