拼写检查器
自动化和提高文档校对效率是开发者和写作者常见的需求。该脚本通过检查和纠正Markdown文件中的拼写和语法错误来满足这一需求。
代码解释
从脚本顶部开始,我们可以看到这是一个GenAI脚本,这一点从.mts扩展名和script函数调用中可以明显看出。
script({ title: "Spell checker", system: [ "system.output_plaintext", "system.assistant", "system.files", "system.changelog", "system.safety_jailbreak", "system.safety_harmful_content", ], temperature: 0.2, cache: "sc",})此代码块将脚本的标题设置为“拼写检查器”,并指定它使用多个系统提示,例如文件操作和差异生成。temperature参数设置为0.1,表示该脚本将以较低的创造性生成输出,从而更倾向于精确性。
定义要处理的文件类型
接下来是一个def调用:
def("FILES", files)这一行定义了FILES为我们收集的文件数组。
以$为前缀的反引号符号用于编写提示模板:
$`Fix the spelling and grammar of the content of <FILES>. Return the full file with correctionsIf you find a spelling or grammar mistake, fix it.If you do not find any mistakes, respond <NO> and nothing else.
- only fix major errors- use a technical documentation tone- minimize changes; do NOT change the meaning of the content- if the grammar is good enough, do NOT change it- do NOT modify the frontmatter. THIS IS IMPORTANT.- do NOT modify code regions. THIS IS IMPORTANT.- do NOT fix \`code\` and \`\`\`code\`\`\` sections- in .mdx files, do NOT fix inline typescript code`如何使用GenAIScript CLI运行脚本
使用GenAIScript CLI运行这个拼写检查脚本非常简单。首先,请按照GenAIScript文档中的说明确保已安装CLI。
安装好CLI后,在终端或命令行界面中导航到脚本的本地副本。运行以下命令来执行拼写检查:
genaiscript convert sc "**/*.md" --rewrite请记住,在使用convert命令时,您不需要指定.genai.mts扩展名。
就这样——一个用于Markdown文件的GenAI拼写检查脚本的详细演练。祝您编码愉快,完善您的文档!
完整源代码 (GitHub)
script({ title: "Spell checker", system: [ "system.output_plaintext", "system.assistant", "system.files", "system.changelog", "system.safety_jailbreak", "system.safety_harmful_content", ], temperature: 0.2, cache: "sc",})const files = def("FILES", env.files)
$`Fix the spelling and grammar of the content of ${files}. Return the full file with correctionsIf you find a spelling or grammar mistake, fix it.If you do not find any mistakes, respond <NO> and nothing else.
- only fix major errors- use a technical documentation tone- minimize changes; do NOT change the meaning of the content- if the grammar is good enough, do NOT change it- do NOT modify the frontmatter. THIS IS IMPORTANT.- do NOT modify code regions. THIS IS IMPORTANT.- do NOT fix \`code\` and \`\`\`code\`\`\` sections- in .mdx files, do NOT fix inline typescript code`内容安全
为确保生成内容的安全性,采取了以下措施。
- This script includes system prompts to prevent prompt injection and harmful content generation.
- 生成的描述会保存到指定路径的文件中,以便在提交更改前进行人工审核。
进一步增强安全性的额外措施包括运行带有安全过滤器的模型或使用内容安全服务验证消息。
有关内容安全的更多信息,请参阅透明度说明。