本文介绍如何通过 WPS JS宏调用 DeepSeek 大模型,实现自动化文本扩写、校对和翻译等功能。
一、文本扩写
1、随便打开一个word文档,点击工具栏“工具”。
2、点击“开发工具”。
3、点击“查看代码”。
4、在打开的WPS宏编辑器界面中,左侧找到“Project(Normal.dotm)”,在“代码”上右击,选择“插入”->“模块”。
5、在新建的模块“Module1”上右击,点击“重命名”,重命名为“deepseek_expand”。
6、在右边的代码编辑器中,粘贴JS宏代码 ,保存。
const OPENAI_API_KEY = "改成自己的";
const OPENAI_API_URL = "https://api.deepseek.com/v1/chat/completions";
const OPENAI_MODEL = "deepseek-chat";
function PROMPT_TEMPLATE(text) {
return `你是一位专业的文本扩写助手。请根据以下要求扩写文本:
1. 保持原文核心意思不变
2. 增加相关细节和背景信息
3. 使用正式、专业的语言风格
请扩写以下文本:
${
text}`;
}
async function expandText() {
const selection = Application.Selection;
if (!selection || !selection.Text) {
alert("请选中需要扩写的文本");
return;
}
const originalText = selection.Text;
const prompt = PROMPT_TEMPLATE(originalText);
try {
const response = await fetch(OPENAI_API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer