使用 Aspose.Words for Python via .NET 搭配 OpenAI、Google 與 Claude AI 模型,偵測並標示文件中的文法錯誤。CheckGrammar 方法會分析 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 與 EPUB 檔案,並標記文法問題 — 協助您無需手動校對即可產出完美且專業的內容。
驗證需要您所選擇之 AI 提供者的 API 金鑰。如需支援模型的完整清單,請參閱 API 參考資料。
立即開始檢查 Python 中的文法 — 試用上方的即時示範。
pip install aspose-words
複製
doc = aw.Document("Document.docx")
api_key = os.getenv("API_KEY")
# 使用 OpenAI 的生成式語言模型。
model = aw.ai.AiModel.create(aw.ai.AiModelType.GPT_4O_MINI).with_api_key(api_key).as_open_ai_model()
grammar_options = aw.ai.CheckGrammarOptions()
grammar_options.improve_stylistics = True
proofed_doc = model.check_grammar(doc, grammar_options)
proofed_doc.save("Output.docx")
doc = aw.Document("Document.docx")
# Pass an empty string if the self-hosted model does not require an API key.
model = CustomAiModel("my-model-24b", "https://your-server.com/v1").with_api_key("")
grammar_options = aw.ai.CheckGrammarOptions()
grammar_options.improve_stylistics = True
proofed_doc = model.check_grammar(doc, grammar_options)
proofed_doc.save("Output.docx")
class CustomAiModel(aw.ai.OpenAiModel):
def __init__(self, name, url):
super().__init__(name)
self._url = url
@property
def url(self):
return self._url
我們在PyPi存儲庫中託管我們的 Python 請按照有關如何 "Aspose.Words for Python via .NET" 安裝到您的開發人員環境的分步說明進行操作。
這個包與 Python ≥3.5 和 <3.12 兼容。如果您為 Linux 開發軟件,請查看產品文檔中對 gcc 和 libpython 的附加要求。