T4: AnySearch 改为全局固定配置 + 修复外部服务弹窗 UI
This commit is contained in:
1 parent
3c9d9518b1
commit
97125d7b65
6 files changed
+634
-441
No files matched your search
@@ -1496,27 +1496,18 @@ async def web_search_endpoint(
|
||||
):
|
||||
"""联网检索(AnySearch):返回实时网页结果,供前端 / 智能体引用。"""
|
||||
try:
|
||||
from sqlalchemy import text
|
||||
import json as _json
|
||||
from ..anysearch_client import anysearch_search
|
||||
row = db.execute(text(
|
||||
"SELECT api_key, api_url, config FROM external_kb_services "
|
||||
"WHERE service_type='anysearch' AND is_enabled=1 LIMIT 1"
|
||||
)).fetchone()
|
||||
if not row:
|
||||
from ..anysearch_client import anysearch_search, load_anysearch_config
|
||||
cfg = load_anysearch_config(db)
|
||||
if not cfg.get("is_enabled") or not cfg.get("api_key"):
|
||||
return {"code": 0, "data": {"results": [], "enabled": False, "message": "未配置 AnySearch 联网检索服务"}}
|
||||
api_key = row[0] or ""
|
||||
api_url = row[1] or "https://api.anysearch.com/v1/search"
|
||||
cfg = row[2]
|
||||
if isinstance(cfg, str):
|
||||
try:
|
||||
cfg = _json.loads(cfg)
|
||||
except Exception:
|
||||
cfg = {}
|
||||
cfg = cfg or {}
|
||||
zone = cfg.get("zone", "cn")
|
||||
freshness = cfg.get("freshness")
|
||||
hits = await anysearch_search(api_key, api_url, req.query, top_k=req.top_k, zone=zone, freshness=freshness)
|
||||
hits = await anysearch_search(
|
||||
cfg["api_key"],
|
||||
cfg.get("api_url") or "https://api.anysearch.com/v1/search",
|
||||
req.query,
|
||||
top_k=req.top_k,
|
||||
zone=cfg.get("zone", "cn"),
|
||||
freshness=cfg.get("freshness"),
|
||||
)
|
||||
return {"code": 0, "data": {"results": hits, "enabled": True}}
|
||||
except Exception as e:
|
||||
logger.warning(f"web-search endpoint failed: {e}")
|
||||
|
||||
Reference in new issue
Block a user