dknowc-dsh 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -4
- package/package.json +3 -3
- package/skills/dknowc-official-doc-writer/README.md +7 -2
- package/skills/dknowc-official-doc-writer/SKILL.md +38 -21
- package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/review_checklist.md +18 -14
- package/skills/dknowc-official-doc-writer/reference/revision_workflow.md +45 -0
- package/skills/dknowc-official-doc-writer/reference/sample_search_result.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +323 -57
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +22 -11
- package/skills/dknowc-official-doc-writer/reference/search_intro.md +14 -3
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +12 -10
- package/skills/dknowc-official-doc-writer/reference/task_router.md +12 -8
- package/skills/dknowc-official-doc-writer/scripts/check_release.py +10 -0
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +43 -9
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +7 -7
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +2 -5
- package/skills/dknowc-official-doc-writer/scripts/local_memory.py +3 -3
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +2 -3
- package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +12 -15
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +3 -1
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +958 -532
- package/skills/dknowc-official-doc-writer/scripts/review_document.py +0 -1
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +19 -2
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +4 -5
- package/skills/dknowc-ppt-assistant/README.md +7 -6
- package/skills/dknowc-ppt-assistant/SKILL.md +7 -5
- package/skills/dknowc-ppt-assistant/references/material_usage.md +20 -8
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +3 -3
- package/skills/dknowc-ppt-assistant/scripts/preview_slide_html.py +141 -0
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1037 -587
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +29 -17
- package/skills/dknowc-ppt-assistant/workflows/routing.md +2 -2
- package/skills/dknowc-trusted-consulting/README.md +17 -16
- package/skills/dknowc-trusted-consulting/SKILL.md +58 -30
- package/skills/dknowc-trusted-consulting/reference/consult_intro.md +3 -3
- package/skills/dknowc-trusted-consulting/reference/sample_consult_answer.md +4 -4
- package/skills/dknowc-trusted-consulting/reference/sample_trace_report.html +439 -58
- package/skills/dknowc-trusted-consulting/scripts/adapt_mcp_result.py +4 -0
- package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +0 -2
- package/skills/dknowc-trusted-consulting/scripts/render_trace_html.py +1164 -616
- package/skills/dknowc-trusted-search/README.md +2 -2
- package/skills/dknowc-trusted-search/SKILL.md +23 -17
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +402 -435
- package/skills/dknowc-trusted-search/scripts/adapt_mcp_result.py +19 -37
- package/skills/dknowc-trusted-search/scripts/deep_query.py +117 -137
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +1131 -584
- package/src/index.js +3 -3
|
@@ -20,10 +20,10 @@ trusted_search 内层(search 模式,需要映射):
|
|
|
20
20
|
(渲染脚本 extract_articles_from_search 只认中文键 data.检索文章)
|
|
21
21
|
knowledge_base_url → knowledgeBase / knowledgeBaseUrl(渲染脚本只认驼峰)
|
|
22
22
|
|
|
23
|
-
deep_query 内层(deep
|
|
24
|
-
|
|
25
|
-
(渲染脚本 extract_articles_from_deep
|
|
26
|
-
|
|
23
|
+
deep_query v3 内层(deep 模式,直通透传):
|
|
24
|
+
{code, msg, data:{searches[], common_articles[], traceId}}
|
|
25
|
+
(渲染脚本 1.1.4+ 的 extract_articles_from_deep 原生解析 v3)
|
|
26
|
+
code=500 转发失败为服务端偶发,透传由调用方重试
|
|
27
27
|
答案不由接口给出,由 Agent 基于材料形成后经 --answer-file 传入
|
|
28
28
|
|
|
29
29
|
用法:
|
|
@@ -88,7 +88,7 @@ def _extract_mcp_text(o: Any) -> Optional[str]:
|
|
|
88
88
|
if isinstance(result, dict):
|
|
89
89
|
return _extract_mcp_text(result)
|
|
90
90
|
# 已是业务 JSON(answer/materials/referenceMaterials 等特征键)
|
|
91
|
-
if any(k in o for k in ("answer", "referenceMaterials", "materials", "检索文章", "progress", "search_meta")):
|
|
91
|
+
if any(k in o for k in ("answer", "referenceMaterials", "materials", "检索文章", "progress", "search_meta", "searches", "common_articles", "code")):
|
|
92
92
|
return json.dumps(o, ensure_ascii=False)
|
|
93
93
|
return None
|
|
94
94
|
|
|
@@ -180,36 +180,18 @@ def _normalize_search(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
180
180
|
|
|
181
181
|
|
|
182
182
|
def _normalize_deep(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
183
|
-
"""规范化深度搜索(deep_query
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
"""规范化深度搜索(deep_query v3)返回:透传 v3 的 data.searches/common_articles。
|
|
184
|
+
|
|
185
|
+
v3(2026-08 实测):MCP 内层为 {code, msg, data:{searches[], common_articles[], traceId}}。
|
|
186
|
+
- code=0 成功;code=500 转发失败为服务端偶发问题,原样透传由调用方提示重试
|
|
187
|
+
- searches[]: 每组 {query, areas, result[]},result 为该子查询材料(中文键:
|
|
188
|
+
文章标题/源网址/数据源/发布日期/发布日期可信度/段落)
|
|
189
|
+
- common_articles[]: 多查询公共文章(含 办理地域)
|
|
190
|
+
渲染脚本(1.1.4+)的 extract_articles_from_deep 原生解析该结构,
|
|
191
|
+
此处把内层 JSON 提到顶层(保留 code/msg 供诊断)即可,无需字段映射。
|
|
192
|
+
深度搜索答案仍由 Agent 基于材料综合形成,经 --answer-file 传入渲染。
|
|
186
193
|
"""
|
|
187
194
|
out = dict(payload)
|
|
188
|
-
items: List[Dict[str, Any]] = []
|
|
189
|
-
mats = payload.get("materials")
|
|
190
|
-
if isinstance(mats, list):
|
|
191
|
-
items.extend([m for m in mats if isinstance(m, dict)])
|
|
192
|
-
groups = payload.get("search_groups")
|
|
193
|
-
if isinstance(groups, list):
|
|
194
|
-
for g in groups:
|
|
195
|
-
if isinstance(g, dict) and isinstance(g.get("materials"), list):
|
|
196
|
-
items.extend([m for m in g["materials"] if isinstance(m, dict)])
|
|
197
|
-
elif isinstance(g, dict):
|
|
198
|
-
# search_groups 条目本身可能就是材料(含 title/url 等特征键)
|
|
199
|
-
if any(k in g for k in ("title", "url", "sourceUrl")):
|
|
200
|
-
items.append(g)
|
|
201
|
-
if items:
|
|
202
|
-
# 渲染脚本 extract_articles_from_deep 消费顶层 data.list
|
|
203
|
-
out["data"] = {"list": items}
|
|
204
|
-
# 兼容旧直连 events 形态的防御提取
|
|
205
|
-
if "data" not in out:
|
|
206
|
-
events = payload.get("events")
|
|
207
|
-
if isinstance(events, list):
|
|
208
|
-
out["events"] = events
|
|
209
|
-
kb = payload.get("knowledge_base_url") or payload.get("knowledgeBase") or payload.get("knowledgeBaseUrl")
|
|
210
|
-
if isinstance(kb, str) and kb.strip():
|
|
211
|
-
out["knowledgeBase"] = kb
|
|
212
|
-
out["knowledgeBaseUrl"] = kb
|
|
213
195
|
return out
|
|
214
196
|
|
|
215
197
|
|
|
@@ -221,10 +203,10 @@ def detect_mode(payload: Dict[str, Any]) -> str:
|
|
|
221
203
|
会被误判(materials 为空列表也是 list)。
|
|
222
204
|
"""
|
|
223
205
|
if (
|
|
224
|
-
"
|
|
225
|
-
or isinstance(payload.get("
|
|
226
|
-
or
|
|
227
|
-
or
|
|
206
|
+
isinstance(payload.get("searches"), list)
|
|
207
|
+
or isinstance(payload.get("common_articles"), list)
|
|
208
|
+
or "traceId" in payload
|
|
209
|
+
or "code" in payload
|
|
228
210
|
):
|
|
229
211
|
return "deep"
|
|
230
212
|
if isinstance(payload.get("search_meta"), dict) or (
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""深知可信搜索深度搜索调用脚本。
|
|
3
3
|
|
|
4
|
-
调用 deep-query/
|
|
5
|
-
|
|
4
|
+
调用 deep-query/v3 非流式接口:一次 POST 返回完整 JSON,无 SSE 流式合并步骤。
|
|
5
|
+
适合复杂政策研究、方案设计和多轮查证。
|
|
6
|
+
请求体字段为 query;areas 支持一次传多个地域(逗号分隔),
|
|
7
|
+
服务端按地域自动拆分子查询。返回 data.searches(按子查询分组的材料)、
|
|
8
|
+
data.common_articles(多查询公共文章)与 traceId(链路追踪)。
|
|
6
9
|
"""
|
|
7
10
|
|
|
8
11
|
import argparse
|
|
@@ -14,21 +17,18 @@ import time
|
|
|
14
17
|
import urllib.error
|
|
15
18
|
import urllib.request
|
|
16
19
|
from pathlib import Path
|
|
17
|
-
from typing import Any, Dict,
|
|
20
|
+
from typing import Any, Dict, List, Optional
|
|
18
21
|
|
|
19
22
|
|
|
20
|
-
DEFAULT_ENDPOINT = "https://open.dknowc.cn/api/services/deep-query/
|
|
23
|
+
DEFAULT_ENDPOINT = "https://open.dknowc.cn/api/services/deep-query/v3"
|
|
21
24
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
22
|
-
#
|
|
25
|
+
# 产物根:dsh 会话隔离 <工作区>/dknowc-output/<DSH_SESSION_ID前8位>/;DKNWOC_WS_ROOT 显式优先;无会话回退 _default
|
|
23
26
|
import os as _os
|
|
24
27
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
25
28
|
if not _ws:
|
|
26
|
-
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<会话ID前8位>/,
|
|
27
|
-
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
28
29
|
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
29
30
|
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
30
31
|
WS_ROOT = Path(_ws).resolve()
|
|
31
|
-
|
|
32
32
|
SEARCH_RESULTS_DIR = WS_ROOT / "official-docs" / "search-results"
|
|
33
33
|
|
|
34
34
|
|
|
@@ -40,7 +40,7 @@ def resolve_output_json(output_path: str) -> Path:
|
|
|
40
40
|
elif raw_path.parent == Path("."):
|
|
41
41
|
resolved = (SEARCH_RESULTS_DIR / raw_path.name).resolve()
|
|
42
42
|
else:
|
|
43
|
-
resolved = raw_path.resolve()
|
|
43
|
+
resolved = (SKILL_ROOT / raw_path).resolve()
|
|
44
44
|
|
|
45
45
|
if resolved.suffix.lower() != ".json":
|
|
46
46
|
resolved = resolved.with_suffix(".json")
|
|
@@ -58,68 +58,42 @@ def _pick(*values: Optional[str]) -> str:
|
|
|
58
58
|
return ""
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
def
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return
|
|
61
|
+
def _split_areas(value: Optional[str]) -> List[str]:
|
|
62
|
+
"""v3 支持一次传多个地域:按逗号/顿号/分号拆分;单个地域直接使用。"""
|
|
63
|
+
if not value:
|
|
64
|
+
return []
|
|
65
|
+
areas: List[str] = []
|
|
66
|
+
for token in str(value).replace(",", ",").replace("、", ",").replace(";", ",").replace(";", ",").split(","):
|
|
67
|
+
token = token.strip()
|
|
68
|
+
if token and token not in areas:
|
|
69
|
+
areas.append(token)
|
|
70
|
+
return areas
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
def _build_payload(args: argparse.Namespace) -> Dict[str, Any]:
|
|
74
|
-
payload: Dict[str, Any] = {"
|
|
74
|
+
payload: Dict[str, Any] = {"query": args.question}
|
|
75
75
|
|
|
76
|
-
areas = args.area
|
|
76
|
+
areas = _split_areas(args.area)
|
|
77
77
|
if areas:
|
|
78
|
-
payload["areas"] =
|
|
78
|
+
payload["areas"] = areas
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
payload["queryId"] = query_id
|
|
80
|
+
if args.query_id:
|
|
81
|
+
payload["queryId"] = args.query_id
|
|
83
82
|
|
|
84
83
|
return payload
|
|
85
84
|
|
|
86
85
|
|
|
87
|
-
def
|
|
86
|
+
def _post(url: str, api_key: str, payload: Dict[str, Any], timeout: int) -> Dict[str, Any]:
|
|
87
|
+
"""非流式 POST:一次性读取完整 JSON 响应体。"""
|
|
88
88
|
data = json.dumps(payload, ensure_ascii=False).encode("utf-8")
|
|
89
89
|
req = urllib.request.Request(url, data=data, method="POST")
|
|
90
90
|
req.add_header("api-key", api_key)
|
|
91
91
|
req.add_header("Content-Type", "application/json")
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
timings = {"start": time.perf_counter(), "first_event": 0.0, "total": 0.0}
|
|
95
|
-
current_event = "message"
|
|
96
|
-
|
|
93
|
+
started = time.perf_counter()
|
|
97
94
|
try:
|
|
98
95
|
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
99
|
-
|
|
100
|
-
raw_line = resp.readline()
|
|
101
|
-
if not raw_line:
|
|
102
|
-
break
|
|
103
|
-
line = raw_line.decode("utf-8", errors="replace").replace("\x00", "").strip()
|
|
104
|
-
if not line:
|
|
105
|
-
continue
|
|
106
|
-
if line.startswith("event:"):
|
|
107
|
-
current_event = line.split(":", 1)[1].strip() or "message"
|
|
108
|
-
continue
|
|
109
|
-
if not line.startswith("data:"):
|
|
110
|
-
continue
|
|
111
|
-
chunk = line[5:].strip()
|
|
112
|
-
if chunk == "[DONE]":
|
|
113
|
-
break
|
|
114
|
-
try:
|
|
115
|
-
obj = json.loads(chunk)
|
|
116
|
-
except json.JSONDecodeError:
|
|
117
|
-
obj = {"raw": chunk}
|
|
118
|
-
if not timings["first_event"]:
|
|
119
|
-
timings["first_event"] = time.perf_counter() - timings["start"]
|
|
120
|
-
events.append((current_event, obj))
|
|
121
|
-
if current_event == "done":
|
|
122
|
-
break
|
|
96
|
+
text = resp.read().decode("utf-8", errors="replace").replace("\x00", "")
|
|
123
97
|
except urllib.error.HTTPError as e:
|
|
124
98
|
detail = e.read().decode("utf-8", errors="ignore")
|
|
125
99
|
print(f"错误:HTTP {e.code} {detail or e.reason}", file=sys.stderr)
|
|
@@ -130,28 +104,41 @@ def _post_sse(url: str, api_key: str, payload: Dict[str, Any], timeout: int) ->
|
|
|
130
104
|
except socket.timeout:
|
|
131
105
|
print("错误:深度搜索接口请求超时。该接口耗时较长,可适当增大 --timeout。", file=sys.stderr)
|
|
132
106
|
sys.exit(1)
|
|
133
|
-
|
|
134
|
-
timings["total"] = time.perf_counter() - timings["start"]
|
|
135
|
-
|
|
136
|
-
return events, timings
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def _query_id(events: Iterable[Tuple[str, Dict[str, Any]]]) -> str:
|
|
140
|
-
last = ""
|
|
141
|
-
for _, obj in events:
|
|
142
|
-
value = obj.get("queryId")
|
|
143
|
-
if isinstance(value, str) and value.strip():
|
|
144
|
-
last = value.strip()
|
|
145
|
-
return last
|
|
107
|
+
elapsed = time.perf_counter() - started
|
|
146
108
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return {}
|
|
109
|
+
try:
|
|
110
|
+
body = json.loads(text)
|
|
111
|
+
except json.JSONDecodeError:
|
|
112
|
+
return {"raw": text}
|
|
113
|
+
if isinstance(body, dict):
|
|
114
|
+
body["_elapsedSeconds"] = round(elapsed, 2)
|
|
115
|
+
return body
|
|
116
|
+
return {"data": body, "_elapsedSeconds": round(elapsed, 2)}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _flatten_articles(body: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
120
|
+
"""把 searches[].result 与 common_articles 按源网址去重摊平,供摘要展示。"""
|
|
121
|
+
data = body.get("data") if isinstance(body.get("data"), dict) else {}
|
|
122
|
+
seen: set = set()
|
|
123
|
+
out: List[Dict[str, Any]] = []
|
|
124
|
+
|
|
125
|
+
def add(article: Any) -> None:
|
|
126
|
+
if not isinstance(article, dict):
|
|
127
|
+
return
|
|
128
|
+
key = str(article.get("源网址") or article.get("文章标题") or "")
|
|
129
|
+
if key and key in seen:
|
|
130
|
+
return
|
|
131
|
+
if key:
|
|
132
|
+
seen.add(key)
|
|
133
|
+
out.append(article)
|
|
134
|
+
|
|
135
|
+
for search in data.get("searches") or []:
|
|
136
|
+
if isinstance(search, dict):
|
|
137
|
+
for article in search.get("result") or []:
|
|
138
|
+
add(article)
|
|
139
|
+
for article in data.get("common_articles") or []:
|
|
140
|
+
add(article)
|
|
141
|
+
return out
|
|
155
142
|
|
|
156
143
|
|
|
157
144
|
def _short(text: Any, limit: int = 180) -> str:
|
|
@@ -161,68 +148,67 @@ def _short(text: Any, limit: int = 180) -> str:
|
|
|
161
148
|
return value[:limit].rstrip() + "..."
|
|
162
149
|
|
|
163
150
|
|
|
164
|
-
def _print_summary(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if
|
|
178
|
-
print(f"
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
area =
|
|
200
|
-
|
|
201
|
-
url = vo.get("sourceUrl") or vo.get("url") or ""
|
|
151
|
+
def _print_summary(body: Dict[str, Any], show_materials: int) -> None:
|
|
152
|
+
code = body.get("code")
|
|
153
|
+
msg = body.get("message") or body.get("msg")
|
|
154
|
+
if code not in (0, None) or msg not in ("success", None, ""):
|
|
155
|
+
hint = ";该错误多为服务端转发失败,可稍后重试或调整问题表述" if code == 500 else ""
|
|
156
|
+
print(f"错误:深度搜索接口返回 code={code} {msg or ''}{hint}".strip())
|
|
157
|
+
return
|
|
158
|
+
|
|
159
|
+
data = body.get("data") if isinstance(body.get("data"), dict) else {}
|
|
160
|
+
searches = [s for s in (data.get("searches") or []) if isinstance(s, dict)]
|
|
161
|
+
common = [a for a in (data.get("common_articles") or []) if isinstance(a, dict)]
|
|
162
|
+
|
|
163
|
+
print("深度搜索结果(deep-query/v3 非流式)")
|
|
164
|
+
if body.get("_elapsedSeconds"):
|
|
165
|
+
print(f"总耗时:{body['_elapsedSeconds']:.2f} 秒")
|
|
166
|
+
|
|
167
|
+
if searches:
|
|
168
|
+
print(f"\n子查询分组:共 {len(searches)} 组")
|
|
169
|
+
for s in searches:
|
|
170
|
+
areas = "、".join(str(x) for x in (s.get("areas") or []))
|
|
171
|
+
print(f"- {s.get('query', '')}({areas}):{len(s.get('result') or [])} 篇")
|
|
172
|
+
|
|
173
|
+
articles = _flatten_articles(body)
|
|
174
|
+
if common:
|
|
175
|
+
print(f"\n多查询公共文章:{len(common)} 篇")
|
|
176
|
+
print(f"召回材料(去重后):{len(articles)} 篇")
|
|
177
|
+
if data.get("traceId"):
|
|
178
|
+
print(f"traceId:{data['traceId']}")
|
|
179
|
+
|
|
180
|
+
if articles and show_materials > 0:
|
|
181
|
+
print(f"\n重点材料(前 {min(show_materials, len(articles))} 篇)")
|
|
182
|
+
for idx, item in enumerate(articles[:show_materials], start=1):
|
|
183
|
+
title = item.get("文章标题") or "未命名材料"
|
|
184
|
+
agency = item.get("数据源") or ""
|
|
185
|
+
date = item.get("发布日期") or ""
|
|
186
|
+
area = item.get("办理地域") or ""
|
|
187
|
+
url = item.get("源网址") or ""
|
|
202
188
|
print(f"{idx}. {title}")
|
|
203
|
-
|
|
204
|
-
|
|
189
|
+
meta = [x for x in [agency, area, date] if x]
|
|
190
|
+
if meta:
|
|
191
|
+
print(f" {' | '.join(meta)}")
|
|
192
|
+
paragraphs = item.get("段落") or []
|
|
193
|
+
first_para = next((p.get("内容") for p in paragraphs if isinstance(p, dict) and p.get("内容")), "")
|
|
194
|
+
if first_para:
|
|
195
|
+
print(f" 摘要:{_short(first_para)}")
|
|
205
196
|
if url:
|
|
206
197
|
print(f" 原文:{url}")
|
|
207
198
|
|
|
208
|
-
event_names = [event for event, _ in events]
|
|
209
|
-
if "done" in event_names:
|
|
210
|
-
print("\n状态:检索完成")
|
|
211
|
-
|
|
212
199
|
|
|
213
200
|
def main() -> None:
|
|
214
|
-
parser = argparse.ArgumentParser(description="深知可信搜索 deep-query/
|
|
215
|
-
parser.add_argument("question", help="
|
|
201
|
+
parser = argparse.ArgumentParser(description="深知可信搜索 deep-query/v3 深度搜索调用脚本(非流式)")
|
|
202
|
+
parser.add_argument("question", help="用户复杂问题(请求体字段 query)")
|
|
216
203
|
parser.add_argument("--endpoint", help="覆盖深度搜索接口地址")
|
|
217
|
-
parser.add_argument("--area", help="
|
|
218
|
-
parser.add_argument("--query-id", help="显式传入 queryId
|
|
204
|
+
parser.add_argument("--area", help="办理地域;v3 支持逗号分隔一次传多个地域,服务端按地域拆分子查询")
|
|
205
|
+
parser.add_argument("--query-id", help="显式传入 queryId;默认不传,返回侧以 traceId 做链路追踪")
|
|
219
206
|
parser.add_argument("--show-payload", action="store_true", help="打印请求参数")
|
|
220
207
|
parser.add_argument("--dry-run", action="store_true", help="只打印请求参数,不发起请求")
|
|
221
|
-
parser.add_argument("--
|
|
222
|
-
parser.add_argument("--json-only", action="store_true", help="仅输出结构化 JSON")
|
|
208
|
+
parser.add_argument("--json-only", action="store_true", help="仅输出接口原始 JSON")
|
|
223
209
|
parser.add_argument("--output", "-o", help="深度搜索结果 JSON 文件名,写入 official-docs/search-results/(配合 --json-only 使用)")
|
|
224
|
-
parser.add_argument("--show-materials", type=int, default=5, help="摘要中展示前 N
|
|
225
|
-
parser.add_argument("--timeout", type=int, default=
|
|
210
|
+
parser.add_argument("--show-materials", type=int, default=5, help="摘要中展示前 N 篇材料")
|
|
211
|
+
parser.add_argument("--timeout", type=int, default=300, help="请求超时秒数")
|
|
226
212
|
args = parser.parse_args()
|
|
227
213
|
|
|
228
214
|
endpoint = _pick(
|
|
@@ -246,26 +232,20 @@ def main() -> None:
|
|
|
246
232
|
if args.dry_run:
|
|
247
233
|
return
|
|
248
234
|
|
|
249
|
-
|
|
235
|
+
body = _post(endpoint, api_key, payload, args.timeout)
|
|
250
236
|
|
|
251
237
|
if args.json_only:
|
|
252
|
-
raw_json = json.dumps(
|
|
238
|
+
raw_json = json.dumps(body, ensure_ascii=False, indent=2)
|
|
253
239
|
if args.output:
|
|
254
240
|
output_path = resolve_output_json(args.output)
|
|
255
241
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
256
242
|
output_path.write_text(raw_json, encoding="utf-8")
|
|
257
|
-
print(f"已保存深度搜索结果 JSON:{
|
|
243
|
+
print(f"已保存深度搜索结果 JSON:{output_path.relative_to(SKILL_ROOT)}")
|
|
258
244
|
else:
|
|
259
245
|
print(raw_json)
|
|
260
246
|
return
|
|
261
247
|
|
|
262
|
-
|
|
263
|
-
for event, obj in events:
|
|
264
|
-
print(f"event:{event}")
|
|
265
|
-
print(json.dumps(obj, ensure_ascii=False))
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
_print_summary(events, timings, args.show_materials)
|
|
248
|
+
_print_summary(body, args.show_materials)
|
|
269
249
|
|
|
270
250
|
|
|
271
251
|
if __name__ == "__main__":
|