feat: add download target type for fetching files from URLs
This commit is contained in:
parent
a4600df4d5
commit
c1ad6e6e3c
14 changed files with 296 additions and 74 deletions
|
|
@ -12,7 +12,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||
|
||||
import pytest
|
||||
|
||||
from hokusai.config import TargetConfig
|
||||
from hokusai.config import GenerateTargetConfig
|
||||
from hokusai.providers.bfl import BFLResult
|
||||
from hokusai.providers.blackforest import BlackForestProvider
|
||||
from hokusai.providers.blackforest import (
|
||||
|
|
@ -81,7 +81,7 @@ class TestBlackForestProvider:
|
|||
async def test_basic_image_generation(
|
||||
self, project_dir: Path, image_bytes: bytes
|
||||
) -> None:
|
||||
target_config = TargetConfig(prompt="A red square")
|
||||
target_config = GenerateTargetConfig(prompt="A red square")
|
||||
bfl_result, mock_http = _make_bfl_mocks(image_bytes)
|
||||
|
||||
with (
|
||||
|
|
@ -107,7 +107,7 @@ class TestBlackForestProvider:
|
|||
async def test_image_with_dimensions(
|
||||
self, project_dir: Path, image_bytes: bytes
|
||||
) -> None:
|
||||
target_config = TargetConfig(prompt="A banner", width=1920, height=480)
|
||||
target_config = GenerateTargetConfig(prompt="A banner", width=1920, height=480)
|
||||
bfl_result, mock_http = _make_bfl_mocks(image_bytes)
|
||||
|
||||
with (
|
||||
|
|
@ -138,7 +138,9 @@ class TestBlackForestProvider:
|
|||
ref_path = project_dir / "ref.png"
|
||||
_ = ref_path.write_bytes(b"reference image data")
|
||||
|
||||
target_config = TargetConfig(prompt="Like this", reference_images=["ref.png"])
|
||||
target_config = GenerateTargetConfig(
|
||||
prompt="Like this", reference_images=["ref.png"]
|
||||
)
|
||||
bfl_result, mock_http = _make_bfl_mocks(image_bytes)
|
||||
|
||||
with (
|
||||
|
|
@ -171,7 +173,7 @@ class TestBlackForestProvider:
|
|||
_ = ref1.write_bytes(b"ref1 data")
|
||||
_ = ref2.write_bytes(b"ref2 data")
|
||||
|
||||
target_config = TargetConfig(
|
||||
target_config = GenerateTargetConfig(
|
||||
prompt="Combine", reference_images=["ref1.png", "ref2.png"]
|
||||
)
|
||||
bfl_result, mock_http = _make_bfl_mocks(image_bytes)
|
||||
|
|
@ -204,7 +206,9 @@ class TestBlackForestProvider:
|
|||
ref_path = project_dir / "ref.png"
|
||||
_ = ref_path.write_bytes(b"reference image data")
|
||||
|
||||
target_config = TargetConfig(prompt="Edit", reference_images=["ref.png"])
|
||||
target_config = GenerateTargetConfig(
|
||||
prompt="Edit", reference_images=["ref.png"]
|
||||
)
|
||||
bfl_result, mock_http = _make_bfl_mocks(image_bytes)
|
||||
|
||||
with (
|
||||
|
|
@ -229,7 +233,7 @@ class TestBlackForestProvider:
|
|||
assert inputs["input_image"] == encode_image_b64(ref_path)
|
||||
|
||||
async def test_image_no_sample_url_raises(self, project_dir: Path) -> None:
|
||||
target_config = TargetConfig(prompt="x")
|
||||
target_config = GenerateTargetConfig(prompt="x")
|
||||
|
||||
with patch("hokusai.providers.blackforest.BFLClient") as mock_cls:
|
||||
from hokusai.providers.bfl import BFLError
|
||||
|
|
@ -261,7 +265,7 @@ class TestMistralProvider:
|
|||
"""Test MistralProvider with mocked Mistral client."""
|
||||
|
||||
async def test_basic_text_generation(self, project_dir: Path) -> None:
|
||||
target_config = TargetConfig(prompt="Write a poem")
|
||||
target_config = GenerateTargetConfig(prompt="Write a poem")
|
||||
response = _make_text_response("Roses are red...")
|
||||
|
||||
with patch("hokusai.providers.mistral.Mistral") as mock_cls:
|
||||
|
|
@ -282,7 +286,7 @@ class TestMistralProvider:
|
|||
|
||||
async def test_text_with_text_input(self, project_dir: Path) -> None:
|
||||
_ = (project_dir / "source.txt").write_text("Source material here")
|
||||
target_config = TargetConfig(prompt="Summarize", inputs=["source.txt"])
|
||||
target_config = GenerateTargetConfig(prompt="Summarize", inputs=["source.txt"])
|
||||
response = _make_text_response("Summary: ...")
|
||||
|
||||
with patch("hokusai.providers.mistral.Mistral") as mock_cls:
|
||||
|
|
@ -306,7 +310,9 @@ class TestMistralProvider:
|
|||
|
||||
async def test_text_with_image_input(self, project_dir: Path) -> None:
|
||||
_ = (project_dir / "photo.png").write_bytes(b"\x89PNG")
|
||||
target_config = TargetConfig(prompt="Describe this image", inputs=["photo.png"])
|
||||
target_config = GenerateTargetConfig(
|
||||
prompt="Describe this image", inputs=["photo.png"]
|
||||
)
|
||||
response = _make_text_response("A beautiful photo")
|
||||
|
||||
with patch("hokusai.providers.mistral.Mistral") as mock_cls:
|
||||
|
|
@ -330,7 +336,7 @@ class TestMistralProvider:
|
|||
assert chunks[1].image_url.url.startswith("data:image/png;base64,")
|
||||
|
||||
async def test_text_no_choices_raises(self, project_dir: Path) -> None:
|
||||
target_config = TargetConfig(prompt="x")
|
||||
target_config = GenerateTargetConfig(prompt="x")
|
||||
response = MagicMock()
|
||||
response.choices = []
|
||||
|
||||
|
|
@ -348,7 +354,7 @@ class TestMistralProvider:
|
|||
)
|
||||
|
||||
async def test_text_empty_content_raises(self, project_dir: Path) -> None:
|
||||
target_config = TargetConfig(prompt="x")
|
||||
target_config = GenerateTargetConfig(prompt="x")
|
||||
response = _make_text_response(None)
|
||||
|
||||
with patch("hokusai.providers.mistral.Mistral") as mock_cls:
|
||||
|
|
@ -369,7 +375,7 @@ class TestMistralProvider:
|
|||
_ = (project_dir / "b.txt").write_text("content B")
|
||||
_ = (project_dir / "c.png").write_bytes(b"\x89PNG")
|
||||
|
||||
target_config = TargetConfig(
|
||||
target_config = GenerateTargetConfig(
|
||||
prompt="Combine all", inputs=["a.txt", "b.txt", "c.png"]
|
||||
)
|
||||
response = _make_text_response("Combined")
|
||||
|
|
@ -400,7 +406,7 @@ class TestMistralProvider:
|
|||
async def test_text_with_reference_images(self, project_dir: Path) -> None:
|
||||
_ = (project_dir / "ref.png").write_bytes(b"\x89PNG")
|
||||
|
||||
target_config = TargetConfig(
|
||||
target_config = GenerateTargetConfig(
|
||||
prompt="Describe the style", reference_images=["ref.png"]
|
||||
)
|
||||
response = _make_text_response("A stylized image")
|
||||
|
|
@ -455,7 +461,9 @@ class TestOpenAIImageProvider:
|
|||
ref = project_dir / "ref.png"
|
||||
_ = ref.write_bytes(b"reference data")
|
||||
|
||||
target_config = TargetConfig(prompt="Edit this", reference_images=["ref.png"])
|
||||
target_config = GenerateTargetConfig(
|
||||
prompt="Edit this", reference_images=["ref.png"]
|
||||
)
|
||||
b64 = base64.b64encode(image_bytes).decode()
|
||||
mock_client = _make_openai_mock(b64)
|
||||
|
||||
|
|
@ -487,7 +495,7 @@ class TestOpenAIImageProvider:
|
|||
_ = ref1.write_bytes(b"ref1 data")
|
||||
_ = ref2.write_bytes(b"ref2 data")
|
||||
|
||||
target_config = TargetConfig(
|
||||
target_config = GenerateTargetConfig(
|
||||
prompt="Combine", reference_images=["ref1.png", "ref2.png"]
|
||||
)
|
||||
b64 = base64.b64encode(image_bytes).decode()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue