DeepSeek 已经成为很多开发者的首选 AI 编程工具——免费、无限、中文好、逻辑强。本文用一个真实 API 项目,手把手展示 DeepSeek 的编程工作流。
为什么开发者爱用 DeepSeek
- 完全免费:API 和网页版都是免费无限用
- 中文编程理解:中文注释、变量名理解精准
- 逻辑推理强:复杂业务逻辑的处理能力强
- API 价格低:$0.001/M tokens,企业成本极低
实战项目:构建一个 AI 文章摘要 API
Step 1:项目初始化
用 DeepSeek 生成项目结构:
mkdir article-summary-api
cd article-summary-api
npm init -y
npm install express @deepseek/sdk axios cors dotenv
Step 2:编写核心代码
让 DeepSeek 帮你写 main.js:
const express = require('express');
const axios = require('axios');
const cors = require('cors');
require('dotenv').config();
const app = express();
app.use(cors());
app.use(express.json());
app.post('/summary', async (req, res) => {
const { url } = req.body;
if (!url) return res.status(400).json({ error: '缺少url参数' });
try {
// 1. 抓取文章内容(用 Playwright 或 axios)
// 2. 调用 DeepSeek API 生成摘要
const response = await axios.post(
'https://api.deepseek.com/v1/chat/completions',
{
model: 'deepseek-chat',
messages: [{
role: 'user',
content: `请为以下文章生成100字摘要:\n{articleContent}`
}]
},
{
headers: {
'Authorization': `Bearer ${process.env.DEEPSEEK_API_KEY}`,
'Content-Type': 'application/json'
}
}
);
res.json({ summary: response.data.choices[0].message.content });
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.listen(3000, () => console.log('API 运行在 http://localhost:3000'));
Step 3:让 DeepSeek 帮你写完整测试代码
DeepSeek 的强项是:根据你的需求描述,直接生成完整的、可运行的代码。比 ChatGPT 更精准地理解中文注释和变量命名。
DeepSeek vs ChatGPT 编程对比
| 场景 | DeepSeek | ChatGPT |
|---|---|---|
| 中文项目 | ★★★★★ | ★★★★☆ |
| 英文项目 | ★★★★☆ | ★★★★★ |
| 复杂业务逻辑 | ★★★★★ | ★★★★☆ |
| API 文档生成 | ★★★★☆ | ★★★★★ |
| Bug 排查 | ★★★★★ | ★★★★☆ |
| 免费程度 | ★★★★★(完全免费) | ★★★☆☆($20/月) |
总结
DeepSeek 是中文项目的编程首选,免费 + 高质量让它的性价比远超 ChatGPT。建议用 DeepSeek 做日常编程主力,复杂任务再用 ChatGPT。