过时描述的检测
开发者文档通常在每个文件中都包含描述。这些描述可能会过时,导致混淆和错误信息。为了防止这种情况,您可以使用GenAIScript自动检测文档中的过时描述。
Markdown与前置元数据
许多文档系统使用markdown格式编写文档,并使用'frontmatter'头部来存储元数据。以下是一个带有frontmatter的markdown文件示例:
---title: "My Document"description: "This is a sample document."---
# My Document
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
目标是创建一个脚本,用于检测frontmatter中的description
字段是否已过时。
脚本
GenAIScript 设计用于处理文件,并提供了一个特殊变量 env.files
,其中包含待分析的文件列表。您可以使用此变量通过 def 函数将文件包含在上下文中。我们将每个文件限制为2000个token,以避免大文件内容爆炸式增长。
// Define the file to be analyzeddef("DOCS", env.files, { endsWith: ".md", maxTokens: 2000 })
下一步是给脚本分配一个任务。在这个例子中,任务是检查frontmatter中的内容和description
字段是否匹配。
// Analyze the content to detect outdated descriptions$`Check if the 'description' field in the front matter in DOCS is outdated.`
最后,我们利用内置的诊断生成功能为每个过时的描述创建一个错误。
// enable diagnostics generation$`Generate an error for each outdated description.`
在Visual Studio Code中运行
将此脚本保存到工作区后,您就能通过右键菜单选择运行GenAIScript…来对文件或文件夹执行该脚本。
自动化
您可以使用cli自动在文档文件上运行此工具,以识别过时的描述。
genaiscript run detect-outdated-descriptions **/*.md
该脚本可以集成到您的CI/CD流水线中,实现检测流程的自动化。