
graphify 的视频转写机制Whisper 集成、God-Node 领域提示与 Step 2.5 流水线【免费下载链接】graphifyTurn any codebase, with its docs, SQL schemas, configs, and PDFs, into a queryable knowledge graph. A /graphify skill for Claude Code, Cursor, Codex, and Gemini CLI: local deterministic AST parsing, every edge explained, no vector store.项目地址: https://gitcode.com/GitHub_Trending/graph/graphify本文以 Claude 技能参考文档 transcribe.md 为核心完整拆解 graphify 把视频/音频语料纳入知识图谱的 Step 2.5 环节从detect检测到video文件到由 god node 标签生成 Whisper 领域提示domain hint再到执行本地 faster-whisper 转写、产出.txt文稿并回流到文档抽取流程的全过程。读完你可以掌握两个环境变量的正确用法export而非赋值、避免 JSON 输出被 stdout 进度污染的经典陷阱#1392并能对照 graphify/transcribe.py 源码理解缓存、URL 下载与容错机制的实现细节。Step 2.5 在流水线中的定位仅在检测到视频时触发graphify 的构建流水线中转写是一个按需加载的分支步骤。技能主文档 graphify/skill.md 明确规定Skip this step entirely ifdetectreturned zerovideofiles. When the corpus has video or audio, seereferences/transcribe.mdto transcribe them to text first, then treat the transcripts as doc files in Step 3.也就是说语料库里没有任何视频文件时Agent 根本不会读取 transcribe 参考文档——这是原文档开宗明义的第一句约束。它的触发链是Step 2 的detect按扩展名把语料分类视频/音频文件归入video桶判定表见 graphify/detect.py 中的VIDEO_EXTENSIONS.mp4 .mov .webm .mkv .avi .m4v .mp3 .wav .m4a .ogg与 graphify/transcribe.py#L11 中的集合保持一致结果写入graphify-out/.graphify_detect.json若video列表非空进入 Step 2.5先把视频转成文本再在 Step 3 中把文稿当作普通文档参与语义抽取同一份参考文档也被复制到其他平台技能目录下如 graphify/skills/codex/references/transcribe.md各平台技能的行为是等价的。领域提示domain hint让 god nodes 免费指导 Whisper 的 initial_prompt参考文档给出的核心策略是不额外调用任何 API。你自己编码 Agent本来就是一个语言模型直接读取 god node 标签亲手写一句领域提示再把它作为 Whisper 的initial_prompt传入即可。数据来源。god node 标签来自graphify-out/.graphify_detect.json首次运行或上一次运行留下的分析文件。god nodes 本身由 graphify/analyze.py#L109-L130 的god_nodes(G, top_n10)计算按度degree降序取前 10 个真实实体并排除文件级 hub 节点、概念节点与 JSON 键噪声节点——这些是语料库中连接最多的核心抽象天然适合作为话题锚点。提示的写法。原文档给出两个示范标签为transformer, attention, encoder, decoder→Machine learning research on transformer architectures and attention mechanisms. Use proper punctuation and paragraph breaks.标签为kubernetes, deployment, pod, helm→DevOps discussion about Kubernetes deployments and Helm charts. Use proper punctuation and paragraph breaks.兜底规则。如果语料库只有视频文件、没有任何其他文档或代码可供推断领域直接使用通用兜底提示Use proper punctuation and paragraph breaks.这个字符串在源码中就是_FALLBACK_PROMPT常量graphify/transcribe.py#L16保证文档与实现一致。环境变量传递与源码印证。提示必须命名为GRAPHIFY_WHISPER_PROMPT并且必须export不是 shell 里的普通变量赋值因为转写是在一个子 Python 进程中运行的只有导出的环境变量才对子进程可见。这一点在源码里有双重印证graphify/transcribe.py#L95-L115 的build_whisper_prompt()会优先检查os.environ.get(GRAPHIFY_WHISPER_PROMPT)一旦存在就短路掉基于 god node 的自动拼装测试用例test_build_whisper_prompt_env_override见 tests/test_transcribe.py#L40-L44专门验证了这个短路行为未设置时build_whisper_prompt()会取前 10 个 god node 标签中的前 5 个拼成Technical discussion about {topics}. Use proper punctuation and paragraph breaks.作为次级默认。执行转写参考文档给出的完整命令原文档 Step 2 的完整可复制命令如下建议原样保留使用export GRAPHIFY_WHISPER_MODELbase # or whatever --whisper-model the user passed (must be exported) export GRAPHIFY_WHISPER_PROMPTthe one-sentence domain hint you composed in Step 1 $(cat graphify-out/.graphify_python) -c import json, os, sys from pathlib import Path from graphify.transcribe import transcribe_all detect json.loads(Path(graphify-out/.graphify_detect.json).read_text(encoding\utf-8\)) video_files detect.get(files, {}).get(video, []) prompt os.environ.get(GRAPHIFY_WHISPER_PROMPT, Use proper punctuation and paragraph breaks.) transcript_paths transcribe_all(video_files, initial_promptprompt) # Write the JSON from Python (NOT a shell redirect): transcribe_all/Whisper # print progress to stdout, which would otherwise corrupt the JSON file (#1392). Path(graphify-out/.graphify_transcripts.json).write_text(json.dumps(transcript_paths, ensure_asciiFalse), encoding\utf-8\) print(fTranscribed {len(transcript_paths)} file(s), filesys.stderr) 命令中每个细节都有出处逐条说明要素作用源码/文档依据$(cat graphify-out/.graphify_python)使用 Step 1 解析出的、真正装有 graphify 依赖的解释器路径而不是假设的python3graphify/skill-agents.md#L98 写入该文件detect.get(files, {}).get(video, [])从 detect 输出中取出视频文件列表graphify-out/.graphify_detect.json结构GRAPHIFY_WHISPER_PROMPT子进程读取的领域提示缺省时回退到兜底提示graphify/transcribe.py#L106GRAPHIFY_WHISPER_MODEL选择 Whisper 模型默认basegraphify/transcribe.py#L14-L20_model_name()读环境变量缺省_DEFAULT_MODEL base用 Python 写 JSON 而非 shell重定向transcribe_all/Whisper 会向 stdout 打印进度重定向会把进度混进 JSON 文件导致其损坏文档中标注的 #1392 回归print(..., filesys.stderr)计数信息走 stderr同样保护 JSON 通道同上模型选择。默认base如果用户在命令中传了--whisper-model name例如 graphify/skill.md#L21 示范的/graphify path --whisper-model medium则必须export GRAPHIFY_WHISPER_MODELname后再执行上面的命令——再次强调是export而非赋值。转写完成后文稿如何回流到 Step 3参考文档对转写之后的动作有明确约定从graphify-out/.graphify_transcripts.json读回所有文稿路径在派发 Step 3B 的语义子 Agent 之前把这些路径并入文档docs清单——从此它们与.md文档享受同等待遇打印Transcribed N video file(s) - treating as docs告知用户数量若某个文件转写失败打印警告并继续处理其余文件不让单点失败中断整条流水线。最后一条容错语义由 graphify/transcribe.py#L166-L186 的transcribe_all()实现它逐个调用transcribe()except Exception时打印warning: could not transcribe ...并跳过最终只返回成功项的路径列表空输入直接返回[]。对应的测试test_transcribe_all_skips_failedtests/test_transcribe.py#L136-L147验证了失败即跳过、不抛异常的行为。深入 transcribe.py缓存、URL 下载与本地推理参数参考文档只描述了调用面而 graphify/transcribe.py 的实现面还有几个值得了解的机制输出与缓存。文稿默认写入graphify-out/transcripts/目录_TRANSCRIPTS_DIR经由 graphify/paths.py#L295-L301 的out_path(transcripts)解析尊重GRAPHIFY_OUT覆盖。文件名取音频文件的 stem 加.txt若该文件已存在且未传forceTruetranscribe()直接返回缓存路径完全不加载 Whisper 模型。测试test_transcribe_uses_cache与test_transcribe_force_reruns分别覆盖了命中缓存与force强制重转两条路径。本地确定性推理。转写使用faster-whisper固定参数WhisperModel(model_name, devicecpu, compute_typeint8)转写时beam_size5并传入initial_promptgraphify/transcribe.py#L150-L155。从源码结构看这是一个纯 CPU int8 量化配置——与 graphify 本地、无向量库、确定性的整体立场一致不需要 GPU 或云端 ASR 服务。URL 支持。若输入不是文件路径而是http://、https://、www.开头的 URLtranscribe()会先经download_audio()用 yt-dlp 只拉音频流以 URL 的 SHA-1 前 12 位生成稳定文件名yt_hash.ext命中已有缓存则直接复用下载前还会调用graphify.security的validate_url()拦截私有 IP 与非法 schemegraphify/transcribe.py#L50-L92。依赖安装。视频能力是可选依赖在 pyproject.toml 中声明为videoextrafaster-whisper要求 Python ≥ 3.11与yt-dlp2026.6.9。若未安装_get_whisper()/_get_yt_dlp()会抛出带安装提示的ImportErrorpip install graphifyy[video]test_transcribe_missing_faster_whisper验证了该异常会向上传播而不是静默吞掉。小结这条参考文档的工程价值transcribe.md 篇幅不长但每一行都是踩过坑的约定条件加载——没有视频的语料永远不读它避免无关上下文稀释 Agent 注意力零额外 API 的领域提示——god node 标签 → 一句话 domain hint → Whisperinitial_prompt测试test_build_whisper_prompt_returns_topic_string确认了不发 LLM 请求的拼装逻辑两个必须export的环境变量——GRAPHIFY_WHISPER_PROMPT可选缺省回退兜底提示与GRAPHIFY_WHISPER_MODEL默认baseJSON 输出走 Python、进度走 stderr——#1392 的教训被固化进了命令注释失败不阻塞——transcribe_all的逐文件容错保证单个坏文件不拖垮整个图构建。想继续深入可以从 tests/test_transcribe.py 的全部用例出发逐条对照源码或查看 graphify/skill.md 中 Step 2 → Step 2.5 → Step 3 的完整调度关系。【免费下载链接】graphifyTurn any codebase, with its docs, SQL schemas, configs, and PDFs, into a queryable knowledge graph. A /graphify skill for Claude Code, Cursor, Codex, and Gemini CLI: local deterministic AST parsing, every edge explained, no vector store.项目地址: https://gitcode.com/GitHub_Trending/graph/graphify创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考