Ollama 本地部署开源模型 设置公网可访问API,并在vscode当中调用
最新版设置允许跨域并启动
Ollama 支持的 API 端点
端点 | 说明 |
---|---|
http://localhost:11434/api/generate |
生成文本(DeepSeek LLM) |
http://localhost:11434/api/tags |
列出可用模型 |
http://localhost:11434/api/show?name=deepseek-coder |
查看模型信息 |
http://localhost:11434/api/pull |
下载新模型 |
1. 确认 Ollama 是否正确运行
如果你使用 Ollama 部署了 DeepSeek,默认 API 运行在 11434 端口。首先,检查 Ollama 是否正常运行:
http://localhost:11434/api/tags
import requests import json API_URL = "http://host:port/api/generate" headers = { "Content-Type": "application/json" } data = { "model": "deepseek-r1:14b", "prompt": "请介绍一下 DeepSeek。", "stream": True # 开启流式输出 } response = requests.post(API_URL, headers=headers, json=data, stream=True) for line in response.iter_lines(): if line: json_data = json.loads(line.decode("utf-8")) print(json_data.get("response", ""), end="", flush=True)
在VSCode当中调用
安装cline插件
Api provider 选择Ollama
Base Url 输入 API 的根目录 http://host:port