惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 聂微东
GbyAI
GbyAI
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
Visual Studio Blog
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
B
Blog
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
雷峰网
雷峰网
爱范儿
爱范儿
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
Jina AI
Jina AI
P
Proofpoint News Feed
A
About on SuperTechFans
I
InfoQ
F
Fortinet All Blogs
L
LangChain Blog
T
Tailwind CSS Blog

博客园 - zhaofeng555

欧氏距离 vs 余弦相似度 相似度2-欧式距离 相似度1-余弦相似度 Oh-My-OpenCode介绍 OpenCode 里的 Atlas / Sisyphus / Prometheus区别 安装opencode langchain第二个小例子 langchain的第一个小例子 springai访问本地alloma第一个例子 springai访问本地alloma的qwen3报错 C/c++趣味程序百例 mac 安装stale disffusion笔记 mac 安装TA-Lib包 centos7 install docker CentOS7 内核升级从3.10升级到4.4(以kernel-lt 为例) 一个数组中有一个重复的数字,O(n) 找出来 找数组中重复的数字 mysql server 端命令 mac安装python3 pandas tushare
springai第二个例子使用配置类配置chatclient
zhaofeng555 · 2026-01-09 · via 博客园 - zhaofeng555
package com.haojg.config;

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

@Configuration
public class ChatModelConfig {

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

}
package com.haojg.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ChatController {

    @Autowired
    private ChatClient chatClient;

    // 第1种方式通过ChatClient.Builder创建
//    public ChatController(ChatClient.Builder builder) {
//        this.chatClient=builder.build();
//    }
    // 第2种通过ChatModel创建
//    public ChatController(ChatModel chatModel) {
//        this.chatClient = ChatClient.builder(chatModel).build();
//        this.chatClient = ChatClient.create(chatModel);
//    }
    // 第3种通过ChatModel创建
//    public ChatController(ChatModel chatModel) {
//        this.chatClient = ChatClient.create(chatModel);
//    }

    @GetMapping(value = "/chat", produces = "text/plain")
    public String chat(String message) {
        String content = chatClient.prompt(message).call().content();
        log.info("message={}, content:{}", message, content);
        return content;
    }

}