DeepSeek-R1 免费本地部署 和 Python 调用

Windows上的本地化部署deepseek-r1,独享DeepSeek,真香 ,使用python调用非常快 欢迎来到涛涛聊AI。Ollama是一个强大的工具,可以帮助你在本地轻松部署和管理大语言模型,如deepseek-r1。DeepSeek-R1是由DeepSeek团队开发的第一代高性能推理模型,旨在通过强化学习提升大语言模型的推理能力。该模型采用大规模专家混合(MoE)架构,参数规模高达6710亿,是许多开源大模型的10倍。DeepSeek-R1在数学、代码和推理任务上表现出色,尤其在长链推理(CoT)方面表现优异。此外,它还支持模型蒸馏,能够将推理能力迁移到小型模型上,提升其性能。 阅读详情
AI摘要

本文介绍了DeepSeek - R1免费本地部署及Python调用方法。本地部署需先安装Ollama,根据显卡显存或内存选择合适模型下载,通过命令行操作完成安装与运行,还可更改环境变量。Python调用方面,先运行服务,再介绍了generate和chat两种调用方式。

1、安装 Ollama 及R1本地测试
打开ollama官网
点击download,根据系统选择对应的安装包
下载后点击Install安装
通过Win+R打开命令行
cmd
输入代码测试安装成功,同时查看相关命令
ollama -v
下面回到ollama官网点击左上角Models
如果你的显卡有8G以上显存或8G以上内存,可以尝试7b的模型,如果没有就直接选择1.5b模型。下面是集中模型的下载代码,可以直接复制,粘贴到命令行。
DeepSeek-R1-Distill-Qwen-1.5B
ollama run deepseek-r1:1.5b
DeepSeek-R1-Distill-Qwen-7B
ollama run deepseek-r1:7b
复制安装命令在命令行,enter运行,等待下载完成。
通过ollama list查看已安装模型
ollama list
通过ollama run +模型名称运行模型,我这里是7b模型因此使用
ollama run deepseek-r1:7b
如果是1.5b模型则使用
ollama run deepseek-r1:1.5b
现在就可以开始对话了

如想要更改MODELS,HOST,等环境变量
set OLLAMA_MODELS=E:\ollama
set OLLAMA_HOST=0.0.0.0:8888
set OLLAMA_ORIGINS=*

2、Python 调用
1.运行服务
ollama serve
2.Python 调用

generate方式:

import requests
import json
import subprocess
while True:
    user_input = input(">>>")
    if user_input=='/bye':break
    if user_input=='/clear':
        subprocess.call('cls',shell=True)
        continue
    url = "http://localhost:11434/api/generate"
    data = { "model": "deepseek-r1:7b", "prompt": user_input }
    response = requests.post(url, json=data,stream=True)
    for line in response.iter_lines(): 
        if line: 
            data = json.loads(line.decode('utf-8'))
            print(data["response"],end='')
    print("\n")

chat方式:

import requests
import json
import subprocess
url = "http://localhost:11434/api/chat"
headers = {"Content-Type": "application/json"}
messages = [
    {
        "role": "system",
        "content": "You are a warm-hearted assistant, and you only speak Chinese."
    },
    {
        "role": "user",
        "content": "李华去公园玩把腿摔断了,被送到医院了。腿摔断一般要多长时间好?"
    },
    {
        "role": "assistant",
        "content": "腿摔断的恢复时间不一,通常需要几个月才能基本康复。\n\n如果是轻微的骨折,一般可以在1-2个月内恢复,主要需要注意休息和康复锻炼。"
    }
]
while True:
    user_input = input(">>>")#李华为啥去医院了?
    if user_input=='/bye':break
    if user_input=='/clear':
        subprocess.call('cls',shell=True)
        continue
    prompt= {
         "role": "user",
         "content": user_input
     }
    messages.append(prompt)
    # 初始对话
    data = {
      "model": "deepseek-r1:7b",
      "messages": messages,
      "stream": False
    }
    response = requests.post(url, headers=headers, data=json.dumps(data))
    print(response.json()['message']['content'])
    messages.append(response.json()['message'])
    if len(messages) >21:
        del messages[1:3]
 

Python接入DeepSeek全指南:从API调用到本地部署的完整方案 本文详细介绍了Python接入DeepSeek大语言模型的三种主要方式:云端API调用、本地模型部署和IDE集成。云端API调用适合快速接入,提供示例代码和进阶技巧;本地部署方案适用于数据敏感场景,包含环境准备和模型加载步骤;IDE集成则能提升开发效率。每种方案各有优势,开发者可根据项目需求、硬件条件和预算选择最适合的接入方式。文章还涵盖了API密钥管理、流式响应、错误处理等实用技巧,为开发者提供全面的接入指南。 阅读详情

相关推荐

本地部署deepseek-r1建立向量知识库和知识库检索实践【代码】

本地部署DeepSeek-r1后,进行探索本地知识库,向量数据库的建立,文档的解析,利用知识库和大模型进行集成检索。

