Deepseek学习随笔(6)--- API 开发与自动化
获取 API Key
要开始使用 DeepSeek 的 API,你首先需要获取 API Key:
- 登录 DeepSeek 控制台 。
- 进入 API 管理 页面,生成 API Key。
![]()
API 调用示例(Python)
以下是一个使用 Python 调用 DeepSeek API 的示例:
import requests
API_KEY = "your_api_key_here"
API_URL = "https://api.deepseek.com/v1/generate"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
data = {
"prompt": "请生成一段关于人工智能的科普文本",
"max_tokens": 100
}
response = requests.post(API_URL, headers=headers, json=data)
print(response.json())
构建自动化工作流
通过 API,你可以构建各种自动化工作流,如每日简报生成、数据报告自动发送等。
示例场景
假设你需要每天自动生成一份销售数据报告,你可以使用 DeepSeek API 编写自动化脚本,自动分析数据并生成报告。
import requests
import schedule
import time
API_KEY = "your_api_key_here"
API_URL = "https://api.deepseek.com/v1/generate"
def generate_daily_report():
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
data = {
"prompt": "请分析今日的销售数据,并生成一份报告",
"max_tokens": 200
}
response = requests.post(API_URL, headers=headers, json=data)
print(response.json())
schedule.every().day.at("09:00").do(generate_daily_report)
while True:
schedule.run_pending()
time.sleep(1)
通过这种方式,你可以自动化生成每日销售报告,提升工作效率。

浙公网安备 33010602011771号