feat: 优化图片描述可重复生成
This commit is contained in:
@@ -31,8 +31,8 @@ public class ChatClientFactory {
|
|||||||
.defaultOptions(
|
.defaultOptions(
|
||||||
OpenAiChatOptions.builder()
|
OpenAiChatOptions.builder()
|
||||||
// .model("deepseek-ai/DeepSeek-R1")
|
// .model("deepseek-ai/DeepSeek-R1")
|
||||||
.model("Qwen/Qwen3-8B")
|
// .model("Qwen/Qwen3-8B")
|
||||||
// .model("Qwen/Qwen3-32B")
|
.model("Qwen/Qwen3-32B")
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
@@ -46,17 +46,17 @@ public class ChatClientFactory {
|
|||||||
OpenAiChatModel.builder()
|
OpenAiChatModel.builder()
|
||||||
.openAiApi(
|
.openAiApi(
|
||||||
OpenAiApi.builder()
|
OpenAiApi.builder()
|
||||||
.baseUrl(ZHIPU_URL)
|
// .baseUrl(ZHIPU_URL)
|
||||||
.apiKey(ZHIPU_API_KEY)
|
// .apiKey(ZHIPU_API_KEY)
|
||||||
.completionsPath("/v4/chat/completions")
|
// .completionsPath("/v4/chat/completions")
|
||||||
// .baseUrl(SILICONFLOW_URL)
|
.baseUrl(SILICONFLOW_URL)
|
||||||
// .apiKey(SILICONFLOW_API_KEY)
|
.apiKey(SILICONFLOW_API_KEY)
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.defaultOptions(
|
.defaultOptions(
|
||||||
OpenAiChatOptions.builder()
|
OpenAiChatOptions.builder()
|
||||||
.model("glm-4v-flash")
|
// .model("glm-4v-flash")
|
||||||
// .model("Qwen/Qwen2.5-VL-72B-Instruct")
|
.model("Qwen/Qwen2.5-VL-72B-Instruct")
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.json.JSONArray;
|
import cn.hutool.json.JSONArray;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
@@ -9,6 +10,7 @@ import cn.hutool.json.JSONUtil;
|
|||||||
import cn.hutool.poi.excel.ExcelUtil;
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
import cn.hutool.poi.excel.ExcelWriter;
|
import cn.hutool.poi.excel.ExcelWriter;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -30,14 +32,14 @@ import org.springframework.util.MimeTypeUtils;
|
|||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class PrecariatApplication implements ApplicationRunner {
|
public class PrecariatApplication implements ApplicationRunner {
|
||||||
private final List<FunctionInformation> informationList = List.of(
|
private final List<FunctionInformation> informationList = List.of(
|
||||||
// new FunctionInformation("数据中心-数据集管理", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/数据中心/数据集管理"),
|
// new FunctionInformation("数据中心-数据集管理", "C:\\Users\\lanyuanxiaoyao\\Desktop\\星海AI中台\\数据中心\\数据集管理")
|
||||||
// new FunctionInformation("数据中心-数据网盘", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/数据中心/数据网盘"),
|
// new FunctionInformation("数据中心-数据网盘", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/数据中心/数据网盘"),
|
||||||
// new FunctionInformation("数据中心-数据审批", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/数据中心/数据审批")
|
// new FunctionInformation("数据中心-数据审批", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/数据中心/数据审批")
|
||||||
new FunctionInformation("标注中心-标签模板", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/标注中心/标签模板"),
|
// new FunctionInformation("标注中心-标签模板", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/标注中心/标签模板"),
|
||||||
new FunctionInformation("标注中心-我的任务", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/标注中心/我的任务"),
|
// new FunctionInformation("标注中心-我的任务", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/标注中心/我的任务"),
|
||||||
new FunctionInformation("标注中心-标注项目", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/标注中心/标注项目"),
|
new FunctionInformation("标注中心-标注项目", "C:\\Users\\lanyuanxiaoyao\\SynologyDrive\\document\\工作\\202506 标注中心\\星海AI中台功能截图\\标注中心\\标注项目")
|
||||||
new FunctionInformation("标注中心-标注场景", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/标注中心/标注场景"),
|
// new FunctionInformation("标注中心-标注场景", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/标注中心/标注场景"),
|
||||||
new FunctionInformation("标注中心-标注总览", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/标注中心/标注总览")
|
// new FunctionInformation("标注中心-标注总览", "/Users/lanyuanxiaoyao/Pictures/星海AI中台/标注中心/标注总览")
|
||||||
);
|
);
|
||||||
@Resource
|
@Resource
|
||||||
private ChatClient chatClient;
|
private ChatClient chatClient;
|
||||||
@@ -81,7 +83,6 @@ public class PrecariatApplication implements ApplicationRunner {
|
|||||||
避免列举具体数据行内容。
|
避免列举具体数据行内容。
|
||||||
明确指出行末尾或行内是否存在可见的操作元素(如图标按钮、文字链接按钮),并描述其视觉特征(如:每行末尾有“编辑”图标按钮和“删除”文字链接)。
|
明确指出行末尾或行内是否存在可见的操作元素(如图标按钮、文字链接按钮),并描述其视觉特征(如:每行末尾有“编辑”图标按钮和“删除”文字链接)。
|
||||||
交互元素: 描述所有可见按钮、输入框、下拉选择框、单选框、复选框、选项卡等的文字标签和视觉状态(如:激活/未激活、选中/未选中)。
|
交互元素: 描述所有可见按钮、输入框、下拉选择框、单选框、复选框、选项卡等的文字标签和视觉状态(如:激活/未激活、选中/未选中)。
|
||||||
视觉元素: 描述图标(注明其旁边的文字或位置)、分割线、背景色块、图片占位符等及其位置。
|
|
||||||
|
|
||||||
3.禁止事项 (强化):
|
3.禁止事项 (强化):
|
||||||
禁止遗漏: 确保扫描并描述了页面的所有可见区域和元素。
|
禁止遗漏: 确保扫描并描述了页面的所有可见区域和元素。
|
||||||
@@ -115,26 +116,50 @@ public class PrecariatApplication implements ApplicationRunner {
|
|||||||
.content();
|
.content();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void generateExplain(FunctionInformation information, Boolean overwrite) {
|
||||||
|
FileUtil.listFileNames(information.getImagesPath())
|
||||||
|
.stream()
|
||||||
|
.filter(name -> StrUtil.equals(FileUtil.extName(name), "png"))
|
||||||
|
.map(name -> FileUtil.file(information.getImagesPath(), name))
|
||||||
|
.map(FileUtil::getAbsolutePath)
|
||||||
|
.forEach(imagePath -> {
|
||||||
|
log.info("explain: {}", imagePath);
|
||||||
|
String explainTextPath = StrUtil.format(
|
||||||
|
"{}/{}.txt",
|
||||||
|
FileUtil.getParent(imagePath, 1),
|
||||||
|
FileUtil.getName(imagePath)
|
||||||
|
);
|
||||||
|
if (!overwrite && FileUtil.exist(explainTextPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String description = describeScreenshoot(imagePath);
|
||||||
|
FileUtil.writeBytes(
|
||||||
|
description.getBytes(StandardCharsets.UTF_8),
|
||||||
|
explainTextPath
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) {
|
public void run(ApplicationArguments args) {
|
||||||
List<OutputInformation> lines = new ArrayList<>();
|
List<OutputInformation> lines = new ArrayList<>();
|
||||||
for (FunctionInformation information : informationList) {
|
for (FunctionInformation information : informationList) {
|
||||||
|
generateExplain(information, false);
|
||||||
List<String> descriptions = FileUtil.listFileNames(information.getImagesPath())
|
List<String> descriptions = FileUtil.listFileNames(information.getImagesPath())
|
||||||
.parallelStream()
|
.stream()
|
||||||
.filter(name -> StrUtil.equals(FileUtil.extName(name), "png"))
|
.filter(name -> StrUtil.equals(FileUtil.extName(name), "txt"))
|
||||||
.map(name -> FileUtil.file(information.getImagesPath(), name))
|
.map(name -> FileUtil.file(information.getImagesPath(), name))
|
||||||
.map(FileUtil::getAbsolutePath)
|
.map(FileUtil::getAbsolutePath)
|
||||||
.map(imagePath -> {
|
.map(imagePath -> FileUtil.readString(imagePath, StandardCharsets.UTF_8))
|
||||||
String description = describeScreenshoot(imagePath);
|
|
||||||
log.info("{}\n{}", imagePath, description);
|
|
||||||
return description;
|
|
||||||
})
|
|
||||||
.toList();
|
.toList();
|
||||||
|
if (ObjectUtil.isEmpty(descriptions)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
String response = chatClient.prompt(StrUtil.format(
|
String response = chatClient.prompt(StrUtil.format(
|
||||||
// language=TEXT
|
// language=TEXT
|
||||||
"""
|
"""
|
||||||
你将被提供某个管理系统关于“{}”功能的所有相关网页内容描述。
|
你将被提供某个管理系统关于“{}”功能的所有相关网页内容描述。
|
||||||
这些描述包含页面元素、功能名称、以及同一页面在不同操作(如点击按钮、选择下拉框)后的状态变化。请仔细分析,合并描述中相同的页面内容和功能。
|
这些描述包含页面元素、功能名称、以及同一页面在不同操作(如点击按钮、选择下拉框)后的状态变化,其中部分功能会有共用的页面(如新增弹框、删除弹框等),请仔细分析,合并描述中相同的页面内容和功能。
|
||||||
|
|
||||||
1.功能列表分析要求
|
1.功能列表分析要求
|
||||||
核心目标:从提供的网页描述中,详尽识别并抽象出所有业务逻辑功能。
|
核心目标:从提供的网页描述中,详尽识别并抽象出所有业务逻辑功能。
|
||||||
@@ -177,7 +202,7 @@ public class PrecariatApplication implements ApplicationRunner {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try (ExcelWriter writer = ExcelUtil.getWriter(StrUtil.format("/Users/lanyuanxiaoyao/Project/Precariat/{}.xlsx", DateUtil.current()))) {
|
try (ExcelWriter writer = ExcelUtil.getWriter(StrUtil.format("{}.xlsx", DateUtil.current()))) {
|
||||||
writer.addHeaderAlias("group", "一级功能");
|
writer.addHeaderAlias("group", "一级功能");
|
||||||
writer.addHeaderAlias("name", "二级功能");
|
writer.addHeaderAlias("name", "二级功能");
|
||||||
writer.addHeaderAlias("subName", "三级功能");
|
writer.addHeaderAlias("subName", "三级功能");
|
||||||
|
|||||||
Reference in New Issue
Block a user