-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetnote_explore.sh
More file actions
executable file
·134 lines (110 loc) · 3.69 KB
/
getnote_explore.sh
File metadata and controls
executable file
·134 lines (110 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
###############################################################################
# Get 笔记知识库探索工具
# 用法: ./getnote_explore.sh [关键词] [数量]
# 示例:
# ./getnote_explore.sh 提示词 5
# ./getnote_explore.sh AI工具
# ./getnote_explore.sh (查看知识库概览)
###############################################################################
# 切换到脚本所在目录
cd "$(dirname "$0")"
# 加载环境变量
if [ -f "config/getnote.env" ]; then
export $(grep -v '^#' config/getnote.env | xargs)
else
echo "❌ 错误: 找不到 config/getnote.env 文件"
exit 1
fi
# 检查环境变量
if [ -z "$GETNOTE_API_KEY" ]; then
echo "❌ 错误: GETNOTE_API_KEY 未设置"
exit 1
fi
# 参数处理
KEYWORD="${1:-概览}"
TOP_K="${2:-5}"
echo "======================================================================="
echo "📚 Get 笔记知识库探索"
echo "======================================================================="
echo ""
if [ "$KEYWORD" == "概览" ]; then
# 显示知识库所有内容
python3 << 'EOF'
from mcp_tools.getnote import GetNoteAPI
client = GetNoteAPI()
print('📚 知识库完整内容列表\n')
# 使用广泛的关键词获取所有内容
keywords = ['文章', '教程', '指南', 'AI', '开发', '学习']
all_items = {}
for kw in keywords:
try:
materials = client.recall(kw, top_k=30)
for m in materials:
item_id = m.get('id')
if item_id and item_id not in all_items:
all_items[item_id] = m
except:
continue
# 分类
notes = [m for m in all_items.values() if m.get('type') == 'NOTE']
files_by_title = {}
for m in all_items.values():
if m.get('type') == 'FILE':
title = m.get('title', '无标题')
if title not in files_by_title:
files_by_title[title] = 0
files_by_title[title] += 1
# 显示笔记
print(f'📝 笔记(NOTE): {len(notes)} 条\n')
for i, note in enumerate(sorted(notes, key=lambda x: x.get('title', '')), 1):
title = note.get('title', '无标题')
extra = note.get('extra', {})
url = extra.get('url', '') if isinstance(extra, dict) else ''
print(f'{i:2d}. {title}')
if url:
print(f' 🔗 {url}')
# 显示文档
print(f'\n📄 文档(FILE): {len(files_by_title)} 份\n')
for i, (title, count) in enumerate(files_by_title.items(), 1):
print(f'{i:2d}. {title}')
if count > 1:
print(f' (分成 {count} 个片段)')
print()
print('='*70)
print(f'📊 总计: {len(notes)} 篇笔记 + {len(files_by_title)} 份文档')
print(f'🔢 存储片段数: {len(all_items)} 条')
print('='*70)
print('\n💡 使用 ./getnote_explore.sh <关键词> 查看具体内容')
EOF
else
# 查询特定关键词
python3 << EOF
from mcp_tools.getnote import GetNoteAPI
client = GetNoteAPI()
print(f'🔍 搜索关键词: "$KEYWORD"')
print(f'📊 返回数量: {$TOP_K}')
print('='*70)
print()
materials = client.recall("$KEYWORD", top_k=$TOP_K)
if materials:
print(f'✅ 找到 {len(materials)} 条相关素材:\n')
for i, m in enumerate(materials, 1):
print(f'{i}. {m.get("title", "无标题")}')
print(f' 类型: {m.get("type", "未知")}')
print(f' 相关度: {m.get("score", 0):.4f}')
# 显示原文链接
extra = m.get('extra', {})
if isinstance(extra, dict) and 'url' in extra:
print(f' 🔗 原文: {extra["url"]}')
# 显示内容预览
content = m.get('content', '')
if content:
preview = content[:200].replace('\n', ' ')
print(f' 摘要: {preview}...')
print()
else:
print('❌ 未找到相关素材')
print('='*70)
EOF
fi