diff --git a/py/autotag.py b/py/autotag.py index 0c807f06..68c72a5b 100644 --- a/py/autotag.py +++ b/py/autotag.py @@ -16,10 +16,13 @@ from PIL import Image # A loader takes (model_type, use_gpu) and returns ("gguf" | "wd14" | "hf", backend) ModelLoader = Callable[[str, bool], Tuple[str, Any]] -# Suggestions keep only names a Save accepts (the vocabulary tag rules). +# Suggestions keep only names a Save accepts (the vocabulary tag rules), and +# never more than one image tag set holds. try: + from ..database.annotations import MAX_IMAGE_TAGS from ..database.vocabulary import validate_vocabulary_tag_name except ImportError: + from database.annotations import MAX_IMAGE_TAGS from database.vocabulary import validate_vocabulary_tag_name # Try to import logging from utils, fallback to standard logging @@ -94,8 +97,8 @@ DEFAULT_PROMPT = ( "descriptive." ) -# Upper bound of one suggestion request: the image tag set cap (100 names). -MAX_SUGGESTION_LIMIT = 100 +# Upper bound of one suggestion request: the image tag set cap. +MAX_SUGGESTION_LIMIT = MAX_IMAGE_TAGS SYSTEM_PROMPT = ( "You are a helpful assistant and help users with any queries they may have " diff --git a/py/config.py b/py/config.py index 5115bfe3..a2285246 100644 --- a/py/config.py +++ b/py/config.py @@ -468,7 +468,7 @@ class IntegrationConfig: # Number of tag suggestions the Tag dialogs request by default (D68). The cap # is the image tag set limit: more suggestions could never all be kept. DEFAULT_SUGGESTION_LIMIT = 10 -MAX_SUGGESTION_LIMIT = 100 +MAX_SUGGESTION_LIMIT = 100 # pinned to MAX_IMAGE_TAGS by tests/test_config.py class AutotagConfig: diff --git a/tests/test_config.py b/tests/test_config.py index 795de80c..0b2805a0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -427,6 +427,18 @@ class TestAutotagConfig(unittest.TestCase): PromptManagerConfig.load_from_file(path) return logs + def test_every_copy_of_the_tag_set_cap_is_one_value(self): + # A suggestion request is bounded by the image tag set cap; the + # copies that cannot import it (config loads before the database, + # the inspection envelope stays storage-free) are pinned to it here. + from database.annotations import MAX_IMAGE_TAGS + from py import autotag + from utils import inspection_response + + self.assertEqual(autotag.MAX_SUGGESTION_LIMIT, MAX_IMAGE_TAGS) + self.assertEqual(config_module.MAX_SUGGESTION_LIMIT, MAX_IMAGE_TAGS) + self.assertEqual(inspection_response.MAX_IMAGE_TAGS, MAX_IMAGE_TAGS) + def test_default_is_ten_and_persisted_under_autotag_defaults(self): self.assertEqual(config_module.DEFAULT_SUGGESTION_LIMIT, 10) self.assertEqual(config_module.MAX_SUGGESTION_LIMIT, 100) diff --git a/utils/inspection_response.py b/utils/inspection_response.py index fae4c35b..048103ac 100644 --- a/utils/inspection_response.py +++ b/utils/inspection_response.py @@ -13,7 +13,8 @@ if TYPE_CHECKING: MAX_RESPONSE_BYTES = 8 * 1024 * 1024 MAX_LIBRARY_BYTES = 32 * 1024 -# The image tag set cap (database/annotations.py MAX_IMAGE_TAGS). +# The image tag set cap (database/annotations.py MAX_IMAGE_TAGS; pinned equal +# by tests/test_config.py). MAX_IMAGE_TAGS = 100 _IMAGE_TAG_STATES = frozenset({"current", "none", "unavailable"}) _MAX_SAFE_INTEGER = 2**53 - 1