sb-deepseek-chatclient聊天20250703
1、application.properties
spring.application.name=ai-chat
server.port=8899
spring.ai.openai.api-key=sk-595b6ce15e1c4a16b1bbae6b8ee16a4d
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
2、
package com.ds.aichat.controller;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ChatDeepSeekController {
private final ChatClient chatClient;
public ChatDeepSeekController(ChatClient.Builder chatClientBuilder) {
this.chatClient = chatClientBuilder.build();
}
@GetMapping("/chat")
public String chat(@RequestParam(value = "msg", defaultValue = "给我讲个笑话吧")
String message) {
//提示词
return chatClient.prompt()
//用户输入信息
.user( message)
//模型调用
.call()
//返回文本
.content();
}
}
3、