使用 OpenAI、Google 和 Claude AI 模型,结合 Aspose.Words for C++,检测并突出显示文档中的语法错误。CheckGrammar 方法可分析 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 和 EPUB 等文件,并标记语法问题——帮助您在无需人工校对的情况下交付精炼、专业的内容。
身份验证需要您所选 AI 提供商的 API 密钥。完整的支持模型列表请参阅 API 参考。
立即在 C++ 开始语法检查——尝试上方的实时演示。
dotnet add package Aspose.Words.Cpp
复制
auto doc = System::MakeObject<Aspose::Words::Document>(u"Document.docx");
auto apiKey = System::Environment::GetEnvironmentVariable(u"API_KEY");
// 使用 OpenAI 生成式语言模型。
SharedPtr<AiModel> model = System::ExplicitCast<OpenAiModel>(SharedPtr<AiModel>()->Create(AiModelType::Gpt4OMini)->WithApiKey(apiKey));
auto grammarOptions = MakeObject<CheckGrammarOptions>();
grammarOptions->set_ImproveStylistics(true);
auto proofedDoc = model->CheckGrammar(doc, grammarOptions);
proofedDoc->Save(u"Output.docx");
auto doc = System::MakeObject<Aspose::Words::Document>(u"Document.docx");
// Pass an empty string if the self-hosted model does not require an API key.
auto model = System::MakeObject<CustomAiModel>(u"my-model-24b", u"https://your-server.com/v1");
model->WithApiKey(u"");
auto grammarOptions = System::MakeObject<Aspose::Words::AI::CheckGrammarOptions>();
grammarOptions->set_ImproveStylistics(true);
auto proofedDoc = model->CheckGrammar(doc, grammarOptions);
proofedDoc->Save(u"Output.docx");
class CustomAiModel : public Aspose::Words::AI::OpenAiModel
{
private:
System::String mUrl;
public:
CustomAiModel(System::String name, System::String url) : OpenAiModel(name) { mUrl = url; }
System::String get_Url() override { return mUrl; }
};
有三个选项可以将 Aspose.Words for C++ 安装到您的开发人员环境中。请选择符合您需求的一种,并按照分步说明进行操作:
您可以使用这个 C++ 库在 Microsoft Windows 、Linux 和 macOS 操作系统上开发软件:
如果您为 Linux 或 macOS 开发软件,请查看产品文档中 fontconfig 和 mesa-glu 开源包)的信息。