mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
feat(civitai): allow tag-only and sort-only browsing
Relax the empty-query guard so search works with tag, sort, or period alone. Skip exact-match name filtering when no keyword is provided so browse results return the full API response.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import re
|
||||
import time
|
||||
from installer import log
|
||||
from modules.civitai.client_civitai import client
|
||||
@@ -20,12 +21,18 @@ def search_civitai(
|
||||
token: str = None,
|
||||
exact: bool = True,
|
||||
) -> list[CivitModel]:
|
||||
if not query:
|
||||
log.error('CivitAI: empty query')
|
||||
if not query and not tag and not sort:
|
||||
log.error('CivitAI: no search criteria provided')
|
||||
return []
|
||||
|
||||
t0 = time.time()
|
||||
|
||||
# URL query → extract model ID (e.g. https://civitai.com/models/967405/nova-orange-xl)
|
||||
url_match = re.match(r'https?://civitai\.com/models/(\d+)', query.strip())
|
||||
if url_match:
|
||||
query = url_match.group(1)
|
||||
log.info(f'CivitAI: extracted model id={query} from URL')
|
||||
|
||||
# Numeric query → single model fetch
|
||||
if query.isnumeric():
|
||||
model = client.get_model(int(query), token=token)
|
||||
@@ -49,7 +56,7 @@ def search_civitai(
|
||||
|
||||
all_models = response.items
|
||||
exact_models: list[CivitModel] = []
|
||||
if exact:
|
||||
if exact and query:
|
||||
q_lower = query.lower()
|
||||
for model in all_models:
|
||||
names = [model.name.lower()]
|
||||
|
||||
Reference in New Issue
Block a user