springai接入本地部署deepseek
时间: 2025-02-22 11:57:03 AIGC 浏览: 113
### 部署 DeepSeek 并与 Spring AI 集成
#### 准备工作环境
为了确保顺利部署,需先安装 Docker[^1]。Docker 是容器化平台,能够简化应用程序及其依赖项的打包过程。
#### 创建 Spring Boot 项目
访问 [https://start.spring.io/](https://start.spring.io/) 来创建一个新的 Spring Boot 项目。在构建工具部分选择 Maven 或 Gradle,并指定 Java 版本。点击 ADD DEPENDENCIES 后,在搜索框输入 Ollama 添加相应依赖,这一步骤实现了 Spring AI 对 Ollama 的支持[^3]。
```xml
<dependency>
<groupId>com.ollama</groupId>
<artifactId>spring-ai-starter</artifactId>
<version>${latest.version}</version>
</dependency>
```
#### 设置 DeepSeek-R1 API 服务
完成上述准备工作之后,按照官方文档指导设置 DeepSeek-R1 API 接口。此阶段涉及配置文件调整以及必要的参数设定,以适应具体的硬件条件和业务需求[^2]。
#### 编写控制器类
定义 RESTful Web Service 控制器用于处理来自客户端请求并向 DeepSeek 发送查询:
```java
@RestController
@RequestMapping("/api/deepseek")
public class DeepSeekController {
@Autowired
private DeepSeekService deepSeekService;
@PostMapping("/query")
public ResponseEntity<String> query(@RequestBody String inputText){
try {
String result = deepSeekService.query(inputText);
return new ResponseEntity<>(result, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>("Error occurred", HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
```
#### 测试 API 功能
启动应用服务器后,可以通过 Postman 或 curl 工具发送 POST 请求测试新搭建的服务端点是否正常运作。
```bash
curl -X POST http://localhost:8080/api/deepseek/query \
-H "Content-Type: application/json" \
-d '{"text":"your question here"}'
```
阅读全文
相关推荐
















