springboot集成deepseek
最近deepseek很火写一篇随文
1.deepseek官网:https://www.deepseek.com/
2.spring-ai官网:https://docs.spring.io/spring-ai/reference/api/chat/deepseek-chat.html
3.截止到目前springboot已经集成了deepseek极大的简化了使用难度

4.pom文件配置
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
<version>1.0.0-M5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
5.controller代码
/***
* @author zhanchaohan
*/
@RestController
public class ChatController {
private final OpenAiChatModel chatModel;
@Autowired
public ChatController(OpenAiChatModel chatModel) {
this.chatModel = chatModel;
}
@GetMapping("/ai/generate")
public Map generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
return Map.of("generation", this.chatModel.call(message));
}
@GetMapping("/ai/generateStream")
public Flux<ChatResponse> generateStream(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
Prompt prompt = new Prompt(new UserMessage(message));
return this.chatModel.stream(prompt);
}
}
6.配置信息
spring.application.name=deepseek spring.ai.openai.api-key= spring.ai.openai.base-url=https://api.deepseek.com spring.ai.openai.chat.options.model=deepseek-chat spring.ai.openai.chat.options.temperature=0.7 # The DeepSeek API doesn't support embeddings, so we need to disable it. spring.ai.openai.embedding.enabled=false
7.打开浏览器访问http://localhost:8080/ai/generate



浙公网安备 33010602011771号