Add configurable CivitAI candidate limit

Allow the number of CivitAI search candidates to be configured (default 5, bounds 1–20) and thread this limit through the frontend and backend. Backend: introduce DEFAULT/MAX constants, validate candidate_limit, include it in cache keys and logs, collect and deduplicate candidates from tRPC and HTML searches up to the limit, prefer exact 100% matches and otherwise pick the best-confidence result. Frontend: persist civitaiCandidateLimit in localStorage, add an input to options UI, clamp/save the value, include civitai_candidate_limit in search payloads, and apply suggested subfolder info from returned civitai_search_result. Misc: UI copy updated and minor log/message tweaks.
This commit is contained in:
Dariusz L
2026-04-26 03:09:03 +02:00
parent ef567a449e
commit f4f28fc450
3 changed files with 118 additions and 38 deletions
+14 -1
View File
@@ -806,6 +806,18 @@ class ModelLinkerExtension:
data = await request.json()
filename = data.get("filename", "")
category = data.get("category", "")
civitai_candidate_limit_raw = data.get(
"civitai_candidate_limit", 5
)
try:
civitai_candidate_limit = int(
civitai_candidate_limit_raw
)
except (TypeError, ValueError):
civitai_candidate_limit = 5
civitai_candidate_limit = max(
1, min(civitai_candidate_limit, 20)
)
# Handle both boolean and string forms
is_urn_raw = data.get("is_urn", False)
civitai_session_token = data.get("civitai_session_token", "")
@@ -848,7 +860,7 @@ class ModelLinkerExtension:
search_civitai_source = "civitai" in normalized_sources
log_info(
f"Search request: filename={filename}, category={category}, is_urn={is_urn}, model_id={data.get('model_id')}, version_id={data.get('version_id')}, sources={sorted(normalized_sources)}"
f"Search request: filename={filename}, category={category}, is_urn={is_urn}, model_id={data.get('model_id')}, version_id={data.get('version_id')}, sources={sorted(normalized_sources)}, civitai_candidate_limit={civitai_candidate_limit}"
)
results = {
@@ -1008,6 +1020,7 @@ class ModelLinkerExtension:
filename,
model_type=category,
session_token=civitai_session_token or None,
candidate_limit=civitai_candidate_limit,
)
log_search_result("civitai", civitai_result)
if civitai_result: