fix(annotations): derive the suggestion cap from the image tag set cap

py/autotag.py now takes MAX_SUGGESTION_LIMIT from database.annotations
MAX_IMAGE_TAGS. The two copies that cannot import it (py/config.py loads
before the database, utils/inspection_response.py stays storage-free) are
pinned equal by a test, so the 100 limits cannot drift apart.
This commit is contained in:
Vito Sansevero
2026-10-22 10:06:44 -07:00
parent 16d6b88df3
commit f6b37b1cfd
4 changed files with 21 additions and 5 deletions
+6 -3
View File
@@ -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 "
+1 -1
View File
@@ -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:
+12
View File
@@ -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)
+2 -1
View File
@@ -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