From c0c3a4c4056a1bf3eccbd7ca26e448de6aa9bf0e Mon Sep 17 00:00:00 2001 From: moosecrap Date: Mon, 27 Jul 2026 01:45:52 -0700 Subject: [PATCH] Tag search limit --- README.md | 1 + config.py | 1 + tools/search_tags.py | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ab7cf88..de68f35 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ Tuning the server's behavior is done via `config.py`. | `MODEL_PRESETS_PATH` | Path to the `model_presets.toml` file. | `ROOT_DIR / "model_presets.toml"` | | `RES_PRESETS_PATH` | Path to the `resolution_presets.toml` file. | `ROOT_DIR / "resolution_presets.toml"` | | `TAG_DATABASE_PATH` | Path to the Danbooru `tags.csv` file. | (Path to extension folder) | +| `TAG_SEARCH_LIMIT` | Number of results returned by `search_tags` (direct or similar). | `20` | ### 🧠 Model & Token Tuning (Optimized for Gemma 4) | Parameter | Description | Default | diff --git a/config.py b/config.py index 6ff030d..54c7624 100644 --- a/config.py +++ b/config.py @@ -17,6 +17,7 @@ SD_URL = "http://127.0.0.1:7860" MODEL_PRESETS_PATH = str(ROOT_DIR / "model_presets.toml") RES_PRESETS_PATH = str(ROOT_DIR / "resolution_presets.toml") TAG_DATABASE_PATH = "/home/matt/stable-diffusion-webui/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv" +TAG_SEARCH_LIMIT = 20 # --- Model Specific Token Tuning (Tuned for Gemma 4) --- # Patch size is typically (clip.vision.patch_size * n_merge) diff --git a/tools/search_tags.py b/tools/search_tags.py index 0ffb0f3..2d177b4 100644 --- a/tools/search_tags.py +++ b/tools/search_tags.py @@ -74,9 +74,9 @@ async def handle(args: Dict[str, Any]) -> List[Dict[str, Any]]: # Sort by count descending matches.sort(key=lambda x: x["count"], reverse=True) - # Format top 20 results + # Format top results results = [] - for m in matches[:20]: + for m in matches[:config.TAG_SEARCH_LIMIT]: count_fmt = format_count(str(m["count"])) type_sfx = get_type_suffix(m["type"]) @@ -90,7 +90,7 @@ async def handle(args: Dict[str, Any]) -> List[Dict[str, Any]]: if not results: # Attempt to find similar tags using difflib all_names_lower = [t["name_lower"] for t in _TAG_CACHE] - suggestions_lower = difflib.get_close_matches(query, all_names_lower, n=10, cutoff=0.5) + suggestions_lower = difflib.get_close_matches(query, all_names_lower, n=config.TAG_SEARCH_LIMIT, cutoff=0.5) if not suggestions_lower: return [{"type": "text", "text": f"No tags found matching '{query}'."}]