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

推荐订阅源

T
Threatpost
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
P
Privacy International News Feed
L
LINUX DO - 最新话题
博客园_首页
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
Kaspersky official blog
C
Cisco Blogs
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
罗磊的独立博客
MyScale Blog
MyScale Blog
Last Week in AI
Last Week in AI
A
About on SuperTechFans
G
GRAHAM CLULEY
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
D
DataBreaches.Net
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
AWS News Blog
AWS News Blog
I
InfoQ
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 叶小钗
Project Zero
Project Zero

博客园 - cn2025

kubeSphere发布ruoyi-web前端 20260711 kubeSphere发布ruoyi-pro后端 k8s集群-kubeShpere 20260710 安装Helm 20260710 k8s-portainer docker 镜像查询 k8集群一键重置 docker run OceanBase spring ai alibaba doc AI2.0 【多模态】 20260615 世界只有一个墨脱 AI2.0 【Mcp-client】 20260611 AI2.0 【Mcp-server】 20260611 GoLand 配Go SDK AI2.0 【redis向量-Rag】 问答顾问器QuestionAnswerAdvisor 20260608 AI2.0 【redis向量】redis-stack 20260608 AI2.0 【Embedding】嵌入模型 20260606 AI 工具 AI2.0 Tool调用20260604 AI2.0 对话chatMemory20260601 AI2.0 模型输出结构化【POJO、Record、List、Map 】20260530 AI2.0 Prompt【模板、流式 API、系统提示词】 20260529 AI2.0 自定义Advisor 20260528 AI2.0 ollama 20260528 AI2.0 dashscope-openai 20260527 ps 配Claude 20260527 spring-ai-alibaba-agent 260526 票务 Tool+Spring Security【动态tooLs:toolCallbacks】 20260525 spring-ai-alibaba-agent 260525 spring-ai-alibaba-agent 260523 票务 Tool接口 / 方法 / 参数【无意义、可读、业务化、参数数量过多】 20260521 票务 Tool参数幻觉 20260521 spring-ai-alibaba-agent 260521 spring-ai-alibaba-agent 260520 票务Tool 20260519 票务助手 -多模型20260518 结构化输出 -原理【structuredconverter】20260518 spring-ai-alibaba-agent 260518 Dify 添加Ollma模型qwen2:0.5b 应用 20260516 docker 部【dify-api】/【dify-web】 20260514 Chatclient 结构化输出20260514 spring-ai-alibaba-agent 260514 Chatmemory 多层(近、中、长期)20260513 ChatmemoryRedis 历史对话存【REDIS】20260512 ChatmemoryJdbc 历史对话存【JDBC】20260511 spring-ai-alibaba-agent 260511 ChatmemoryConversationId 多用户对话记忆 20260508 spring-ai-alibaba-agent 260508 ChatmemoryMax 历史对话长度20260507 2026SE Chatmemory 对话记忆20260506 spring-ai-alibaba-agent 260506 ChatClientPrompt 自定义拦截器【ReReadingAdvisor】重读提示词 20260430 docker-apache/kafka:4.1.2部暑 集群20260423 ChatClientPrompt Template.st20260428 ChatClientPrompt Template20260427 sb-KafkaListener 20260425 docker-apache/kafka:4.1.2部暑 20260425 dashscope-sb ChatClientPrompt20260425 SBAI-MultiPlatformAndModel 20260424 PlatformModel SB-ChatClient-DeepSeekDashScopeOllamaModel 20260424 dashscope-sb ChatClient20260420 ollama-sb 多态 图转文 20260418 【gemma3:4b 解析慢】 dashscope-sb 多模态(图片、语音识别) 文生视频 ollama-sb 20260414 dashscope-sb 阿里百炼-文生图20260413 dashscope-sb20260413 dashscope-sb20260411 docker-zabbix 20260410 deepseek-sb20260408 MQTT20260403 spring-ai-alibaba-agent 260403 MqttTest 20260401 spring-ai-alibaba-agent 260401 docker安装 EMQX spring-ai-alibaba-agent 260331 MQTT 20260331 spring-ai-alibaba-agent 三大 Java 生态 AI Agent 框架 CentOS7-静态 IP centos-stream10 安装 百炼-工作流-sb sb-flink1.13.1-jdk8-分隔字符串 20260125
ToolTemperature 温度过低,AI推算缺失自由度20260520
cn2025 · 2026-05-20 · via 博客园 - cn2025

image

1、pom

<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>3.2.0</spring-boot.version>
<spring-ai.version>1.0.0</spring-ai.version>
<spring-ai-alibaba.version>1.0.0.2</spring-ai-alibaba.version>
    <jedis.version>5.2.0</jedis.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 阿里云通义千问(DashScope)starter -->
<dependency>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>spring-ai-alibaba-starter-dashscope</artifactId>
</dependency>

<!--对话记忆 chat-memory-->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-autoconfigure-model-chat-memory</artifactId>
</dependency>
<!-- Spring AI JDBC 聊天记忆核心依赖 -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-chat-memory-repository-jdbc</artifactId>
</dependency>
<!-- Spring Boot JDBC Starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- MySQL 驱动 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Spring AI Alibaba Redis 记忆 Starter -->
<dependency>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>spring-ai-alibaba-starter-memory-redis</artifactId>
</dependency>

