ChatClient和ChatModel

ChatModel常用的消息发到LLM,LLM返回

ChatClient,基于ChatModel构建,支持prompt,格式输出,参数交互,聊天记忆,工具调用,RAG

ChatClient

不支持自动注入,必须手动注入

@Bean
public ChatClient chatClient(ChatModel chatModel) {
    return ChatClient.builder(chatModel).build();
}

或者

@RestController
public class ChatClientController {
    private final ChatClient chatClient;

    public ChatClientController(ChatModel chatModel){
        this.chatClient = ChatClient.builder(chatModel).build();
    }
    @GetMapping("/chat/client")
    public Flux<String> chat2(@RequestParam(value = "message") String message) {
        return chatClient.prompt().user(message).stream().content();
    }
}