feat: complete image console and add verified REST and MCP workflows
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""OpenAI 兼容网关适配器。
|
||||
|
||||
模型发现: GET {base_url}/models
|
||||
出图: POST {base_url}/images/generations
|
||||
返回: data[0].b64_json 或 data[0].url
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .base import Capabilities, ImageResult, ProviderAdapter
|
||||
|
||||
|
||||
class OpenAICompatAdapter(ProviderAdapter):
|
||||
name = "openai_compat"
|
||||
capabilities = Capabilities(
|
||||
supports_image_input=False,
|
||||
size_hint="WxH",
|
||||
kind="image",
|
||||
)
|
||||
|
||||
def generate(
|
||||
self,
|
||||
model: str,
|
||||
prompt: str,
|
||||
size: str,
|
||||
ratio: str,
|
||||
n: int,
|
||||
images: list[str],
|
||||
) -> list[ImageResult]:
|
||||
body: dict = {"model": model, "prompt": prompt, "n": n}
|
||||
if size:
|
||||
if size in ("1K", "2K", "3K", "4K"):
|
||||
side = int(size[0]) * 1024
|
||||
size = f"{side}x{side}"
|
||||
body["size"] = size
|
||||
resp = self._request("POST", "/images/generations", json_body=body, timeout=600.0)
|
||||
payload = self._json(resp)
|
||||
results = self.collect_results(payload)
|
||||
# URL 形态需要二次下载
|
||||
out: list[ImageResult] = []
|
||||
for r in results:
|
||||
out.append(self.download(r.url) if r.url else r)
|
||||
return out
|
||||
Reference in New Issue
Block a user