<!-- Jedis 客户端依赖 -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>

</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- 统一管理Spring AI依赖版本 -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>spring-ai-alibaba-bom</artifactId>
<version>${spring-ai-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Spring AI 里程碑/快照仓库(必须配置,否则依赖无法下载) -->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>

2、yml


server:
port: 18081
spring:
ai:
dashscope:
api-key: sk-8718a83408d7443b9544cXXXXXXXX
chat:
memory:
repository:
jdbc:
initialize-schema: always
schema: classpath:/sql/schema-mysql.sql
   memory:
   # Redis 配置必须放在 spring.ai 下,层级要和你的 @Value 匹配
   redis:
   host: 192.168.91.165 # 你的 Redis 地址
   port: 6379
   timeout: 5000
   # password: 123456 # 有密码再打开

datasource:
url: jdbc:mysql://192.168.91.165:3306/springai?useSSL=false&serverTimezone=UTC
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
logging:
level:
org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor: debug
#org.springframework.ai.chat.client.advisor: debug


3、service
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ToolService {

@Autowired
private TicketService ticketService;

@Tool(description = "获取指定位置的天气,根据位置自动推算经纬度")
public String getAirQuality(
@ToolParam(description = "纬度") double latitude,
@ToolParam(description = "经度") double longitude) {
return "天晴";
}

}



4、controller

import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import com.sb.dashscope18081.service.ToolService;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* @author Administrator
*/
@RequestMapping("/openai")
@ResponseBody
@Controller
public class ChatclientToolController {

@Autowired
private ChatClient.Builder chatClientBuilder;
//
@Autowired
private ToolService toolService;

/**
* Temperature温度过低,AI推算缺失自由度
* @param message
* @return
*/
@GetMapping("/simple/tooltemperature")
public String tooltemperature(
@RequestParam(value = "message",
defaultValue = "武汉天气是什么") String message
) {
// // 构建ChatClient并调用
ChatClient chatClient = chatClientBuilder
//底层就会告诉大模型提供什么
//.defaultTools(toolService)
.build();
String content = chatClient.prompt()
.options(DashScopeChatOptions.builder()
.withTemperature(1.9)
.build())
.user(message)
.tools(toolService)//用 .tools() 替代 defaultTools()
.call()
.content();

System.out.println("【Temperature温度过低,AI推算缺失自由度】:"+content);
return "【Temperature温度过低,AI推算缺失自由度】:"+content;
}
}

5、controller

5.1

[M5UIK2KU]OZL[FUKH_4PPR

 http://localhost:18081/openai/simple/tooltemperature?mesage=?mesage=武汉的天气是什么

image

 
5.2

D2@4A58IIKN}JWKDP0(Z}HG

 http://localhost:18081/openai/simple/tooltemperature?mesage=?mesage=武汉的天气是什么

image

6、controller
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import com.sb.dashscope18081.service.ToolService;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* @author Administrator
*/
@RequestMapping("/openai")
@ResponseBody
@Controller
public class ChatclientToolControllertest {
// @Autowired
// private ChatClient.Builder chatClientBuilder;
// //
// @Autowired
// private ToolService toolService;
ChatClient chatClient;

public ChatclientToolControllertest(ChatClient.Builder chatClientBuilder, ToolService toolService) {
chatClient= chatClientBuilder
.defaultTools(toolService)
.build();
}

@GetMapping("/simple/tooltest")
public String tool(
@RequestParam(value = "message",
defaultValue = "讲个笑话") String message
) {
String content = chatClient.prompt()
.user(message)
.call()
.content();

System.out.println(content);
return content;
}

@GetMapping("/simple/tooltest2")
public String tool2(
@RequestParam(value = "message",
defaultValue = "讲个笑话") String message
) {
String content = chatClient.prompt()
.user(message)
.call()
.content();

System.out.println(content);
return content;
}

/**
* Temperature温度过低,AI推算缺失自由度
* @param message
* @return
*/
@GetMapping("/simple/tooltemperaturetest")
public String tooltemperature1(
@RequestParam(value = "message",
defaultValue = "讲个笑话") String message
) {
String content = chatClient.prompt()
.options(DashScopeChatOptions.builder()
.withTemperature(0.1)
.build())
.user(message)
.call()
.content();

System.out.println("【Temperature-0.1温度过低,AI推算缺失自由度】:"+content);
return "【Temperature-0.1温度过低,AI推算缺失自由度】:"+content;
}

/**
* Temperature温度过低,AI推算缺失自由度
* @param message
* @return
*/
@GetMapping("/simple/tooltemperaturetest2")
public String tooltemperature12(
@RequestParam(value = "message",
defaultValue = "讲个笑话") String message
) {
String content = chatClient.prompt()
.options(DashScopeChatOptions.builder()
.withTemperature(1.9)
.build())
.user(message)
.call()
.content();

System.out.println("【Temperature-1.9温度过低,AI推算缺失自由度】:"+content);
return "【Temperature-1.9温度过低,AI推算缺失自由度】:"+content;
}
}

http://localhost:18081/openai/simple/tooltest?message=退票

image

http://localhost:18081/openai/simple/tooltemperaturetest?message=波密天气

image


http://localhost:18081/openai/simple/tooltemperaturetest2?message=波密天气

image