Compare commits

...
5 Commits
Author SHA1 Message Date
wonder 7cb2f7fe62 🔄Update: 更新AI模型版本 2025-10-15 14:59:20 +08:00
wonder afdd50c857 🔄Update: 消息卡片新版本 2025-10-15 14:58:37 +08:00
wonder ed4000b834 🐛Fix: 修复已删除文件逻辑 2025-10-15 14:55:10 +08:00
wonder 90af1d199d 🐛Fix: 排除部分文件读取异常 2025-10-13 19:49:57 +08:00
wonder ea42aa89d9 🐛Fix: 增加 AI 返回错误时的特判 2025-10-13 19:44:21 +08:00
5 changed files with 24 additions and 4 deletions
@@ -3,7 +3,7 @@ package cn.hezhaohui.webhook.constant;
public class AIConstant {
public static final String AI_URL = "https://api.siliconflow.cn/v1/chat/completions";
public static final String AI_TOKEN = "sk-htzofywujywqlpwdddcrwxuotefavvqnibrrhvrbdnbiilkw";
public static final String AI_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct";
public static final String AI_MODEL = "Qwen/Qwen3-Coder-30B-A3B-Instruct";
public static final String AI_SYSTEM_PROMPT = "【身份】你是一位代码总结专家,你擅长总结用户给出的代码并且做出有见解的回答。" +
"【要求】你需要根据用户给出的 commit messages 以及 代码文件的变化,总结出代码的改动内容,并给出有见解的回答。回答结果需要简洁精炼专业,默认情况下不分点描述。对于简单的技术内容,通过概括性的语言描述即可,避免口语化回答。你不需要输出带有 MarkDown 格式的文本,因为用户的终端不支持该选项。在适宜的地方需要使用换行。" +
@@ -26,7 +26,9 @@ public class AIService {
.header("Authorization", "Bearer " + AIConstant.AI_TOKEN)
.body(jsonBody)
.execute();
if (response.getStatus() != 200) {
return AIConstant.DEFAULT_ERROR_RESPONSE;
}
JSONObject jsonResponse = JSONUtil.parseObj(response.body());
return jsonResponse.getJSONArray("choices").getJSONObject(0).getJSONObject("message").getStr("content");
}
@@ -4,9 +4,19 @@ import cn.hutool.http.HttpUtil;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Set;
@Service
public class FileService {
private static final Set<String> UNSUPPORTED_FILE_TYPES = Set.of(
".jpg", ".jpeg", ".png", ".gif", ".bmp", ".ico", // 图片
".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", // 文档
".zip", ".rar", ".7z", ".tar", ".gz", // 压缩文件
".exe", ".dll", ".so", ".class", // 可执行文件
".jar", ".war", ".ear", // Java归档
".gitignore", ".gitattributes", ".gitmodules" // Git配置文件
);
// repo: http://47.121.181.112:3000/wonder/lark-webhook-sender
// prefix: /raw/branch/main/
// raw: gitea-webhook/src/main/java/cn/hezhaohui/webhook/controller/HookController.java
@@ -19,6 +29,13 @@ public class FileService {
public String getRawContents(String repo, String raw) {
String url = getRawUrl(repo, raw);
String fileName = raw.substring(raw.lastIndexOf("/")+1);
// 检查文件拓展名
String fileExtension = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
if (UNSUPPORTED_FILE_TYPES.contains(fileExtension)) {
return "[FileName]" + fileName + "\n[FileContent]*不支持显示的文件类型,请忽略\n";
}
String fileContent = HttpUtil.get(url);
return "[FileName]" + fileName + "\n" + "[FileContent]" + fileContent + "\n";
}
@@ -50,7 +50,8 @@ public class HookService {
if (addedFiles.size() + removedFiles.size() + modifiedFiles.size() <= 20) {
String addedFilesContent = fileService.getAllFiles(event.getRepository().getHtml_url(), addedFiles);
String removedFilesContent = fileService.getAllFiles(event.getRepository().getHtml_url(), removedFiles);
// 对于已被删除的文件,访问不到对应文件的url,只需要返回文件名即可
String removedFilesContent = removedFiles.toString();
String modifiedFilesContent = fileService.getAllFiles(event.getRepository().getHtml_url(), modifiedFiles);
String allFilesContentString = "[Added Files]: \n" +
@@ -4,5 +4,5 @@ public class AppConstant {
public static final String APP_ID = "cli_a860966d8eb69013";
public static final String APP_SECRET = "srCSYZQDaglgSkLSs5MGrfEsCW4fCQE2";
public static final String TEMPATE_ID = "AAqxBOlIDzI20";
public static final String TEMPLATE_VERSION = "1.0.1";
public static final String TEMPLATE_VERSION = "1.0.2";
}