test(image-generation): tighten zhipu provider coverage

This commit is contained in:
Xubin Ren 2026-05-23 16:55:25 +08:00
parent 192d2af19d
commit 5937236f9d
4 changed files with 4 additions and 30 deletions

View File

@ -1195,7 +1195,7 @@ If you want to always use the local conversion, you can force it using:
## Image Generation ## Image Generation
Image generation is configured under `tools.imageGeneration` and uses provider credentials from `providers.openrouter` or `providers.aihubmix`. Image generation is configured under `tools.imageGeneration` and uses credentials from the selected provider's `providers.<name>` block.
See [Image Generation](./image-generation.md) for WebUI usage, provider examples, artifact storage, and troubleshooting. See [Image Generation](./image-generation.md) for WebUI usage, provider examples, artifact storage, and troubleshooting.

View File

@ -255,7 +255,7 @@ Supported aspect ratios: `1:1`, `16:9`, `9:16`, `3:4`, `4:3`. Sizes can be speci
{ {
"providers": { "providers": {
"zhipu": { "zhipu": {
"apiKey": "${ZHIPU_API_KEY}" "apiKey": "${ZAI_API_KEY}"
} }
}, },
"tools": { "tools": {
@ -328,4 +328,3 @@ Use the reference image. Keep the same robot and composition, change the palette
| AIHubMix says `Incorrect model ID` | Use `model: "gpt-image-2-free"`; nanobot expands it to the required `openai/gpt-image-2-free` model path internally | | AIHubMix says `Incorrect model ID` | Use `model: "gpt-image-2-free"`; nanobot expands it to the required `openai/gpt-image-2-free` model path internally |
| Generation times out | Try a smaller/default image size, set AIHubMix `extraBody.quality` to `"low"`, or retry later | | Generation times out | Try a smaller/default image size, set AIHubMix `extraBody.quality` to `"low"`, or retry later |
| Reference image rejected | Reference image paths must be inside the workspace or nanobot media directory and must be valid image files | | Reference image rejected | Reference image paths must be inside the workspace or nanobot media directory and must be valid image files |

View File

@ -1504,7 +1504,6 @@ class ZhipuImageGenerationClient(ImageGenerationProvider):
"prompt": prompt, "prompt": prompt,
} }
# Resolve size
size = _zhipu_size(aspect_ratio, image_size) size = _zhipu_size(aspect_ratio, image_size)
if size: if size:
body["size"] = size body["size"] = size
@ -1517,10 +1516,6 @@ class ZhipuImageGenerationClient(ImageGenerationProvider):
try: try:
return await self._generate_with_client( return await self._generate_with_client(
client, client,
prompt=prompt,
model=model,
aspect_ratio=aspect_ratio,
image_size=image_size,
headers=headers, headers=headers,
body=body, body=body,
url=url, url=url,
@ -1533,10 +1528,6 @@ class ZhipuImageGenerationClient(ImageGenerationProvider):
self, self,
client: httpx.AsyncClient, client: httpx.AsyncClient,
*, *,
prompt: str,
model: str,
aspect_ratio: str | None,
image_size: str | None,
headers: dict[str, str], headers: dict[str, str],
body: dict[str, Any], body: dict[str, Any],
url: str, url: str,

View File

@ -172,16 +172,7 @@ async def test_generate_image_tool_allows_ollama_without_api_key(
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_generate_image_tool_allows_zhipu_without_api_key( async def test_generate_image_tool_reports_missing_zhipu_key(tmp_path: Path) -> None:
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
set_config_path(tmp_path / "config.json")
FakeImageClient.instances = []
monkeypatch.setattr(
"nanobot.agent.tools.image_generation.get_image_gen_provider",
lambda name: FakeImageClient if name == "zhipu" else None,
)
tool = ImageGenerationTool( tool = ImageGenerationTool(
workspace=tmp_path, workspace=tmp_path,
config=ImageGenerationToolConfig( config=ImageGenerationToolConfig(
@ -194,14 +185,7 @@ async def test_generate_image_tool_allows_zhipu_without_api_key(
result = await tool.execute(prompt="draw a cat") result = await tool.execute(prompt="draw a cat")
payload = json.loads(result) assert result.startswith("Error: Zhipu API key is not configured")
assert len(payload["artifacts"]) == 1
fake = FakeImageClient.instances[0]
assert fake.kwargs["api_key"] is None
assert fake.kwargs["api_base"] == "https://open.bigmodel.cn/api/paas/v4"
assert fake.calls[0]["aspect_ratio"] == "1:1"
assert fake.calls[0]["image_size"] == "1K"
@pytest.mark.asyncio @pytest.mark.asyncio