使用 OpenAI、Google 和 Claude AI 模型,结合 Aspose.Words for Node.js via .NET,检测并突出显示文档中的语法错误。CheckGrammar 方法可分析 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 和 EPUB 等文件,并标记语法问题——帮助您在无需人工校对的情况下交付精炼、专业的内容。
身份验证需要您所选 AI 提供商的 API 密钥。完整的支持模型列表请参阅 API 参考。
立即在 JavaScript 开始语法检查——尝试上方的实时演示。
npm install @aspose/words
复制
const aw = require('@aspose/words');
const doc = new aw.Document("Document.docx");
const apiKey = process.env.API_KEY;
// 使用 OpenAI 生成式语言模型。
const model = aw.AI.AiModel.createGpt4OMini();
model.setApiKey(apiKey);
const grammarOptions = new aw.AI.CheckGrammarOptions();
grammarOptions.improveStylistics = true;
const proofedDoc = model.checkGrammar(doc, grammarOptions);
proofedDoc.save("Output.docx");
const aw = require('@aspose/words');
const doc = new aw.Document("Document.docx");
// Pass an empty string if the self-hosted model does not require an API key.
const model = new CustomAiModel("my-model-24b", "https://your-server.com/v1");
model.setApiKey("");
const grammarOptions = new aw.AI.CheckGrammarOptions();
grammarOptions.improveStylistics = true;
const proofedDoc = model.checkGrammar(doc, grammarOptions);
proofedDoc.save("Output.docx");
class CustomAiModel extends aw.AI.OpenAiModel {
constructor(name, url) {
super(name);
this._url = url;
}
get url() {
return this._url;
}
}
We host our Node.js via .Net packages in NPM repositories. Please follow the step-by-step instructions on how to install "Aspose.Words for Node.js via .NET" to your developer environment.
This package is compatible with Node.js 14.17.0 or higher.