mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-17 08:13:56 +00:00
test(image-generation): tighten zhipu provider coverage
This commit is contained in:
parent
192d2af19d
commit
5937236f9d
@ -1195,7 +1195,7 @@ If you want to always use the local conversion, you can force it using:
|
||||
|
||||
## 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.
|
||||
|
||||
|
||||
@ -255,7 +255,7 @@ Supported aspect ratios: `1:1`, `16:9`, `9:16`, `3:4`, `4:3`. Sizes can be speci
|
||||
{
|
||||
"providers": {
|
||||
"zhipu": {
|
||||
"apiKey": "${ZHIPU_API_KEY}"
|
||||
"apiKey": "${ZAI_API_KEY}"
|
||||
}
|
||||
},
|
||||
"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 |
|
||||
| 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 |
|
||||
|
||||
|
||||
@ -1504,7 +1504,6 @@ class ZhipuImageGenerationClient(ImageGenerationProvider):
|
||||
"prompt": prompt,
|
||||
}
|
||||
|
||||
# Resolve size
|
||||
size = _zhipu_size(aspect_ratio, image_size)
|
||||
if size:
|
||||
body["size"] = size
|
||||
@ -1517,10 +1516,6 @@ class ZhipuImageGenerationClient(ImageGenerationProvider):
|
||||
try:
|
||||
return await self._generate_with_client(
|
||||
client,
|
||||
prompt=prompt,
|
||||
model=model,
|
||||
aspect_ratio=aspect_ratio,
|
||||
image_size=image_size,
|
||||
headers=headers,
|
||||
body=body,
|
||||
url=url,
|
||||
@ -1533,10 +1528,6 @@ class ZhipuImageGenerationClient(ImageGenerationProvider):
|
||||
self,
|
||||
client: httpx.AsyncClient,
|
||||
*,
|
||||
prompt: str,
|
||||
model: str,
|
||||
aspect_ratio: str | None,
|
||||
image_size: str | None,
|
||||
headers: dict[str, str],
|
||||
body: dict[str, Any],
|
||||
url: str,
|
||||
|
||||
@ -172,16 +172,7 @@ async def test_generate_image_tool_allows_ollama_without_api_key(
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_image_tool_allows_zhipu_without_api_key(
|
||||
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,
|
||||
)
|
||||
async def test_generate_image_tool_reports_missing_zhipu_key(tmp_path: Path) -> None:
|
||||
tool = ImageGenerationTool(
|
||||
workspace=tmp_path,
|
||||
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")
|
||||
|
||||
payload = json.loads(result)
|
||||
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"
|
||||
assert result.startswith("Error: Zhipu API key is not configured")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user