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

推荐订阅源

J
Java Code Geeks
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
A
About on SuperTechFans
Vercel News
Vercel News
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
V
Visual Studio Blog
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
美团技术团队

博客园 - 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;
    }

}