B站先查看deepseek的应用和API调用和本地化部署这三方面知识
- 确认 Ollama 是否正确运行
如果你使用 Ollama 部署了 DeepSeek,默认 API 运行在 11434 端口。首先,检查 Ollama 是否正常运行:
curl http://localhost:11434/api/tags
如果返回:
{“models”:[“deepseek-coder:latest”, “deepseek-chat:latest”]}
说明 Ollama 运行正常,并且已安装 DeepSeek 模型。
- Python 调用 Ollama 运行的 DeepSeek
2.1 发送对话请求
Ollama 的 API 端点与 OpenAI 兼容 API 不同,需要使用 /api/generate:
import requests
import json
API_URL = “http://localhost:11434/api/generate” # Ollama API 端点
headers = {
“Content-Type”: “application/json”
}
data = {
“model”: “deepseek-coder”, # 你的 DeepSeek 模型名称
“prompt”: “请介绍一下 DeepSeek。”,
“stream”: False # 关闭流式输出
}
response = requests.post(API_URL, headers=headers, json=data)
if response.status_code == 200:
result = response.json()
print(“AI 回复:”, result[“response”])
else:
print(“请求失败:”, response.status

最低0.47元/天 解锁文章
1067

被折叠的 条评论
为什么被折叠?



