mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-08 13:12:08 +00:00
test(image-gen): cap Codex reference inputs
This commit is contained in:
parent
ecffd290a3
commit
460235d584
2 changed files with 25 additions and 5 deletions
|
|
@ -31,6 +31,7 @@ from agent.image_gen_provider import (
|
|||
DEFAULT_ASPECT_RATIO,
|
||||
ImageGenProvider,
|
||||
error_response,
|
||||
normalize_reference_images,
|
||||
resolve_aspect_ratio,
|
||||
save_b64_image,
|
||||
success_response,
|
||||
|
|
@ -84,6 +85,7 @@ _CODEX_INSTRUCTIONS = (
|
|||
"requests by using the image_generation tool when provided."
|
||||
)
|
||||
|
||||
_MAX_REFERENCE_IMAGES = 16
|
||||
_MAX_INPUT_IMAGE_BYTES = 25 * 1024 * 1024
|
||||
_IMAGE_MAGIC_MIME = (
|
||||
(b"\x89PNG\r\n\x1a\n", "image/png"),
|
||||
|
|
@ -236,10 +238,9 @@ def _normalize_input_images(
|
|||
values: List[str] = []
|
||||
if isinstance(image_url, str) and image_url.strip():
|
||||
values.append(image_url.strip())
|
||||
if isinstance(reference_image_urls, (list, tuple)):
|
||||
for ref in reference_image_urls:
|
||||
if isinstance(ref, str) and ref.strip():
|
||||
values.append(ref.strip())
|
||||
for ref in (normalize_reference_images(reference_image_urls) or []):
|
||||
values.append(ref)
|
||||
values = values[:_MAX_REFERENCE_IMAGES]
|
||||
return [_to_input_image_part(value) for value in values]
|
||||
|
||||
|
||||
|
|
@ -453,7 +454,7 @@ class OpenAICodexImageGenProvider(ImageGenProvider):
|
|||
# images as `input_image` message content parts. Keep this capability
|
||||
# honest so the dynamic `image_generate` schema encourages identity-
|
||||
# preserving edits instead of unrelated text-to-image redraws.
|
||||
return {"modalities": ["text", "image"], "max_reference_images": 16}
|
||||
return {"modalities": ["text", "image"], "max_reference_images": _MAX_REFERENCE_IMAGES}
|
||||
|
||||
def generate(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -204,6 +204,25 @@ class TestGenerate:
|
|||
assert content[1]["image_url"].startswith("data:image/png;base64,")
|
||||
assert content[2] == {"type": "input_image", "image_url": "https://example.com/ref.png"}
|
||||
|
||||
def test_generate_clamps_reference_images_to_cap(self, provider, monkeypatch):
|
||||
monkeypatch.setattr(codex_plugin, "_read_codex_access_token", lambda: "codex-token")
|
||||
captured = {}
|
||||
|
||||
def _collect(token, *, prompt, size, quality, input_images=None):
|
||||
captured["input_images"] = input_images
|
||||
return _b64_png()
|
||||
|
||||
monkeypatch.setattr(codex_plugin, "_collect_image_b64", _collect)
|
||||
|
||||
refs = [f"https://example.com/ref-{idx}.png" for idx in range(20)]
|
||||
result = provider.generate("combine the references", reference_image_urls=refs)
|
||||
|
||||
assert result["success"] is True
|
||||
assert result["modality"] == "image"
|
||||
assert result["input_image_count"] == 16
|
||||
assert len(captured["input_images"]) == 16
|
||||
assert captured["input_images"][-1]["image_url"] == "https://example.com/ref-15.png"
|
||||
|
||||
def test_rejects_non_image_local_source(self, provider, monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(codex_plugin, "_read_codex_access_token", lambda: "codex-token")
|
||||
text_path = tmp_path / "not-image.txt"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue