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

推荐订阅源

S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园 - 【当耐特】
月光博客
月光博客
Vercel News
Vercel News
D
Docker
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
有赞技术团队
有赞技术团队
雷峰网
雷峰网
博客园 - 聂微东
小众软件
小众软件
Y
Y Combinator Blog
腾讯CDC
L
LangChain Blog
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss

博客园 - cn2025

K8s -sentinel-dashboard【nacos版本】集 20260815 kubeSphere【ks-controller-manager-webhook-cert】证书 20260814 K8s -nacos集 20260813 K8s - 安装部署redis集群-哨兵sentinels集(支持从K8s外部访问)20260812 k8s-deployment发布测试(pv-pvc-deployment-service) 20260810 K8s - 安装部署Kafka、Zookeeper集群教程(支持从K8s外部访问)20260808 k8s-关机及启动脚本工具 【kubeSphere发布ruoyi-pro前端】工具脚本20260731 【k8s】 etcd服务端及客户端版本及快照【定时】备份 20260730 harbor【https启用】及k8节点部证书20260728 kube-flannel.yml k8s集群-安装helm 【kubeShpere】 官网 20260710 kubesphere-KDP 工具脚本【kubeSphere发布ruoyi-pro前端】20260720 HbuilderX 内置终端转为 gitBash 20260720 kubeSphere发布ruoyi-pro后端-用到脚本 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
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