使用 Aspose.Words for C++ 搭配 OpenAI、Google 與 Claude AI 模型,偵測並標示文件中的文法錯誤。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 開源包)的信息。