feat: adapt preloaded skills to smart-reasoning agent
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
---
|
||||
name: 引用生成器
|
||||
description: 自动生成规范引用格式。当用户需要生成参考文献、引用来源、标注知识库内容出处、或要求提供引用信息时使用此技能。
|
||||
---
|
||||
|
||||
# Citation Generator
|
||||
|
||||
为知识库检索结果生成规范的引用格式。
|
||||
|
||||
## 核心能力
|
||||
|
||||
1. **来源标注**: 为回答中使用的每个知识点标注来源
|
||||
2. **格式化引用**: 支持多种引用格式(APA、MLA、Chicago、简化格式)
|
||||
3. **参考文献列表**: 在回答末尾生成完整的参考文献列表
|
||||
|
||||
## 引用格式
|
||||
|
||||
### 简化格式(默认)
|
||||
|
||||
对于知识库内容,使用以下格式:
|
||||
```
|
||||
[文档名称, 第X页/段落X]
|
||||
```
|
||||
|
||||
示例:
|
||||
```
|
||||
根据公司政策[员工手册2024.pdf, 第15页],年假申请需提前...
|
||||
```
|
||||
|
||||
### APA 格式
|
||||
|
||||
```
|
||||
作者. (年份). 标题. 来源.
|
||||
```
|
||||
|
||||
### 参考文献列表格式
|
||||
|
||||
在回答末尾,使用以下格式列出所有引用:
|
||||
|
||||
```
|
||||
---
|
||||
**参考文献**
|
||||
|
||||
1. [1] 文档A - 第X章/第Y页
|
||||
2. [2] 文档B - 第Z段
|
||||
```
|
||||
|
||||
## 使用指南
|
||||
|
||||
1. **检索内容时**: 记录每个检索结果的来源信息(文档名、页码、分块ID)
|
||||
2. **引用时**: 在使用知识点后立即标注来源
|
||||
3. **汇总时**: 在回答末尾列出完整参考文献
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 如果检索结果未提供页码,使用分块或段落编号
|
||||
- 对于同一文档的多次引用,可合并为一条
|
||||
- 引用应准确对应原文内容,不可虚构来源
|
||||
@@ -0,0 +1,154 @@
|
||||
---
|
||||
name: 数据处理器
|
||||
description: 数据处理与分析技能。当用户需要对知识库检索结果进行数据分析、统计计算、格式转换、数据提取或生成报告时使用此技能。支持 Python 脚本执行进行高级数据处理。
|
||||
---
|
||||
|
||||
# Data Processor
|
||||
|
||||
企业级知识库数据处理与分析技能,用于处理 RAG 检索结果和执行数据分析任务。
|
||||
|
||||
## 核心能力
|
||||
|
||||
1. **数据分析**: 对检索到的文档数据进行统计分析
|
||||
2. **格式转换**: JSON/CSV/Markdown 等格式相互转换
|
||||
3. **数据提取**: 从非结构化文本中提取结构化信息
|
||||
4. **报告生成**: 生成数据分析报告和摘要
|
||||
|
||||
## 使用场景
|
||||
|
||||
当用户请求涉及以下内容时,使用此技能:
|
||||
- "分析这些数据"、"统计一下"、"计算总数/平均值"
|
||||
- "转换为 JSON/CSV 格式"
|
||||
- "提取关键信息"、"整理成表格"
|
||||
- "生成报告"、"数据汇总"
|
||||
|
||||
## 可用脚本
|
||||
|
||||
### 1. analyze.py - 数据分析脚本
|
||||
|
||||
分析输入的 JSON 数据,生成统计报告。
|
||||
|
||||
**用法**:
|
||||
```bash
|
||||
# 通过 stdin 传入 JSON 数据
|
||||
echo '{"items": [1, 2, 3, 4, 5]}' | python scripts/analyze.py
|
||||
|
||||
# 或传入文件路径
|
||||
python scripts/analyze.py --file data.json
|
||||
```
|
||||
|
||||
**输入格式**:
|
||||
```json
|
||||
{
|
||||
"items": [数据项数组],
|
||||
"query": "可选的查询描述"
|
||||
}
|
||||
```
|
||||
|
||||
**输出**: JSON 格式的统计结果,包含计数、求和、平均值等。
|
||||
|
||||
### 2. format_converter.py - 格式转换脚本
|
||||
|
||||
在 JSON、CSV、Markdown 表格之间转换数据。
|
||||
|
||||
**用法**:
|
||||
```bash
|
||||
# JSON 转 CSV
|
||||
echo '[{"name": "A", "value": 1}]' | python scripts/format_converter.py --to csv
|
||||
|
||||
# JSON 转 Markdown 表格
|
||||
echo '[{"name": "A", "value": 1}]' | python scripts/format_converter.py --to markdown
|
||||
|
||||
# CSV 转 JSON
|
||||
echo 'name,value\nA,1' | python scripts/format_converter.py --from csv --to json
|
||||
```
|
||||
|
||||
### 3. extract_info.py - 信息提取脚本
|
||||
|
||||
从文本中提取结构化信息(数字、日期、关键词等)。
|
||||
|
||||
**用法**:
|
||||
```bash
|
||||
echo "2024年销售额为100万元,同比增长15%" | python scripts/extract_info.py
|
||||
```
|
||||
|
||||
**输出**:
|
||||
```json
|
||||
{
|
||||
"numbers": ["100", "15"],
|
||||
"dates": ["2024年"],
|
||||
"percentages": ["15%"],
|
||||
"amounts": ["100万元"]
|
||||
}
|
||||
```
|
||||
|
||||
## 处理流程
|
||||
|
||||
### 分析 RAG 检索结果
|
||||
|
||||
当需要分析知识库检索结果时:
|
||||
|
||||
1. 收集检索到的文档片段
|
||||
2. 提取关键数据点
|
||||
3. 使用 `analyze.py` 进行统计
|
||||
4. 整理并呈现分析结果
|
||||
|
||||
**示例**:
|
||||
```
|
||||
用户: "帮我统计知识库中提到的所有产品销售数据"
|
||||
|
||||
步骤:
|
||||
1. 使用 knowledge_search 检索相关文档
|
||||
2. 整理数据为 JSON 格式
|
||||
3. 调用 execute_skill_script:
|
||||
- skill_name: "data-processor"
|
||||
- script_path: "scripts/analyze.py"
|
||||
- 通过 stdin 传入数据
|
||||
4. 解析输出并生成报告
|
||||
```
|
||||
|
||||
### 数据格式转换
|
||||
|
||||
当用户需要特定格式输出时:
|
||||
|
||||
1. 整理数据为标准 JSON 格式
|
||||
2. 使用 `format_converter.py` 转换
|
||||
3. 返回目标格式结果
|
||||
|
||||
## 最佳实践
|
||||
|
||||
1. **数据预处理**: 调用脚本前,确保数据格式正确
|
||||
2. **错误处理**: 检查脚本执行结果,处理异常情况
|
||||
3. **结果验证**: 验证输出结果的合理性
|
||||
4. **渐进处理**: 大数据量时分批处理
|
||||
|
||||
## 输出格式
|
||||
|
||||
分析结果示例:
|
||||
```markdown
|
||||
## 数据分析报告
|
||||
|
||||
### 基本统计
|
||||
- 数据条数: 50
|
||||
- 数值总和: 1,234,567
|
||||
- 平均值: 24,691.34
|
||||
- 最大值: 99,999
|
||||
- 最小值: 100
|
||||
|
||||
### 分布情况
|
||||
| 区间 | 数量 | 占比 |
|
||||
|------|------|------|
|
||||
| 0-1000 | 10 | 20% |
|
||||
| 1000-10000 | 25 | 50% |
|
||||
| >10000 | 15 | 30% |
|
||||
|
||||
### 结论
|
||||
根据数据分析,XXX...
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 脚本在 Docker 沙箱中执行,确保安全隔离
|
||||
- 执行超时默认为 60 秒
|
||||
- 输入数据大小有限制,大文件请分批处理
|
||||
- 脚本输出为 JSON 格式,便于后续处理
|
||||
@@ -0,0 +1,250 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
数据分析脚本 - 用于分析 RAG 检索结果和知识库数据
|
||||
|
||||
支持功能:
|
||||
- 基本统计(计数、求和、平均值、最大/最小值)
|
||||
- 数值分布分析
|
||||
- 文本统计(词频、字符数)
|
||||
|
||||
用法:
|
||||
# 通过 stdin 传入 JSON 数据
|
||||
echo '{"items": [1, 2, 3, 4, 5]}' | python analyze.py
|
||||
|
||||
# 通过参数传入文件
|
||||
python analyze.py --file data.json
|
||||
|
||||
# 指定分析类型
|
||||
echo '{"items": [1, 2, 3]}' | python analyze.py --type numeric
|
||||
"""
|
||||
|
||||
import sys
|
||||
import json
|
||||
import argparse
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def analyze_numeric(data: list) -> dict:
|
||||
"""分析数值数据"""
|
||||
if not data:
|
||||
return {"error": "空数据集"}
|
||||
|
||||
# 过滤出数值
|
||||
numbers = [x for x in data if isinstance(x, (int, float))]
|
||||
if not numbers:
|
||||
return {"error": "无有效数值数据"}
|
||||
|
||||
numbers.sort()
|
||||
n = len(numbers)
|
||||
|
||||
result = {
|
||||
"count": n,
|
||||
"sum": sum(numbers),
|
||||
"mean": sum(numbers) / n,
|
||||
"min": min(numbers),
|
||||
"max": max(numbers),
|
||||
"median": numbers[n // 2] if n % 2 == 1 else (numbers[n // 2 - 1] + numbers[n // 2]) / 2,
|
||||
}
|
||||
|
||||
# 计算标准差
|
||||
mean = result["mean"]
|
||||
variance = sum((x - mean) ** 2 for x in numbers) / n
|
||||
result["std_dev"] = variance ** 0.5
|
||||
|
||||
# 分布统计
|
||||
if n >= 5:
|
||||
result["quartiles"] = {
|
||||
"q1": numbers[n // 4],
|
||||
"q2": result["median"],
|
||||
"q3": numbers[3 * n // 4]
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def analyze_text(data: list) -> dict:
|
||||
"""分析文本数据"""
|
||||
if not data:
|
||||
return {"error": "空数据集"}
|
||||
|
||||
texts = [str(x) for x in data if x]
|
||||
|
||||
# 基本统计
|
||||
total_chars = sum(len(t) for t in texts)
|
||||
total_words = sum(len(t.split()) for t in texts)
|
||||
|
||||
# 词频统计(简单分词)
|
||||
all_words = []
|
||||
for text in texts:
|
||||
words = text.split()
|
||||
all_words.extend(w.strip('.,!?;:""\'()[]{}') for w in words if w.strip())
|
||||
|
||||
word_freq = Counter(all_words)
|
||||
|
||||
result = {
|
||||
"count": len(texts),
|
||||
"total_chars": total_chars,
|
||||
"total_words": total_words,
|
||||
"avg_chars_per_item": total_chars / len(texts) if texts else 0,
|
||||
"avg_words_per_item": total_words / len(texts) if texts else 0,
|
||||
"top_words": dict(word_freq.most_common(10)),
|
||||
"unique_words": len(word_freq)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def analyze_mixed(data: list) -> dict:
|
||||
"""分析混合数据"""
|
||||
if not data:
|
||||
return {"error": "空数据集"}
|
||||
|
||||
# 类型统计
|
||||
type_counts = Counter(type(x).__name__ for x in data)
|
||||
|
||||
result = {
|
||||
"total_items": len(data),
|
||||
"type_distribution": dict(type_counts),
|
||||
}
|
||||
|
||||
# 分别分析数值和文本
|
||||
numbers = [x for x in data if isinstance(x, (int, float))]
|
||||
texts = [x for x in data if isinstance(x, str)]
|
||||
|
||||
if numbers:
|
||||
result["numeric_analysis"] = analyze_numeric(numbers)
|
||||
if texts:
|
||||
result["text_analysis"] = analyze_text(texts)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def analyze_dict_list(data: list) -> dict:
|
||||
"""分析字典列表(如数据库查询结果)"""
|
||||
if not data:
|
||||
return {"error": "空数据集"}
|
||||
|
||||
if not all(isinstance(x, dict) for x in data):
|
||||
return {"error": "数据格式不正确,需要字典列表"}
|
||||
|
||||
result = {
|
||||
"record_count": len(data),
|
||||
"fields": {},
|
||||
}
|
||||
|
||||
# 获取所有字段
|
||||
all_keys = set()
|
||||
for item in data:
|
||||
all_keys.update(item.keys())
|
||||
|
||||
# 分析每个字段
|
||||
for key in all_keys:
|
||||
values = [item.get(key) for item in data if key in item]
|
||||
|
||||
# 判断字段类型
|
||||
non_null_values = [v for v in values if v is not None]
|
||||
if not non_null_values:
|
||||
result["fields"][key] = {"type": "all_null", "null_count": len(values)}
|
||||
continue
|
||||
|
||||
sample = non_null_values[0]
|
||||
if isinstance(sample, (int, float)):
|
||||
field_analysis = analyze_numeric(non_null_values)
|
||||
field_analysis["type"] = "numeric"
|
||||
elif isinstance(sample, str):
|
||||
field_analysis = analyze_text(non_null_values)
|
||||
field_analysis["type"] = "text"
|
||||
else:
|
||||
field_analysis = {"type": type(sample).__name__, "count": len(non_null_values)}
|
||||
|
||||
field_analysis["null_count"] = len(values) - len(non_null_values)
|
||||
result["fields"][key] = field_analysis
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="数据分析工具")
|
||||
parser.add_argument("--file", "-f", help="输入文件路径")
|
||||
parser.add_argument("--type", "-t", choices=["numeric", "text", "mixed", "auto"],
|
||||
default="auto", help="分析类型")
|
||||
parser.add_argument("--pretty", "-p", action="store_true", help="格式化输出")
|
||||
args = parser.parse_args()
|
||||
|
||||
# 读取输入
|
||||
try:
|
||||
if args.file:
|
||||
with open(args.file, 'r', encoding='utf-8') as f:
|
||||
raw_data = f.read()
|
||||
else:
|
||||
raw_data = sys.stdin.read()
|
||||
|
||||
if not raw_data.strip():
|
||||
print(json.dumps({"error": "空输入"}))
|
||||
return
|
||||
|
||||
data = json.loads(raw_data)
|
||||
except json.JSONDecodeError as e:
|
||||
print(json.dumps({"error": f"JSON 解析错误: {str(e)}"}))
|
||||
return
|
||||
except FileNotFoundError:
|
||||
print(json.dumps({"error": f"文件未找到: {args.file}"}))
|
||||
return
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": f"读取错误: {str(e)}"}))
|
||||
return
|
||||
|
||||
# 提取数据
|
||||
items = None
|
||||
if isinstance(data, dict):
|
||||
if "items" in data:
|
||||
items = data["items"]
|
||||
elif "data" in data:
|
||||
items = data["data"]
|
||||
elif "results" in data:
|
||||
items = data["results"]
|
||||
else:
|
||||
# 假设整个 dict 是单条记录,包装成列表
|
||||
items = [data]
|
||||
elif isinstance(data, list):
|
||||
items = data
|
||||
else:
|
||||
print(json.dumps({"error": "不支持的数据格式,需要列表或包含 items/data/results 的字典"}))
|
||||
return
|
||||
|
||||
# 根据类型分析
|
||||
if args.type == "auto":
|
||||
# 自动检测
|
||||
if items and all(isinstance(x, dict) for x in items):
|
||||
result = analyze_dict_list(items)
|
||||
elif items and all(isinstance(x, (int, float)) for x in items):
|
||||
result = analyze_numeric(items)
|
||||
elif items and all(isinstance(x, str) for x in items):
|
||||
result = analyze_text(items)
|
||||
else:
|
||||
result = analyze_mixed(items)
|
||||
elif args.type == "numeric":
|
||||
result = analyze_numeric(items)
|
||||
elif args.type == "text":
|
||||
result = analyze_text(items)
|
||||
else:
|
||||
result = analyze_mixed(items)
|
||||
|
||||
# 添加元信息
|
||||
output = {
|
||||
"success": True,
|
||||
"analysis": result,
|
||||
"metadata": {
|
||||
"input_type": type(data).__name__,
|
||||
"item_count": len(items) if items else 0,
|
||||
"analysis_type": args.type
|
||||
}
|
||||
}
|
||||
|
||||
# 输出
|
||||
indent = 2 if args.pretty else None
|
||||
print(json.dumps(output, ensure_ascii=False, indent=indent))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,199 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
信息提取脚本 - 从文本中提取结构化信息
|
||||
|
||||
提取内容:
|
||||
- 数字
|
||||
- 日期
|
||||
- 百分比
|
||||
- 金额
|
||||
- 邮箱
|
||||
- URL
|
||||
- 电话号码
|
||||
|
||||
用法:
|
||||
echo "2024年销售额为100万元,同比增长15%" | python extract_info.py
|
||||
|
||||
# 指定提取类型
|
||||
echo "联系我: test@example.com 或 13800138000" | python extract_info.py --types email,phone
|
||||
"""
|
||||
|
||||
import sys
|
||||
import json
|
||||
import argparse
|
||||
import re
|
||||
|
||||
|
||||
def extract_numbers(text: str) -> list:
|
||||
"""提取数字"""
|
||||
# 匹配整数和小数
|
||||
pattern = r'-?\d+(?:\.\d+)?'
|
||||
numbers = re.findall(pattern, text)
|
||||
# 转换为数值
|
||||
result = []
|
||||
for n in numbers:
|
||||
try:
|
||||
if '.' in n:
|
||||
result.append(float(n))
|
||||
else:
|
||||
result.append(int(n))
|
||||
except ValueError:
|
||||
result.append(n)
|
||||
return result
|
||||
|
||||
|
||||
def extract_dates(text: str) -> list:
|
||||
"""提取日期"""
|
||||
patterns = [
|
||||
r'\d{4}[-/年]\d{1,2}[-/月]\d{1,2}[日]?', # 2024-01-01 或 2024年1月1日
|
||||
r'\d{4}[-/年]\d{1,2}[月]?', # 2024-01 或 2024年1月
|
||||
r'\d{4}年', # 2024年
|
||||
r'\d{1,2}[-/月]\d{1,2}[日]?', # 01-01 或 1月1日
|
||||
]
|
||||
|
||||
dates = []
|
||||
for pattern in patterns:
|
||||
matches = re.findall(pattern, text)
|
||||
dates.extend(matches)
|
||||
|
||||
return list(set(dates))
|
||||
|
||||
|
||||
def extract_percentages(text: str) -> list:
|
||||
"""提取百分比"""
|
||||
pattern = r'-?\d+(?:\.\d+)?%'
|
||||
return re.findall(pattern, text)
|
||||
|
||||
|
||||
def extract_amounts(text: str) -> list:
|
||||
"""提取金额"""
|
||||
patterns = [
|
||||
r'[¥$€£]\s*\d+(?:,\d{3})*(?:\.\d+)?', # ¥100.00
|
||||
r'\d+(?:,\d{3})*(?:\.\d+)?\s*[元万亿美金]', # 100万元
|
||||
r'\d+(?:\.\d+)?[百千万亿]+[元]?', # 100万
|
||||
]
|
||||
|
||||
amounts = []
|
||||
for pattern in patterns:
|
||||
matches = re.findall(pattern, text)
|
||||
amounts.extend(matches)
|
||||
|
||||
return list(set(amounts))
|
||||
|
||||
|
||||
def extract_emails(text: str) -> list:
|
||||
"""提取邮箱"""
|
||||
pattern = r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
|
||||
return re.findall(pattern, text)
|
||||
|
||||
|
||||
def extract_urls(text: str) -> list:
|
||||
"""提取 URL"""
|
||||
pattern = r'https?://[^\s<>"{}|\\^`\[\]]+'
|
||||
return re.findall(pattern, text)
|
||||
|
||||
|
||||
def extract_phones(text: str) -> list:
|
||||
"""提取电话号码"""
|
||||
patterns = [
|
||||
r'1[3-9]\d{9}', # 手机号
|
||||
r'\d{3,4}[-\s]?\d{7,8}', # 固话
|
||||
r'\+\d{1,3}[-\s]?\d{10,12}', # 国际号码
|
||||
]
|
||||
|
||||
phones = []
|
||||
for pattern in patterns:
|
||||
matches = re.findall(pattern, text)
|
||||
phones.extend(matches)
|
||||
|
||||
return list(set(phones))
|
||||
|
||||
|
||||
def extract_keywords(text: str, min_len: int = 2) -> list:
|
||||
"""提取关键词(中文和英文)"""
|
||||
# 中文关键词
|
||||
chinese_pattern = r'[\u4e00-\u9fa5]{2,}'
|
||||
chinese_words = re.findall(chinese_pattern, text)
|
||||
|
||||
# 英文关键词
|
||||
english_pattern = r'[a-zA-Z]{3,}'
|
||||
english_words = re.findall(english_pattern, text)
|
||||
|
||||
# 统计词频
|
||||
from collections import Counter
|
||||
words = chinese_words + [w.lower() for w in english_words]
|
||||
|
||||
# 过滤停用词
|
||||
stopwords = {'的', '是', '在', '了', '和', '与', '或', '为', '有', '这', '那', '等',
|
||||
'the', 'is', 'are', 'was', 'were', 'and', 'or', 'for', 'with', 'this'}
|
||||
words = [w for w in words if w not in stopwords and len(w) >= min_len]
|
||||
|
||||
word_freq = Counter(words)
|
||||
return [{"word": w, "count": c} for w, c in word_freq.most_common(20)]
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="信息提取工具")
|
||||
parser.add_argument("--types", "-t",
|
||||
help="要提取的类型,逗号分隔 (numbers,dates,percentages,amounts,emails,urls,phones,keywords)")
|
||||
parser.add_argument("--pretty", "-p", action="store_true", help="格式化输出")
|
||||
args = parser.parse_args()
|
||||
|
||||
# 读取输入
|
||||
try:
|
||||
text = sys.stdin.read()
|
||||
if not text.strip():
|
||||
print(json.dumps({"error": "空输入"}))
|
||||
return
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": f"读取错误: {str(e)}"}))
|
||||
return
|
||||
|
||||
# 确定要提取的类型
|
||||
all_types = ["numbers", "dates", "percentages", "amounts", "emails", "urls", "phones", "keywords"]
|
||||
if args.types:
|
||||
extract_types = [t.strip().lower() for t in args.types.split(",")]
|
||||
else:
|
||||
extract_types = all_types
|
||||
|
||||
# 提取信息
|
||||
result = {
|
||||
"success": True,
|
||||
"text_length": len(text),
|
||||
"extracted": {}
|
||||
}
|
||||
|
||||
extractors = {
|
||||
"numbers": extract_numbers,
|
||||
"dates": extract_dates,
|
||||
"percentages": extract_percentages,
|
||||
"amounts": extract_amounts,
|
||||
"emails": extract_emails,
|
||||
"urls": extract_urls,
|
||||
"phones": extract_phones,
|
||||
"keywords": extract_keywords,
|
||||
}
|
||||
|
||||
for ext_type in extract_types:
|
||||
if ext_type in extractors:
|
||||
try:
|
||||
extracted = extractors[ext_type](text)
|
||||
if extracted:
|
||||
result["extracted"][ext_type] = extracted
|
||||
except Exception as e:
|
||||
result["extracted"][ext_type] = {"error": str(e)}
|
||||
|
||||
# 统计
|
||||
result["summary"] = {
|
||||
"total_extractions": sum(len(v) if isinstance(v, list) else 0
|
||||
for v in result["extracted"].values()),
|
||||
"types_found": list(result["extracted"].keys())
|
||||
}
|
||||
|
||||
# 输出
|
||||
indent = 2 if args.pretty else None
|
||||
print(json.dumps(result, ensure_ascii=False, indent=indent))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,206 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
格式转换脚本 - JSON/CSV/Markdown 相互转换
|
||||
|
||||
用法:
|
||||
# JSON 转 CSV
|
||||
echo '[{"name": "A", "value": 1}]' | python format_converter.py --to csv
|
||||
|
||||
# JSON 转 Markdown 表格
|
||||
echo '[{"name": "A", "value": 1}]' | python format_converter.py --to markdown
|
||||
|
||||
# CSV 转 JSON
|
||||
cat data.csv | python format_converter.py --from csv --to json
|
||||
"""
|
||||
|
||||
import sys
|
||||
import json
|
||||
import argparse
|
||||
import csv
|
||||
import io
|
||||
|
||||
|
||||
def json_to_csv(data: list) -> str:
|
||||
"""将 JSON 列表转换为 CSV"""
|
||||
if not data:
|
||||
return ""
|
||||
|
||||
if not all(isinstance(x, dict) for x in data):
|
||||
raise ValueError("JSON 数据必须是字典列表")
|
||||
|
||||
# 获取所有字段
|
||||
fieldnames = []
|
||||
for item in data:
|
||||
for key in item.keys():
|
||||
if key not in fieldnames:
|
||||
fieldnames.append(key)
|
||||
|
||||
output = io.StringIO()
|
||||
writer = csv.DictWriter(output, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
writer.writerows(data)
|
||||
|
||||
return output.getvalue()
|
||||
|
||||
|
||||
def csv_to_json(csv_text: str) -> list:
|
||||
"""将 CSV 转换为 JSON 列表"""
|
||||
reader = csv.DictReader(io.StringIO(csv_text))
|
||||
return list(reader)
|
||||
|
||||
|
||||
def json_to_markdown(data: list) -> str:
|
||||
"""将 JSON 列表转换为 Markdown 表格"""
|
||||
if not data:
|
||||
return ""
|
||||
|
||||
if not all(isinstance(x, dict) for x in data):
|
||||
raise ValueError("JSON 数据必须是字典列表")
|
||||
|
||||
# 获取所有字段
|
||||
fieldnames = []
|
||||
for item in data:
|
||||
for key in item.keys():
|
||||
if key not in fieldnames:
|
||||
fieldnames.append(key)
|
||||
|
||||
# 构建表头
|
||||
lines = []
|
||||
lines.append("| " + " | ".join(fieldnames) + " |")
|
||||
lines.append("| " + " | ".join(["---"] * len(fieldnames)) + " |")
|
||||
|
||||
# 构建数据行
|
||||
for item in data:
|
||||
row = []
|
||||
for field in fieldnames:
|
||||
value = item.get(field, "")
|
||||
# 转义 Markdown 特殊字符
|
||||
str_value = str(value) if value is not None else ""
|
||||
str_value = str_value.replace("|", "\\|")
|
||||
row.append(str_value)
|
||||
lines.append("| " + " | ".join(row) + " |")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def markdown_to_json(md_text: str) -> list:
|
||||
"""将 Markdown 表格转换为 JSON 列表"""
|
||||
lines = [line.strip() for line in md_text.strip().split("\n") if line.strip()]
|
||||
|
||||
if len(lines) < 2:
|
||||
raise ValueError("无效的 Markdown 表格")
|
||||
|
||||
# 解析表头
|
||||
header_line = lines[0]
|
||||
if not header_line.startswith("|"):
|
||||
raise ValueError("无效的 Markdown 表格格式")
|
||||
|
||||
headers = [h.strip() for h in header_line.strip("|").split("|")]
|
||||
|
||||
# 跳过分隔行
|
||||
data_lines = lines[2:] if len(lines) > 2 else []
|
||||
|
||||
# 解析数据
|
||||
result = []
|
||||
for line in data_lines:
|
||||
if not line.startswith("|"):
|
||||
continue
|
||||
values = [v.strip() for v in line.strip("|").split("|")]
|
||||
item = {}
|
||||
for i, header in enumerate(headers):
|
||||
if i < len(values):
|
||||
item[header] = values[i]
|
||||
result.append(item)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def detect_format(text: str) -> str:
|
||||
"""自动检测输入格式"""
|
||||
text = text.strip()
|
||||
|
||||
if text.startswith("[") or text.startswith("{"):
|
||||
return "json"
|
||||
elif text.startswith("|"):
|
||||
return "markdown"
|
||||
elif "," in text.split("\n")[0]:
|
||||
return "csv"
|
||||
else:
|
||||
return "unknown"
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="数据格式转换工具")
|
||||
parser.add_argument("--from", "-f", dest="from_format",
|
||||
choices=["json", "csv", "markdown", "auto"],
|
||||
default="auto", help="输入格式")
|
||||
parser.add_argument("--to", "-t", dest="to_format",
|
||||
choices=["json", "csv", "markdown"],
|
||||
required=True, help="输出格式")
|
||||
parser.add_argument("--pretty", "-p", action="store_true", help="格式化输出")
|
||||
args = parser.parse_args()
|
||||
|
||||
# 读取输入
|
||||
try:
|
||||
raw_input = sys.stdin.read()
|
||||
if not raw_input.strip():
|
||||
print(json.dumps({"error": "空输入"}))
|
||||
return
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": f"读取错误: {str(e)}"}))
|
||||
return
|
||||
|
||||
# 检测输入格式
|
||||
from_format = args.from_format
|
||||
if from_format == "auto":
|
||||
from_format = detect_format(raw_input)
|
||||
if from_format == "unknown":
|
||||
print(json.dumps({"error": "无法自动检测输入格式"}))
|
||||
return
|
||||
|
||||
# 转换为中间格式(JSON 列表)
|
||||
try:
|
||||
if from_format == "json":
|
||||
data = json.loads(raw_input)
|
||||
if isinstance(data, dict):
|
||||
# 尝试提取列表
|
||||
if "items" in data:
|
||||
data = data["items"]
|
||||
elif "data" in data:
|
||||
data = data["data"]
|
||||
else:
|
||||
data = [data]
|
||||
if not isinstance(data, list):
|
||||
data = [data]
|
||||
elif from_format == "csv":
|
||||
data = csv_to_json(raw_input)
|
||||
elif from_format == "markdown":
|
||||
data = markdown_to_json(raw_input)
|
||||
else:
|
||||
print(json.dumps({"error": f"不支持的输入格式: {from_format}"}))
|
||||
return
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": f"解析输入失败: {str(e)}"}))
|
||||
return
|
||||
|
||||
# 转换为目标格式
|
||||
try:
|
||||
if args.to_format == "json":
|
||||
indent = 2 if args.pretty else None
|
||||
output = json.dumps(data, ensure_ascii=False, indent=indent)
|
||||
elif args.to_format == "csv":
|
||||
output = json_to_csv(data)
|
||||
elif args.to_format == "markdown":
|
||||
output = json_to_markdown(data)
|
||||
else:
|
||||
print(json.dumps({"error": f"不支持的输出格式: {args.to_format}"}))
|
||||
return
|
||||
|
||||
print(output)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": f"转换失败: {str(e)}"}))
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,375 @@
|
||||
---
|
||||
name: 文档协作
|
||||
description: 引导用户通过结构化的文档共同编写工作流程。当用户想撰写文档、提案、技术规范、决策文档或类似结构化内容时使用。该工作流程帮助用户高效传递上下文,通过迭代优化内容,并验证文档对读者有效。当用户提到写文档、创建提案、起草规范或类似文档任务时触发。
|
||||
---
|
||||
|
||||
# Doc Co-Authoring Workflow
|
||||
|
||||
This skill provides a structured workflow for guiding users through collaborative document creation. Act as an active guide, walking users through three stages: Context Gathering, Refinement & Structure, and Reader Testing.
|
||||
|
||||
## When to Offer This Workflow
|
||||
|
||||
**Trigger conditions:**
|
||||
- User mentions writing documentation: "write a doc", "draft a proposal", "create a spec", "write up"
|
||||
- User mentions specific doc types: "PRD", "design doc", "decision doc", "RFC"
|
||||
- User seems to be starting a substantial writing task
|
||||
|
||||
**Initial offer:**
|
||||
Offer the user a structured workflow for co-authoring the document. Explain the three stages:
|
||||
|
||||
1. **Context Gathering**: User provides all relevant context while Claude asks clarifying questions
|
||||
2. **Refinement & Structure**: Iteratively build each section through brainstorming and editing
|
||||
3. **Reader Testing**: Test the doc with a fresh Claude (no context) to catch blind spots before others read it
|
||||
|
||||
Explain that this approach helps ensure the doc works well when others read it (including when they paste it into Claude). Ask if they want to try this workflow or prefer to work freeform.
|
||||
|
||||
If user declines, work freeform. If user accepts, proceed to Stage 1.
|
||||
|
||||
## Stage 1: Context Gathering
|
||||
|
||||
**Goal:** Close the gap between what the user knows and what Claude knows, enabling smart guidance later.
|
||||
|
||||
### Initial Questions
|
||||
|
||||
Start by asking the user for meta-context about the document:
|
||||
|
||||
1. What type of document is this? (e.g., technical spec, decision doc, proposal)
|
||||
2. Who's the primary audience?
|
||||
3. What's the desired impact when someone reads this?
|
||||
4. Is there a template or specific format to follow?
|
||||
5. Any other constraints or context to know?
|
||||
|
||||
Inform them they can answer in shorthand or dump information however works best for them.
|
||||
|
||||
**If user provides a template or mentions a doc type:**
|
||||
- Ask if they have a template document to share
|
||||
- If they provide a link to a shared document, use the appropriate integration to fetch it
|
||||
- If they provide a file, read it
|
||||
|
||||
**If user mentions editing an existing shared document:**
|
||||
- Use the appropriate integration to read the current state
|
||||
- Check for images without alt-text
|
||||
- If images exist without alt-text, explain that when others use Claude to understand the doc, Claude won't be able to see them. Ask if they want alt-text generated. If so, request they paste each image into chat for descriptive alt-text generation.
|
||||
|
||||
### Info Dumping
|
||||
|
||||
Once initial questions are answered, encourage the user to dump all the context they have. Request information such as:
|
||||
- Background on the project/problem
|
||||
- Related team discussions or shared documents
|
||||
- Why alternative solutions aren't being used
|
||||
- Organizational context (team dynamics, past incidents, politics)
|
||||
- Timeline pressures or constraints
|
||||
- Technical architecture or dependencies
|
||||
- Stakeholder concerns
|
||||
|
||||
Advise them not to worry about organizing it - just get it all out. Offer multiple ways to provide context:
|
||||
- Info dump stream-of-consciousness
|
||||
- Point to team channels or threads to read
|
||||
- Link to shared documents
|
||||
|
||||
**If integrations are available** (e.g., Slack, Teams, Google Drive, SharePoint, or other MCP servers), mention that these can be used to pull in context directly.
|
||||
|
||||
**If no integrations are detected and in Claude.ai or Claude app:** Suggest they can enable connectors in their Claude settings to allow pulling context from messaging apps and document storage directly.
|
||||
|
||||
Inform them clarifying questions will be asked once they've done their initial dump.
|
||||
|
||||
**During context gathering:**
|
||||
|
||||
- If user mentions team channels or shared documents:
|
||||
- If integrations available: Inform them the content will be read now, then use the appropriate integration
|
||||
- If integrations not available: Explain lack of access. Suggest they enable connectors in Claude settings, or paste the relevant content directly.
|
||||
|
||||
- If user mentions entities/projects that are unknown:
|
||||
- Ask if connected tools should be searched to learn more
|
||||
- Wait for user confirmation before searching
|
||||
|
||||
- As user provides context, track what's being learned and what's still unclear
|
||||
|
||||
**Asking clarifying questions:**
|
||||
|
||||
When user signals they've done their initial dump (or after substantial context provided), ask clarifying questions to ensure understanding:
|
||||
|
||||
Generate 5-10 numbered questions based on gaps in the context.
|
||||
|
||||
Inform them they can use shorthand to answer (e.g., "1: yes, 2: see #channel, 3: no because backwards compat"), link to more docs, point to channels to read, or just keep info-dumping. Whatever's most efficient for them.
|
||||
|
||||
**Exit condition:**
|
||||
Sufficient context has been gathered when questions show understanding - when edge cases and trade-offs can be asked about without needing basics explained.
|
||||
|
||||
**Transition:**
|
||||
Ask if there's any more context they want to provide at this stage, or if it's time to move on to drafting the document.
|
||||
|
||||
If user wants to add more, let them. When ready, proceed to Stage 2.
|
||||
|
||||
## Stage 2: Refinement & Structure
|
||||
|
||||
**Goal:** Build the document section by section through brainstorming, curation, and iterative refinement.
|
||||
|
||||
**Instructions to user:**
|
||||
Explain that the document will be built section by section. For each section:
|
||||
1. Clarifying questions will be asked about what to include
|
||||
2. 5-20 options will be brainstormed
|
||||
3. User will indicate what to keep/remove/combine
|
||||
4. The section will be drafted
|
||||
5. It will be refined through surgical edits
|
||||
|
||||
Start with whichever section has the most unknowns (usually the core decision/proposal), then work through the rest.
|
||||
|
||||
**Section ordering:**
|
||||
|
||||
If the document structure is clear:
|
||||
Ask which section they'd like to start with.
|
||||
|
||||
Suggest starting with whichever section has the most unknowns. For decision docs, that's usually the core proposal. For specs, it's typically the technical approach. Summary sections are best left for last.
|
||||
|
||||
If user doesn't know what sections they need:
|
||||
Based on the type of document and template, suggest 3-5 sections appropriate for the doc type.
|
||||
|
||||
Ask if this structure works, or if they want to adjust it.
|
||||
|
||||
**Once structure is agreed:**
|
||||
|
||||
Create the initial document structure with placeholder text for all sections.
|
||||
|
||||
**If access to artifacts is available:**
|
||||
Use `create_file` to create an artifact. This gives both Claude and the user a scaffold to work from.
|
||||
|
||||
Inform them that the initial structure with placeholders for all sections will be created.
|
||||
|
||||
Create artifact with all section headers and brief placeholder text like "[To be written]" or "[Content here]".
|
||||
|
||||
Provide the scaffold link and indicate it's time to fill in each section.
|
||||
|
||||
**If no access to artifacts:**
|
||||
Create a markdown file in the working directory. Name it appropriately (e.g., `decision-doc.md`, `technical-spec.md`).
|
||||
|
||||
Inform them that the initial structure with placeholders for all sections will be created.
|
||||
|
||||
Create file with all section headers and placeholder text.
|
||||
|
||||
Confirm the filename has been created and indicate it's time to fill in each section.
|
||||
|
||||
**For each section:**
|
||||
|
||||
### Step 1: Clarifying Questions
|
||||
|
||||
Announce work will begin on the [SECTION NAME] section. Ask 5-10 clarifying questions about what should be included:
|
||||
|
||||
Generate 5-10 specific questions based on context and section purpose.
|
||||
|
||||
Inform them they can answer in shorthand or just indicate what's important to cover.
|
||||
|
||||
### Step 2: Brainstorming
|
||||
|
||||
For the [SECTION NAME] section, brainstorm [5-20] things that might be included, depending on the section's complexity. Look for:
|
||||
- Context shared that might have been forgotten
|
||||
- Angles or considerations not yet mentioned
|
||||
|
||||
Generate 5-20 numbered options based on section complexity. At the end, offer to brainstorm more if they want additional options.
|
||||
|
||||
### Step 3: Curation
|
||||
|
||||
Ask which points should be kept, removed, or combined. Request brief justifications to help learn priorities for the next sections.
|
||||
|
||||
Provide examples:
|
||||
- "Keep 1,4,7,9"
|
||||
- "Remove 3 (duplicates 1)"
|
||||
- "Remove 6 (audience already knows this)"
|
||||
- "Combine 11 and 12"
|
||||
|
||||
**If user gives freeform feedback** (e.g., "looks good" or "I like most of it but...") instead of numbered selections, extract their preferences and proceed. Parse what they want kept/removed/changed and apply it.
|
||||
|
||||
### Step 4: Gap Check
|
||||
|
||||
Based on what they've selected, ask if there's anything important missing for the [SECTION NAME] section.
|
||||
|
||||
### Step 5: Drafting
|
||||
|
||||
Use `str_replace` to replace the placeholder text for this section with the actual drafted content.
|
||||
|
||||
Announce the [SECTION NAME] section will be drafted now based on what they've selected.
|
||||
|
||||
**If using artifacts:**
|
||||
After drafting, provide a link to the artifact.
|
||||
|
||||
Ask them to read through it and indicate what to change. Note that being specific helps learning for the next sections.
|
||||
|
||||
**If using a file (no artifacts):**
|
||||
After drafting, confirm completion.
|
||||
|
||||
Inform them the [SECTION NAME] section has been drafted in [filename]. Ask them to read through it and indicate what to change. Note that being specific helps learning for the next sections.
|
||||
|
||||
**Key instruction for user (include when drafting the first section):**
|
||||
Provide a note: Instead of editing the doc directly, ask them to indicate what to change. This helps learning of their style for future sections. For example: "Remove the X bullet - already covered by Y" or "Make the third paragraph more concise".
|
||||
|
||||
### Step 6: Iterative Refinement
|
||||
|
||||
As user provides feedback:
|
||||
- Use `str_replace` to make edits (never reprint the whole doc)
|
||||
- **If using artifacts:** Provide link to artifact after each edit
|
||||
- **If using files:** Just confirm edits are complete
|
||||
- If user edits doc directly and asks to read it: mentally note the changes they made and keep them in mind for future sections (this shows their preferences)
|
||||
|
||||
**Continue iterating** until user is satisfied with the section.
|
||||
|
||||
### Quality Checking
|
||||
|
||||
After 3 consecutive iterations with no substantial changes, ask if anything can be removed without losing important information.
|
||||
|
||||
When section is done, confirm [SECTION NAME] is complete. Ask if ready to move to the next section.
|
||||
|
||||
**Repeat for all sections.**
|
||||
|
||||
### Near Completion
|
||||
|
||||
As approaching completion (80%+ of sections done), announce intention to re-read the entire document and check for:
|
||||
- Flow and consistency across sections
|
||||
- Redundancy or contradictions
|
||||
- Anything that feels like "slop" or generic filler
|
||||
- Whether every sentence carries weight
|
||||
|
||||
Read entire document and provide feedback.
|
||||
|
||||
**When all sections are drafted and refined:**
|
||||
Announce all sections are drafted. Indicate intention to review the complete document one more time.
|
||||
|
||||
Review for overall coherence, flow, completeness.
|
||||
|
||||
Provide any final suggestions.
|
||||
|
||||
Ask if ready to move to Reader Testing, or if they want to refine anything else.
|
||||
|
||||
## Stage 3: Reader Testing
|
||||
|
||||
**Goal:** Test the document with a fresh Claude (no context bleed) to verify it works for readers.
|
||||
|
||||
**Instructions to user:**
|
||||
Explain that testing will now occur to see if the document actually works for readers. This catches blind spots - things that make sense to the authors but might confuse others.
|
||||
|
||||
### Testing Approach
|
||||
|
||||
**If access to sub-agents is available (e.g., in Claude Code):**
|
||||
|
||||
Perform the testing directly without user involvement.
|
||||
|
||||
### Step 1: Predict Reader Questions
|
||||
|
||||
Announce intention to predict what questions readers might ask when trying to discover this document.
|
||||
|
||||
Generate 5-10 questions that readers would realistically ask.
|
||||
|
||||
### Step 2: Test with Sub-Agent
|
||||
|
||||
Announce that these questions will be tested with a fresh Claude instance (no context from this conversation).
|
||||
|
||||
For each question, invoke a sub-agent with just the document content and the question.
|
||||
|
||||
Summarize what Reader Claude got right/wrong for each question.
|
||||
|
||||
### Step 3: Run Additional Checks
|
||||
|
||||
Announce additional checks will be performed.
|
||||
|
||||
Invoke sub-agent to check for ambiguity, false assumptions, contradictions.
|
||||
|
||||
Summarize any issues found.
|
||||
|
||||
### Step 4: Report and Fix
|
||||
|
||||
If issues found:
|
||||
Report that Reader Claude struggled with specific issues.
|
||||
|
||||
List the specific issues.
|
||||
|
||||
Indicate intention to fix these gaps.
|
||||
|
||||
Loop back to refinement for problematic sections.
|
||||
|
||||
---
|
||||
|
||||
**If no access to sub-agents (e.g., claude.ai web interface):**
|
||||
|
||||
The user will need to do the testing manually.
|
||||
|
||||
### Step 1: Predict Reader Questions
|
||||
|
||||
Ask what questions people might ask when trying to discover this document. What would they type into Claude.ai?
|
||||
|
||||
Generate 5-10 questions that readers would realistically ask.
|
||||
|
||||
### Step 2: Setup Testing
|
||||
|
||||
Provide testing instructions:
|
||||
1. Open a fresh Claude conversation: https://claude.ai
|
||||
2. Paste or share the document content (if using a shared doc platform with connectors enabled, provide the link)
|
||||
3. Ask Reader Claude the generated questions
|
||||
|
||||
For each question, instruct Reader Claude to provide:
|
||||
- The answer
|
||||
- Whether anything was ambiguous or unclear
|
||||
- What knowledge/context the doc assumes is already known
|
||||
|
||||
Check if Reader Claude gives correct answers or misinterprets anything.
|
||||
|
||||
### Step 3: Additional Checks
|
||||
|
||||
Also ask Reader Claude:
|
||||
- "What in this doc might be ambiguous or unclear to readers?"
|
||||
- "What knowledge or context does this doc assume readers already have?"
|
||||
- "Are there any internal contradictions or inconsistencies?"
|
||||
|
||||
### Step 4: Iterate Based on Results
|
||||
|
||||
Ask what Reader Claude got wrong or struggled with. Indicate intention to fix those gaps.
|
||||
|
||||
Loop back to refinement for any problematic sections.
|
||||
|
||||
---
|
||||
|
||||
### Exit Condition (Both Approaches)
|
||||
|
||||
When Reader Claude consistently answers questions correctly and doesn't surface new gaps or ambiguities, the doc is ready.
|
||||
|
||||
## Final Review
|
||||
|
||||
When Reader Testing passes:
|
||||
Announce the doc has passed Reader Claude testing. Before completion:
|
||||
|
||||
1. Recommend they do a final read-through themselves - they own this document and are responsible for its quality
|
||||
2. Suggest double-checking any facts, links, or technical details
|
||||
3. Ask them to verify it achieves the impact they wanted
|
||||
|
||||
Ask if they want one more review, or if the work is done.
|
||||
|
||||
**If user wants final review, provide it. Otherwise:**
|
||||
Announce document completion. Provide a few final tips:
|
||||
- Consider linking this conversation in an appendix so readers can see how the doc was developed
|
||||
- Use appendices to provide depth without bloating the main doc
|
||||
- Update the doc as feedback is received from real readers
|
||||
|
||||
## Tips for Effective Guidance
|
||||
|
||||
**Tone:**
|
||||
- Be direct and procedural
|
||||
- Explain rationale briefly when it affects user behavior
|
||||
- Don't try to "sell" the approach - just execute it
|
||||
|
||||
**Handling Deviations:**
|
||||
- If user wants to skip a stage: Ask if they want to skip this and write freeform
|
||||
- If user seems frustrated: Acknowledge this is taking longer than expected. Suggest ways to move faster
|
||||
- Always give user agency to adjust the process
|
||||
|
||||
**Context Management:**
|
||||
- Throughout, if context is missing on something mentioned, proactively ask
|
||||
- Don't let gaps accumulate - address them as they come up
|
||||
|
||||
**Artifact Management:**
|
||||
- Use `create_file` for drafting full sections
|
||||
- Use `str_replace` for all edits
|
||||
- Provide artifact link after every change
|
||||
- Never use artifacts for brainstorming lists - that's just conversation
|
||||
|
||||
**Quality over Speed:**
|
||||
- Don't rush through stages
|
||||
- Each iteration should make meaningful improvements
|
||||
- The goal is a document that actually works for readers
|
||||
@@ -0,0 +1,80 @@
|
||||
---
|
||||
name: 文档分析器
|
||||
description: 深度分析文档结构和内容。当用户需要分析文档结构、提取关键信息、识别文档类型、进行内容质量评估、或理解文档组织方式时使用此技能。
|
||||
---
|
||||
|
||||
# Document Analyzer
|
||||
|
||||
对知识库中的文档进行深度结构分析和内容理解。
|
||||
|
||||
## 核心能力
|
||||
|
||||
1. **结构分析**: 识别文档的章节层级、组织架构
|
||||
2. **关键信息提取**: 提取核心论点、关键数据、重要结论
|
||||
3. **文档类型识别**: 判断文档类型(报告、手册、论文、合同等)
|
||||
4. **内容质量评估**: 评估文档的完整性、一致性、可读性
|
||||
|
||||
## 分析流程
|
||||
|
||||
### 1. 文档概览
|
||||
|
||||
首先获取文档的整体信息:
|
||||
- 文档名称和类型
|
||||
- 总页数/分块数
|
||||
- 创建/更新时间
|
||||
- 主要章节/标题
|
||||
|
||||
### 2. 结构分析
|
||||
|
||||
识别并描述:
|
||||
- 标题层级结构
|
||||
- 章节组织方式
|
||||
- 逻辑流程(时间顺序、因果关系、并列结构)
|
||||
|
||||
### 3. 内容提取
|
||||
|
||||
重点关注:
|
||||
- **核心主题**: 文档的中心议题
|
||||
- **关键论点**: 主要观点和论述
|
||||
- **支撑数据**: 重要的数据、统计、事实
|
||||
- **结论建议**: 文档的结论或建议
|
||||
|
||||
### 4. 质量评估
|
||||
|
||||
评估维度:
|
||||
- 完整性:是否涵盖必要内容
|
||||
- 一致性:前后是否逻辑一致
|
||||
- 清晰度:表达是否清晰易懂
|
||||
|
||||
## 输出格式
|
||||
|
||||
```markdown
|
||||
## 文档分析报告
|
||||
|
||||
### 基本信息
|
||||
- 文档名称:XXX
|
||||
- 文档类型:XXX
|
||||
- 结构层级:X级
|
||||
|
||||
### 文档结构
|
||||
1. 第一章:XXX
|
||||
1.1 ...
|
||||
1.2 ...
|
||||
2. 第二章:XXX
|
||||
|
||||
### 核心内容
|
||||
- 主题:XXX
|
||||
- 关键论点:
|
||||
1. ...
|
||||
2. ...
|
||||
- 重要数据:XXX
|
||||
|
||||
### 分析结论
|
||||
XXX
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 保持客观中立,忠于原文
|
||||
- 区分事实陈述和观点表达
|
||||
- 标注信息来源位置
|
||||
@@ -0,0 +1,92 @@
|
||||
---
|
||||
name: 摘要生成器
|
||||
description: 生成多层级文档摘要。当用户需要生成内容摘要、提取要点、创建不同长度的文档概述、或快速了解文档主要内容时使用此技能。
|
||||
---
|
||||
|
||||
# Summary Generator
|
||||
|
||||
为知识库文档生成多层次、高质量的摘要。
|
||||
|
||||
## 核心能力
|
||||
|
||||
1. **多层级摘要**: 支持一句话摘要、段落摘要、详细摘要
|
||||
2. **要点提取**: 提取文档的核心要点列表
|
||||
3. **结构化总结**: 按章节/主题组织的结构化摘要
|
||||
|
||||
## 摘要层级
|
||||
|
||||
### Level 1: 一句话摘要(约20字)
|
||||
|
||||
用一句话概括文档的核心内容和价值:
|
||||
```
|
||||
本文档详细说明了XX产品的使用方法和常见问题解决方案。
|
||||
```
|
||||
|
||||
### Level 2: 要点摘要(3-5个要点)
|
||||
|
||||
提取文档最重要的3-5个要点:
|
||||
```
|
||||
**核心要点**
|
||||
1. 要点一:XXX
|
||||
2. 要点二:XXX
|
||||
3. 要点三:XXX
|
||||
```
|
||||
|
||||
### Level 3: 段落摘要(100-200字)
|
||||
|
||||
用1-2段文字全面概括文档内容:
|
||||
```
|
||||
本文档主要介绍了...首先...其次...最后...
|
||||
```
|
||||
|
||||
### Level 4: 详细摘要(章节式)
|
||||
|
||||
按文档结构生成分章节摘要:
|
||||
```
|
||||
**第一章 概述**
|
||||
XXX...
|
||||
|
||||
**第二章 详细说明**
|
||||
XXX...
|
||||
|
||||
**第三章 总结与建议**
|
||||
XXX...
|
||||
```
|
||||
|
||||
## 摘要原则
|
||||
|
||||
1. **准确性**: 摘要必须准确反映原文内容
|
||||
2. **完整性**: 不遗漏重要信息
|
||||
3. **简洁性**: 用最少的文字表达核心内容
|
||||
4. **客观性**: 不添加个人观点
|
||||
|
||||
## 默认行为
|
||||
|
||||
- 未指定层级时,默认生成 Level 2(要点摘要)
|
||||
- 根据文档长度自动调整摘要详细程度
|
||||
- 保留关键数据和结论
|
||||
|
||||
## 使用示例
|
||||
|
||||
用户请求:"帮我总结这篇文档"
|
||||
|
||||
响应格式:
|
||||
```
|
||||
**文档摘要**
|
||||
|
||||
本文档关于 [主题]。
|
||||
|
||||
**核心要点**
|
||||
1. [要点1]
|
||||
2. [要点2]
|
||||
3. [要点3]
|
||||
|
||||
**详细内容**
|
||||
[简要展开说明...]
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 数字、日期等关键信息需保留原值
|
||||
- 专业术语保持原有表述
|
||||
- 如有多个文档,分别生成摘要后再做整合
|
||||
Reference in New Issue
Block a user