feat(common problems fuzzy query): 增加常用问题模糊查询兜底
This commit is contained in:
1 parent
b69c725992
commit
5a269f940d
18 files changed
+411
-58
No files matched your search
@@ -2,7 +2,7 @@
|
||||
backend/app/services/admin/faq_service.py
|
||||
|
||||
用途:全局常用问题(QuickQuestion)与热点 FAQ 候选管理。
|
||||
依赖:models、faq_kb_invalidation、hot_faq_* services。
|
||||
依赖:models、faq_kb_invalidation、hot_faq_* services、faq_text_utils(模糊阈值钳制)。
|
||||
逻辑:由 api/admin/quick_questions.py、faq_candidates.py 调用。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
@@ -13,6 +13,7 @@ from typing import Any
|
||||
from app import db
|
||||
from app.core.errors import NotFoundError, ValidationError
|
||||
from app.models import Agent, KbDocument, QuickQuestion
|
||||
from app.services.faq_text_utils import clamp_fuzzy_threshold
|
||||
|
||||
|
||||
def parse_aliases(raw_aliases) -> list[str]:
|
||||
@@ -61,6 +62,8 @@ def serialize_quick_question(
|
||||
'aliases': q.aliases if isinstance(q.aliases, list) else [],
|
||||
'cache_enabled': bool(q.cache_enabled),
|
||||
'is_enabled': bool(q.is_enabled),
|
||||
'fuzzy_enabled': bool(getattr(q, 'fuzzy_enabled', False)),
|
||||
'fuzzy_threshold': clamp_fuzzy_threshold(getattr(q, 'fuzzy_threshold', None)),
|
||||
'hit_count': q.hit_count or 0,
|
||||
'agent_id': q.agent_id,
|
||||
'agent_name': agent_name,
|
||||
@@ -93,6 +96,12 @@ def apply_quick_question_payload(qq: QuickQuestion, data: dict, *, require_answe
|
||||
qq.cache_enabled = bool(data['cache_enabled'])
|
||||
if 'is_enabled' in data:
|
||||
qq.is_enabled = bool(data['is_enabled'])
|
||||
if 'fuzzy_enabled' in data:
|
||||
qq.fuzzy_enabled = bool(data['fuzzy_enabled'])
|
||||
if 'fuzzy_threshold' in data:
|
||||
qq.fuzzy_threshold = clamp_fuzzy_threshold(data['fuzzy_threshold'])
|
||||
else:
|
||||
qq.fuzzy_threshold = clamp_fuzzy_threshold(qq.fuzzy_threshold)
|
||||
if 'expires_at' in data:
|
||||
qq.expires_at = parse_expires_at(data['expires_at'])
|
||||
if 'retriever_resources' in data and isinstance(data.get('retriever_resources'), list):
|
||||
@@ -106,6 +115,8 @@ def apply_quick_question_payload(qq: QuickQuestion, data: dict, *, require_answe
|
||||
|
||||
if qq.cache_enabled and not str(qq.answer or '').strip():
|
||||
raise ValidationError('启用 FAQ 缓存时必须填写标准答案')
|
||||
if qq.fuzzy_enabled and not qq.cache_enabled:
|
||||
raise ValidationError('启用模糊匹配前需先启用 FAQ 缓存')
|
||||
if require_answer and (not qq.title or not qq.question or not qq.agent_id):
|
||||
raise ValidationError('Missing required fields')
|
||||
|
||||
|
||||
Reference in new issue
Block a user