Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.ai.dataagent.config;

import com.alibaba.cloud.ai.dataagent.service.cache.ResultCacheService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CacheConfig {

@Bean
public ResultCacheService resultCacheService() {
return new ResultCacheService();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class SqlExecutor {

public static final Integer RESULT_SET_LIMIT = 1000;
public static final Integer RESULT_SET_LIMIT = 1000 * 10;

public static final Integer STATEMENT_TIMEOUT = 30;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2024-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.ai.dataagent.service.cache;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

// 新增 ResultCacheService 类
@Service
public class ResultCacheService {

// 设置最大缓存大小和过期策略(例如,写入后10分钟过期)
Cache<String, String> cache = CacheBuilder.newBuilder()
.maximumSize(100) // 设置最大缓存大小(仅为示例)
.expireAfterWrite(30, TimeUnit.MINUTES) // 设置过期时间
.build();

/**
* 存储执行结果并返回摘要码
*/
public String storeResult(String key, String result) {
String cacheKey = generateCacheKey(key);
cache.put(cacheKey, result);
return cacheKey;
}

/**
* 根据摘要码获取完整结果
*/
public String getResult(String cacheKey) {
return cache.getIfPresent(cacheKey);
}

public boolean exists(String cacheKey) {
return cache.getIfPresent(cacheKey) != null;
}

private String generateCacheKey(String key) {
return "result_" + System.currentTimeMillis() + "_" + UUID.randomUUID().toString().substring(0, 10);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public interface LlmService {

Flux<ChatResponse> callUser(String user);

Flux<ChatResponse> callUserWithTools(String user, Object... tools);

@Deprecated
default String blockToString(Flux<ChatResponse> responseFlux) {
return toStringFlux(responseFlux).collect(StringBuilder::new, StringBuilder::append)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ public Flux<ChatResponse> callUser(String user) {
return Mono.fromCallable(() -> registry.getChatClient().prompt().user(user).call().chatResponse()).flux();
}

@Override
public Flux<ChatResponse> callUserWithTools(String user, Object... tools) {
return Mono.fromCallable(() -> registry.getChatClient().prompt().user(user).tools(tools).call().chatResponse())
.flux();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ public Flux<ChatResponse> callUser(String user) {
return registry.getChatClient().prompt().user(user).stream().chatResponse();
}

@Override
public Flux<ChatResponse> callUserWithTools(String user, Object... tools) {
return registry.getChatClient()
.prompt()
.user(user)
.tools(tools) // 注册工具
.stream()
.chatResponse();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2024-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.ai.dataagent.service.tool;

import com.alibaba.cloud.ai.dataagent.service.cache.ResultCacheService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class CacheAccessTool {

private final ResultCacheService resultCacheService;

public CacheAccessTool(ResultCacheService resultCacheService) {
this.resultCacheService = resultCacheService;
}

/**
* 工具方法:根据摘要码获取完整数据
*/
@Tool(name = "getFullData", description = "根据摘要码获取完整数据")
public String getFullData(@ToolParam(description = "摘要码") String cacheKey) {
if (StringUtils.isNotBlank(cacheKey) && resultCacheService.exists(cacheKey)) {
String fullData = resultCacheService.getResult(cacheKey);
log.info("获取完整数据成功: {}", fullData);
return fullData;
}
else {
return "摘要码不存在或已过期";
}
}

/**
* 工具方法:批量获取多个摘要码的数据
*/
public Map<String, String> getMultipleData(List<String> cacheKeys) {
Map<String, String> results = new HashMap<>();
for (String key : cacheKeys) {
results.put(key, getFullData(key));
}
return results;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,41 @@ public ReportTemplateUtil(DataAgentProperties dataAgentProperties) {
border-radius: 8px;
}

/* 8. 表格样式 */
table {
width: 100%;
border-collapse: collapse;
margin: 1.5rem 0;
background-color: #ffffff;
border-radius: 0.5rem;
overflow: hidden;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

th, td {
padding: 0.75rem 1rem;
text-align: left;
border: 1px solid #e5e7eb;
}

th {
background-color: #f9fafb;
font-weight: 600;
color: #374151;
}

td {
border-top: 1px solid #e5e7eb;
}

tr:nth-child(even) {
background-color: #f9fafb;
}

tr:hover {
background-color: #f3f4f6;
}

/* --- 样式结束 --- */
</style>
</head>
Expand Down
Loading
Loading