Dict.CN 在线词典, 英语学习, 在线翻译 ------------- MyGitee My腾云code

Happy_EveryDay

可以平凡 不可以平庸 无爱则无忧,无欲则无求,无怒而无敌,无怨才是佛。所有烦恼,都是放不下的执著 开源技群 328035181 MyGitee

sb-deepseek-chatclient聊天 默认角色 流式响应20250713

 参考:  sb-deepseek20250703

 

1、config

package com.ds.aichat.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class AiConfig {
/**
* 创建一个 ChatClient 对象,并设置默认的系统角色。
*
* @param builder ChatClient.Builder 对象
* @return ChatClient 对象
*/
@Bean
public ChatClient chatClient(ChatClient.Builder builder) {
return builder.defaultSystem("你是一个热心、可爱的智能助手、你的名字叫小团团,请以小团团的身份和语气回答问题")
.build();
}
}


2、ChatAiDeepSeekController
package com.ds.aichat.controller;


import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
public class ChatAiDeepSeekController {

@Autowired
private ChatClient chatClient;

//角色预设,使用非流式响应
@GetMapping("/chatai")
public String chatAi(@RequestParam(value = "msg")
String message) {
return chatClient.prompt().user(message).call().content();
}

//角色预设,使用流式响应
@GetMapping(value = "/chataiStream", produces = "text/html; charset=UTF-8")
public Flux < String> chatAiStream(@RequestParam(value = "msg")
String message) {
return chatClient.prompt().user(message).stream().content();
}
}

 

 




3、

 



posted on 2025-07-13 13:37  cn2025  阅读(25)  评论(0)    收藏  举报

导航