AI人人懂 3127

小白deepseek本地部署+Python调用初尝试

近期火爆全网的deepseek大模型,因为官网一直繁忙啊很多人都在进行本地的部署操作,下面我来分享一下我折腾本地部署的初尝试以上就是今天要分享的内容,本文仅仅简单介绍了如何本地部署一个deepseek大模型。

m0_67683593的博客 7326

【DeepSeek】DeepSeek R1 本地部署(Ollama+Docker+OpenWebUI)

如果您遇到连接问题,通常是由于 WebUI docker 容器无法访问容器内 127.0.0.1:11434 (host.docker.internal:11434) 处的 Ollama 服务器。我的电脑是21款 MacBookPro M1 Pro,运行内存16G,显卡是集成显卡,与内存共用同一内存,下载的模型是DeepSeek-R1 8B,后面内存开销很多,导致电脑变卡,可能需要重启,后面下载1.5b 版本,会好很多。根据自己的显存选择对应的模型,2G显卡推荐选1.5b的。打开终端,输入刚复制的命令。

通往成功之路的一个过客 2207

Python 调用本地部署DeepSeek的API

如果你在调用过程中遇到问题,可以检查 API 端点或错误日志,或者反馈给我们!Ollama 的 API 端点与 OpenAI 兼容 API 不同,需要使用。说明 Ollama 运行正常,并且已安装 DeepSeek 模型。DeepSeek 的 AI 回复。你可以在终端输入以下命令来查看。如果希望让 Ollama。,默认 API 运行在。

李东阳的博客 1341

【亲测可行】本地部署deepseek & api免费部署满血版deepseek & python中配置api使用满血版deepseek-r1

本地部署时显卡不好的话根本带不动,如果显卡是4090的话,可以带动14B的,32B可能比较吃力.把复制的API粘贴到下面的地方,模型选择DeepSeek-R1,最后点击保存。deepseek-R1原始模型参数为671B (billion 十亿)deepseek最好的模型是deepseek-R1。下面三个客户端都可以,下面以chatbox为例。意思是该模型有6710亿个参数。

分享计算机视觉,C++,网络摄像头研发,音视频开发,嵌入式等知识。 5038

DeepSeek-R1 本地部署文档

在docker容器中使用ollama服务本地化部署deepseek-r1模型,运行在nvdia gpu上

wohenibdxt的博客 3026

Python 调用 DeepSeek API 完整指南

本文将详细介绍如何使用 Python 调用 DeepSeek API,实现流式对话并保存对话记录。相比 Go 版本,Python 实现更加简洁优雅,适合快速开发和原型验证。Python 版本的 DeepSeek API 调用实现简单直观,适合快速开发和测试。通过流式处理和文件记录,提供了完整的对话体验。

大白菜代码的博客 2万+

本地部署DeepSeek-R1模型接入PyCharm

本地部署DeepSeek-R1模型接入PyCharm

2301_79763109的博客 4297

使用 Ollama 在本地运行 DeepSeek-R1 模型

目前没有公开的免费测试环境支持通过公网访问ollama和接口。如果你需要测试,建议在本地搭建环境,或者使用云服务提供商(如AWS、GCP、Azure)的免费试用资源来部署和测试。

Leon_Jinhai_Sun的博客 313

保姆级教学——本地免费部署DeepSeek-R1模型并通过Python调用

【代码】保姆级教学——本地免费部署DeepSeek-R1模型并通过Python调用。

shuaige_shiwoa的博客 721

【手把手】DeepSeek-R1本地部署:从零到API调用

DeepSeek-R1 是 DeepSeek 研发的系列推理模型,2025 年 1 月 20 日,DeepSeek 正式发布 DeepSeek-R1 模型,并同步开源模型权重,且推出了 API 服务。

chuweiyan的博客 6847

一键部署DeepSeek-R1:Ollama让AI推理变得如此简单

本文介绍了如何在星图GPU平台上自动化部署DeepSeek-R1-Distill-Llama-8B镜像,快速搭建AI推理环境。该平台简化了部署流程,用户可轻松获得一个强大的开源大语言模型,并将其应用于代码生成、逻辑推理、内容创作等实际场景,显著提升开发与学习效率。

weixin_42527665的博客 41

Labview执行adbshell操作

一、目录 1、实现思路 2、adbshell工具配置 3、Labview执行命令窗口 1、实现思路 使用Labview的优点: 1、可以配合电源系统或者调用其他接口工具实现更高程度的自动化测试; 2、直接执行Linux相关命令,编写相关执行顺序或者逻辑更简易; --------可以用adbpush命令将.sh的脚本文件推入控制器内部执行; 3、Ubuntu系统比较大,如果只是日常执行脚本测试还是比较占用磁盘空间; 2、adbshell工具配置 1)下载adbshell工具; adbshell工具下载链

zataji的博客 2054

白嫖AI大模型,让调测更逼真

