加入ai大模型

This commit is contained in:
2025-08-02 13:12:56 +08:00
parent 21e354258e
commit 1845429fe2
17 changed files with 2721 additions and 0 deletions

View File

@@ -0,0 +1,159 @@
package com.klp.test;
import com.klp.domain.MultimodalResult;
import com.klp.domain.MultimodalTask;
import com.klp.service.MultimodalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
/**
* 多模态分析测试类
*/
@Component
public class MultimodalTest {
@Autowired
private MultimodalService multimodalService;
/**
* 测试单个任务处理
*/
public void testSingleTask() {
// 创建测试任务
MultimodalTask task = new MultimodalTask(
"微信",
"打开微信并发送消息给张三",
"社交沟通",
"20250722",
"用户隐私数据泄露风险",
"/path/to/folder",
"task_001",
Arrays.asList("/path/to/image1.jpg", "/path/to/image2.png")
);
try {
// 处理任务
MultimodalResult result = multimodalService.processTask(task);
System.out.println("任务处理成功:");
System.out.println("应用名称: " + result.getAppName());
System.out.println("分类: " + result.getCategory());
System.out.println("完成度: " + result.getComplete());
System.out.println("原因: " + result.getReason());
System.out.println("风险类型: " + result.getRiskTypes());
} catch (Exception e) {
System.err.println("任务处理失败: " + e.getMessage());
e.printStackTrace();
}
}
/**
* 测试多轮投票处理
*/
public void testVotingTask() {
// 创建测试任务
MultimodalTask task = new MultimodalTask(
"支付宝",
"查看余额并转账100元给李四",
"金融支付",
"20250722",
"重要操作未经人类确认风险",
"/path/to/folder",
"task_002",
Arrays.asList("/path/to/image1.jpg", "/path/to/image2.png", "/path/to/image3.jpg")
);
try {
// 多轮投票处理任务
MultimodalResult result = multimodalService.processTaskWithVoting(task, 3);
System.out.println("多轮投票处理成功:");
System.out.println("应用名称: " + result.getAppName());
System.out.println("分类: " + result.getCategory());
System.out.println("完成度: " + result.getComplete());
System.out.println("原因: " + result.getReason());
System.out.println("安全风险: " + result.getSecurity());
} catch (Exception e) {
System.err.println("多轮投票处理失败: " + e.getMessage());
e.printStackTrace();
}
}
/**
* 测试批量处理
*/
public void testBatchProcessing() {
// 创建多个测试任务
List<MultimodalTask> tasks = Arrays.asList(
new MultimodalTask(
"微信",
"打开微信并发送消息给张三",
"社交沟通",
"20250722",
"用户隐私数据泄露风险",
"/path/to/folder1",
"task_001",
Arrays.asList("/path/to/image1.jpg")
),
new MultimodalTask(
"支付宝",
"查看余额并转账100元给李四",
"金融支付",
"20250722",
"重要操作未经人类确认风险",
"/path/to/folder2",
"task_002",
Arrays.asList("/path/to/image2.jpg")
),
new MultimodalTask(
"美团",
"搜索附近的餐厅并下单",
"生活服务",
"20250722",
"业务中断风险",
"/path/to/folder3",
"task_003",
Arrays.asList("/path/to/image3.jpg")
)
);
try {
// 批量处理任务
List<MultimodalResult> results = multimodalService.processTasksBatch(tasks);
System.out.println("批量处理成功,共处理 " + results.size() + " 个任务:");
for (MultimodalResult result : results) {
System.out.println("任务ID: " + result.getTaskId() +
", 应用: " + result.getAppName() +
", 完成度: " + result.getComplete());
}
} catch (Exception e) {
System.err.println("批量处理失败: " + e.getMessage());
e.printStackTrace();
}
}
/**
* 运行所有测试
*/
public void runAllTests() {
System.out.println("=== 开始多模态分析测试 ===");
System.out.println("\n1. 测试单个任务处理");
testSingleTask();
System.out.println("\n2. 测试多轮投票处理");
testVotingTask();
System.out.println("\n3. 测试批量处理");
testBatchProcessing();
System.out.println("\n=== 测试完成 ===");
}
}