chore: import upstream snapshot with attribution
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""Tests for TextLLM API request/response models and validation."""
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from invokeai.app.api.routers.utilities import ExpandPromptRequest, ExpandPromptResponse, ImageToPromptRequest
|
||||
|
||||
|
||||
class TestExpandPromptRequest:
|
||||
def test_defaults(self):
|
||||
req = ExpandPromptRequest(prompt="a cat", model_key="abc-123")
|
||||
assert req.max_tokens == 300
|
||||
assert req.system_prompt is None
|
||||
|
||||
def test_max_tokens_upper_bound(self):
|
||||
"""max_tokens should be capped at 2048."""
|
||||
with pytest.raises(ValidationError):
|
||||
ExpandPromptRequest(prompt="a cat", model_key="abc-123", max_tokens=2049)
|
||||
|
||||
def test_max_tokens_lower_bound(self):
|
||||
"""max_tokens must be at least 1."""
|
||||
with pytest.raises(ValidationError):
|
||||
ExpandPromptRequest(prompt="a cat", model_key="abc-123", max_tokens=0)
|
||||
|
||||
def test_max_tokens_valid_range(self):
|
||||
req = ExpandPromptRequest(prompt="a cat", model_key="abc-123", max_tokens=2048)
|
||||
assert req.max_tokens == 2048
|
||||
req2 = ExpandPromptRequest(prompt="a cat", model_key="abc-123", max_tokens=1)
|
||||
assert req2.max_tokens == 1
|
||||
|
||||
def test_custom_system_prompt(self):
|
||||
req = ExpandPromptRequest(prompt="a cat", model_key="abc-123", system_prompt="Be brief.")
|
||||
assert req.system_prompt == "Be brief."
|
||||
|
||||
|
||||
class TestImageToPromptRequest:
|
||||
def test_defaults(self):
|
||||
req = ImageToPromptRequest(image_name="img.png", model_key="abc-123")
|
||||
assert "Describe" in req.instruction
|
||||
|
||||
def test_custom_instruction(self):
|
||||
req = ImageToPromptRequest(image_name="img.png", model_key="abc-123", instruction="What is this?")
|
||||
assert req.instruction == "What is this?"
|
||||
|
||||
|
||||
class TestExpandPromptResponse:
|
||||
def test_success_response(self):
|
||||
resp = ExpandPromptResponse(expanded_prompt="A detailed scene")
|
||||
assert resp.expanded_prompt == "A detailed scene"
|
||||
assert resp.error is None
|
||||
|
||||
def test_error_response(self):
|
||||
resp = ExpandPromptResponse(expanded_prompt="", error="Model failed")
|
||||
assert resp.error == "Model failed"
|
||||
Reference in New Issue
Block a user