-data-raw '{"text": "查询今年参加高考人数,只需要输出文本"}'已支持大模型:百度AI大模型-DeepSeek-R1。1. 百度AI大模型: DeepSeek-R1。前提条件:已安装python3.9+生产AI大模型,让开发调测更逼真。

neozzh的专栏 589

华为云CodeHub保姆级教程:从零开始,5分钟搞定本地代码上传(含常见报错解决)

本文提供华为云CodeHub的保姆级教程,从零开始5分钟完成本地代码上传,涵盖环境准备、仓库创建、远程连接及常见报错解决。特别适合新手开发者快速掌握Git命令与云端协作流程,确保代码安全高效上传。

weixin_30443075的博客 480

交叉验证选型指南:k折、留一法、时序与分层CV实战决策

交叉验证是评估机器学习模型泛化能力的基础技术,其核心在于通过系统性数据重划分,缓解有限样本对真实分布估计的偏差。原理上,它通过控制训练-验证数据的独立性与代表性,诊断过拟合风险并提升性能指标的稳定性。技术价值体现在避免单次切分导致的结果偶然性、数据利用低效及验证集污染等问题。典型应用场景涵盖分类任务中的类别不平衡处理、时间序列预测的因果约束、用户行为建模中的数据泄露防控等。本文聚焦k折交叉验证、留一法、时间序列交叉验证与分层抽样等主流方法的适用边界与工程落地要点,结合过拟合诊断和泛化能力评估两大热词,提供可

dienangpiao2051的博客 477

本地部署DeepSeek-R1模型(新手保姆教程)

本地部署deepseek-r1模型调用,新手保姆教程,无需代理

weixin_46277779的博客 4万+

VisionPro开发实战:CogRecordDisplay控件显示与保存图片的完整流程(附C#代码示例)

本文详细解析了VisionPro开发中CogRecordDisplay控件的图像处理全流程,包括图像加载、显示优化、动态清屏及结果保存等关键操作。通过C#代码示例,展示了如何高效使用该控件进行工业视觉应用开发,特别适合自动化检测系统的开发者参考。

weixin_42523792的博客 277

【AI 大模型】DeepSeek 大模型简介 ( DeepSeek-R1 和 DeepSeek-V3 大模型 | Python 调用 DeepSeek API | 本地部署 DeepSeek )

一、DeepSeek 大模型 1、DeepSeek-R1 和 DeepSeek-V3 大模型 DeepSeek-V3 大模型 DeepSeek-R1 大模型 大模型调用 2、DeepSeek 官网访问 DeepSeek-R1 和 DeepSeek-V3 大模型 3、DeepSeek 大模型参数 4、DeepSeek 蒸馏模型本地部署硬件需求 二、DeepSeek 开发者平台 1、开放平台地址 2、申请 API Key 3、Python 调用 DeepSeek API 三、本地部署 DeepSeek 大模型

让 学习 成为一种 习惯 ( 韩曙亮 の 技术博客 ) 2万+

【电驱动】永磁同步电机工作原理及分类

永磁同步电机工作原理及分类

星Yeah 的博客 7334

步进电机 cia402协议 报文自己的理解 (笔记)

步进电机 cia402协议 报文自己的理解 (笔记)

she666666的博客 3813

边缘计算场景下的大模型落地:基于 Cherry Studio 的 DeepSeek-R1-0528 本地部署

作为学生,我选择用 Cherry Studio 在本地调用 DeepSeek-R1-0528,完全是被它的实用性和 “性价比” 圈粉。最近在 GitHub 和 AI 社群里,大家都在热议 DeepSeek-R1-0528,尤其是它的数学解题和编程能力。像我在准备数学建模竞赛时,用它推导算法公式,居然能给出比参考答案更简洁的步骤;写 Python 爬虫作业,它甚至能直接帮我优化代码的运行效率,比我自己反复调试快多了。

K48932的博客 2万+

多模态对齐方案

本文中我们介绍了 13 中常见的大型多模态模型(Large Multimodal Models, LMM),包括 BLIP-2,LLaVA、MiniGPT、Qwen-VL 以及 Ferret 等。最全 LMM 模型结构(13种)综述。单层linear投影、两层mlp。

liguandong 2084

高效快速教你deepseek如何进行本地部署并且可视化对话

随着最近一个新的人工智能deepseek的爆火,很多大佬都开始了在本地进行deepseek的部署操作,并且离线也可以使用,这里的话我就一步一步带你们部署本地的deepseek,说实话这个人工智能的实力不亚于open ai 的gpt。

2301_80863610的博客 3万+

PMP–一、二、三模–分类–13.干系人管理

A:确认是否已制定沟通管理计划,使业务干系人认识到项目的成功之处。B:让业务干系人参加冲刺回顾会议。C:与发起人和关键干系人一起确定产品待办事项列表中的优先要务,以便交付商业利益。D:为关键干系人开展收尾调研。C。

stqer的博客 1418

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: Python练手项目:PDF小工具-fitz版
下一篇: HTML 之 MP3复读器
小6哥
博客等级 码龄18年 16粉丝 17原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值