
本地部署 DeepSeek:从 Ollama 配置到 Spring Boot 集成
随着人工智能技术的迅猛发展,越来越多的开发者希望在本地环境中部署和调用 AI 模型,以满足特定的业务需求。本文将详细介绍如何在本地环境中使用 Ollama 配置 DeepSeek 模型,并在 IntelliJ IDEA 中创建一个 Spring Boot 项目来调用该模型。通过这些步骤,您将能够在本地环境中高效地运行和测试 AI 模型,提升开发效率。
前言
随着人工智能技术的迅猛发展,越来越多的开发者希望在本地环境中部署和调用 AI 模型,以满足特定的业务需求。本文将详细介绍如何在本地环境中使用 Ollama 配置 DeepSeek 模型,并在 IntelliJ IDEA 中创建一个 Spring Boot 项目来调用该模型。通过这些步骤,您将能够在本地环境中高效地运行和测试 AI 模型,提升开发效率。
详细步骤
一、本地配置DeepSeek
1.安装Ollama
Ollama 是一个开源平台,旨在简化大型语言模型的本地部署和管理。您可以从 Ollama官网下载适用于 Windows、Linux 或 macOS 的安装包。
安装成功后可以使用win+R并输入cmd打开终端,接着输入ollama检查是否安装成功,如果有输出对应信息则说明安装成功了
2.下载对应DeepSeek模型并运行
首先选中想要配置的DeepSeek版本并复制右侧指令
将指令复制到终端并进行下载对应版本的DeepSeek,下载完成之后到这个界面,就是下载成功了,可以输入一些信息进行测试
二、SpringBoot项目调用本地DeepSeek
1.创建springboot项目
具体操作如下:
- 打开 IntelliJ IDEA,选择 "New Project"。
- 选择 "Spring Initializr" 作为项目类型。
- 填写项目的基本信息,如 Group、Artifact 等。
- 在 "Dependencies" 中添加所需的依赖,例如 "Spring Web"。
- 点击 "Create" 创建项目。
这里我添加了Web和Ollama的依赖,创建成功界面如下
2.添加deepseek对应配置信息
在application.properties中添加下面配置信息
spring.ai.ollama.chat.options.model=deepseek-r1:1.5b
spring.ai.ollama.base-url=http://127.0.0.1:11434
spring.ai.ollama.chat.enabled=true
server.port=9099
3.编码调用deepseek
接着创建简单controller类和service实现类,结构如图:
对应代码如下:
controller:
@RestController
public class testController {
@Autowired
private DeepSeekTestService deepSeekTestService;
@RequestMapping("/ask1")
public String speak(@RequestParam String msg){
return deepSeekTestService.getResponse(msg);
}
}
service接口:
public interface DeepSeekTestService {
String getResponse(String message);
}
service实现类
@Service
public class DeepSeekServiceImpl implements DeepSeekTestService {
private final OllamaChatModel ollamaChatModel;
public DeepSeekServiceImpl(OllamaChatModel ollamaChatModel) {
this.ollamaChatModel = ollamaChatModel;
}
@Override
public String getResponse(String message) {
String response = ollamaChatModel.call(message);
return response;
}
}
4.测试
启动项目,在浏览器的url路径中输入对应信息进行测试,这样一个简单的springboot对接deepseek项目就完成了!
好久没有更新了,绝对不是懒哈哈哈,好吧其实就是懒了,后面会继续更新一些有关Java的学习知识!还希望大家多多点赞支持,你的支持就是我的最大动力!!!
更多推荐
所有评论(0)