使用 OpenAI、Google 和 Claude AI 模型,结合 Aspose.Words for Python via .NET,检测并突出显示文档中的语法错误。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 的附加要求。