Add AI search query expansion
test / pytest (push) Successful in 1m20s
docker-image / build-and-push (push) Successful in 5m6s

This commit is contained in:
2026-06-01 21:28:29 +02:00
parent d36b940981
commit 70b0cf08ee
10 changed files with 1064 additions and 123 deletions
+24
View File
@@ -20,7 +20,31 @@
</form>
</section>
{% if query and ai_available %}
<section class="card" style="margin-top: 8px;">
{% if ai_activated %}
<span class="muted">AI 搜索已启用</span>
{% else %}
<a href="/search?q={{ query | urlencode }}&ai=1" class="button button-secondary" style="display:inline-block; text-decoration:none;">
AI 智能搜索
</a>
{% endif %}
</section>
{% endif %}
{% if searched %}
{% if ai_error %}
<section class="card" style="margin-top: 8px; border-color: #b42318;">
<p style="margin:0; color: #b42318;"><strong>{{ ai_error }}</strong></p>
</section>
{% endif %}
{% if ai_activated and expanded_terms %}
<section class="card" style="margin-top: 8px; border-color: #0b57d0;">
<p style="margin:0; color: #0b57d0;"><strong>AI 帮你扩展了:</strong>{{ expanded_terms | join('、') }}</p>
</section>
{% endif %}
{% if results %}
<section class="stack">
<p class="muted">共找到 {{ results|length }} 条结果。</p>
+14
View File
@@ -47,6 +47,20 @@
{% endif %}
</label>
<hr style="border:none;border-top:1px solid #ddd;margin:16px 0;">
<label class="form-field checkbox-row">
<input type="checkbox" name="ai_search_enabled" {% if config.ai_search_enabled %}checked{% endif %}>
启用 AI 智能搜索
</label>
<p class="checkbox-help">开启后,搜索页将显示「AI 智能搜索」按钮,通过查询词扩展增强搜索结果。</p>
<label class="form-field">
额外领域提示(可选)
<textarea name="ai_search_extra_hints" rows="3" placeholder="例如:用户物品主要涉及厨房用品和电子产品">{% if config.ai_search_extra_hints %}{{ config.ai_search_extra_hints }}{% endif %}</textarea>
</label>
<p class="checkbox-help">追加到 AI 搜索提示词末尾,帮助模型理解你的物品领域。留空则使用默认提示词。</p>
<div class="form-actions">
<button type="submit" class="button button-primary">保存设置</button>
<button type="submit" class="button button-secondary" formaction="/settings/test" formmethod="post">测试连接</button>