本文主要是介绍SpringBoot配置Ollama实现本地部署DeepSeek,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
《SpringBoot配置Ollama实现本地部署DeepSeek》本文主要介绍了在本地环境中使用Ollama配置DeepSeek模型,并在IntelliJIDEA中创建一个Sprin...
前言
随着人工智能技术的迅猛发展,越来越多的开发者希望在本地环境中部署和调用 AI 模型,以满足特定的业务需求。本文将详细介绍如何在本地环境中使用 Ollama 配置 DeepSeek 模型,并在 IntelliJ IDEA 中创建一个 Spring Boot 项目来调用该模型。通过这些步骤,您将能够在本地环境中高效地运行和测试 AI 模型,提升开发效率。
详细步骤
一、本地配置Dwww.chinasem.cneepSeek
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、ArtifaChina编程ct 等。
- 在 "Dependencies" 中添加所需的依赖,例如 "Spring Web"。
- 点击 "Create" 创建项目。
这里我添加了Web和Ollama的依赖,创建成功界面如下
2.添加deepseek对应配置信息
在application.properties中添加下面配置信息
spring.ai.ollama.chat.options.model=deepseek-r1:http://www.chinasem.cn1.5b
spring.ai.ollama.base-url=http://127.0.0.1:11434
sprinhttp://www.chinasem.cng.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 OllaandroidmaChatModel 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项目就完成了!
到此这篇关于SpringBoot配置Ollama实现本地部署DeepSeek的文章就介绍到这了,更多相关SpringBoot 本地部署DeepSeek内容请搜索编程China编程(www.chinasem.cn)以前的文章或继续浏览下面的相关文章希望大家以后多多支持China编程(www.chinasem.cn)!
这篇关于SpringBoot配置Ollama实现本地部署DeepSeek的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!