mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-27 11:22:03 +00:00
fix shape
This commit is contained in:
parent
525ee58b43
commit
2c02583c2b
2 changed files with 47 additions and 2 deletions
|
|
@ -86,6 +86,11 @@ _ASPECT_MAP = {
|
|||
# Only resolution Krea currently supports.
|
||||
DEFAULT_RESOLUTION = "1K"
|
||||
|
||||
# Krea's image_style_references entries are objects ({"url", "strength"}), not
|
||||
# bare URL strings. When the caller supplies a URL without an explicit strength
|
||||
# we apply Krea's recommended starting value. Range per Krea docs is -2..2.
|
||||
_DEFAULT_STYLE_REFERENCE_STRENGTH = 0.6
|
||||
|
||||
# Valid creativity levels per Krea docs. Default is "medium".
|
||||
_VALID_CREATIVITY = {"raw", "low", "medium", "high"}
|
||||
|
||||
|
|
@ -402,8 +407,19 @@ class KreaImageGenProvider(ImageGenProvider):
|
|||
|
||||
if style_refs:
|
||||
# Reference-guided generation (image-to-image style transfer).
|
||||
# Krea caps at 10 refs per request (already clamped above).
|
||||
payload["image_style_references"] = style_refs
|
||||
# Krea requires each entry to be an object ({"url", "strength"}),
|
||||
# NOT a bare URL string — a string yields a 422 "Expected object,
|
||||
# received string". Convert URL strings to the object form and pass
|
||||
# already-object refs through verbatim (clamped to 10 above).
|
||||
normalized_refs: List[Any] = []
|
||||
for ref in style_refs:
|
||||
if isinstance(ref, str):
|
||||
normalized_refs.append(
|
||||
{"url": ref, "strength": _DEFAULT_STYLE_REFERENCE_STRENGTH}
|
||||
)
|
||||
else:
|
||||
normalized_refs.append(ref)
|
||||
payload["image_style_references"] = normalized_refs
|
||||
|
||||
moodboards = kwargs.get("moodboards")
|
||||
if isinstance(moodboards, list) and moodboards:
|
||||
|
|
|
|||
|
|
@ -309,6 +309,35 @@ class TestGenerate:
|
|||
assert len(payload["image_style_references"]) == 10 # capped at 10
|
||||
assert payload["creativity"] == "high"
|
||||
|
||||
def test_string_style_references_converted_to_objects(self):
|
||||
"""Krea requires {url, strength} objects; bare URL strings must be
|
||||
converted (a string yields a 422 'Expected object, received string')."""
|
||||
from plugins.image_gen.krea import KreaImageGenProvider
|
||||
|
||||
submit = _submit_response()
|
||||
poll = _poll_response(_completed_job())
|
||||
|
||||
with patch("plugins.image_gen.krea.requests.post", return_value=submit) as mock_post, \
|
||||
patch("plugins.image_gen.krea.requests.get", return_value=poll), \
|
||||
patch(
|
||||
"plugins.image_gen.krea.save_url_image",
|
||||
return_value=Path("/tmp/x.png"),
|
||||
), \
|
||||
patch("plugins.image_gen.krea.time.sleep"):
|
||||
KreaImageGenProvider().generate(
|
||||
prompt="test",
|
||||
image_style_references=[
|
||||
"https://x.com/a.png",
|
||||
{"url": "https://x.com/b.png", "strength": 1.2},
|
||||
],
|
||||
)
|
||||
|
||||
payload = mock_post.call_args.kwargs["json"]
|
||||
assert payload["image_style_references"] == [
|
||||
{"url": "https://x.com/a.png", "strength": 0.6},
|
||||
{"url": "https://x.com/b.png", "strength": 1.2},
|
||||
]
|
||||
|
||||
def test_unknown_kwargs_ignored(self):
|
||||
"""Forward-compat: unknown kwargs must not break generate()."""
|
||||
from plugins.image_gen.krea import KreaImageGenProvider
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue