feat(kb): 截图内容视觉提取并入库(36张图→21条知识),import_kb 支持 --include-vision
This commit is contained in:
@@ -21,6 +21,7 @@ nonebot.init()
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
PAGES_DIR = Path(__file__).parent / "pages"
|
||||
VISION_DIR = Path(__file__).parent / "vision_pages"
|
||||
|
||||
# 每条知识的目标长度(字符),按标题切块后超过再按段落切
|
||||
CHUNK_SIZE = 600
|
||||
@@ -86,10 +87,12 @@ def parse_page(path: Path) -> list[dict]:
|
||||
return chunks
|
||||
|
||||
|
||||
async def main(agent_id: str, dry_run: bool) -> None:
|
||||
async def main(agent_id: str, dry_run: bool, include_vision: bool = False) -> None:
|
||||
entries_spec: list[dict] = []
|
||||
for f in sorted(PAGES_DIR.glob("*.txt")):
|
||||
entries_spec.extend(parse_page(f))
|
||||
dirs = [PAGES_DIR] + ([VISION_DIR] if include_vision else [])
|
||||
for d in dirs:
|
||||
for f in sorted(d.glob("*.txt")):
|
||||
entries_spec.extend(parse_page(f))
|
||||
print(f"共解析出 {len(entries_spec)} 条知识条目")
|
||||
if dry_run:
|
||||
for e in entries_spec[:10]:
|
||||
@@ -134,5 +137,6 @@ if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--agent-id", required=True, help="机器人 QQ 号(wtfllm 的 agent_id)")
|
||||
parser.add_argument("--dry-run", action="store_true", help="只解析不写入")
|
||||
parser.add_argument("--include-vision", action="store_true", help="包含截图提取的知识")
|
||||
args = parser.parse_args()
|
||||
asyncio.run(main(args.agent_id, args.dry_run))
|
||||
asyncio.run(main(args.agent_id, args.dry_run, args.include_vision))
|
||||
|
||||
Reference in New Issue
Block a user