Compare commits
5
Commits
2fca4f38df
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cb2f7fe62 | ||
|
|
afdd50c857 | ||
|
|
ed4000b834 | ||
|
|
90af1d199d | ||
|
|
ea42aa89d9 |
@@ -3,7 +3,7 @@ package cn.hezhaohui.webhook.constant;
|
|||||||
public class AIConstant {
|
public class AIConstant {
|
||||||
public static final String AI_URL = "https://api.siliconflow.cn/v1/chat/completions";
|
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_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 = "【身份】你是一位代码总结专家,你擅长总结用户给出的代码并且做出有见解的回答。" +
|
public static final String AI_SYSTEM_PROMPT = "【身份】你是一位代码总结专家,你擅长总结用户给出的代码并且做出有见解的回答。" +
|
||||||
"【要求】你需要根据用户给出的 commit messages 以及 代码文件的变化,总结出代码的改动内容,并给出有见解的回答。回答结果需要简洁精炼专业,默认情况下不分点描述。对于简单的技术内容,通过概括性的语言描述即可,避免口语化回答。你不需要输出带有 MarkDown 格式的文本,因为用户的终端不支持该选项。在适宜的地方需要使用换行。" +
|
"【要求】你需要根据用户给出的 commit messages 以及 代码文件的变化,总结出代码的改动内容,并给出有见解的回答。回答结果需要简洁精炼专业,默认情况下不分点描述。对于简单的技术内容,通过概括性的语言描述即可,避免口语化回答。你不需要输出带有 MarkDown 格式的文本,因为用户的终端不支持该选项。在适宜的地方需要使用换行。" +
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ public class AIService {
|
|||||||
.header("Authorization", "Bearer " + AIConstant.AI_TOKEN)
|
.header("Authorization", "Bearer " + AIConstant.AI_TOKEN)
|
||||||
.body(jsonBody)
|
.body(jsonBody)
|
||||||
.execute();
|
.execute();
|
||||||
|
if (response.getStatus() != 200) {
|
||||||
|
return AIConstant.DEFAULT_ERROR_RESPONSE;
|
||||||
|
}
|
||||||
JSONObject jsonResponse = JSONUtil.parseObj(response.body());
|
JSONObject jsonResponse = JSONUtil.parseObj(response.body());
|
||||||
return jsonResponse.getJSONArray("choices").getJSONObject(0).getJSONObject("message").getStr("content");
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class FileService {
|
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
|
// repo: http://47.121.181.112:3000/wonder/lark-webhook-sender
|
||||||
// prefix: /raw/branch/main/
|
// prefix: /raw/branch/main/
|
||||||
// raw: gitea-webhook/src/main/java/cn/hezhaohui/webhook/controller/HookController.java
|
// 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) {
|
public String getRawContents(String repo, String raw) {
|
||||||
String url = getRawUrl(repo, raw);
|
String url = getRawUrl(repo, raw);
|
||||||
String fileName = raw.substring(raw.lastIndexOf("/")+1);
|
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);
|
String fileContent = HttpUtil.get(url);
|
||||||
return "[FileName]" + fileName + "\n" + "[FileContent]" + fileContent + "\n";
|
return "[FileName]" + fileName + "\n" + "[FileContent]" + fileContent + "\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ public class HookService {
|
|||||||
|
|
||||||
if (addedFiles.size() + removedFiles.size() + modifiedFiles.size() <= 20) {
|
if (addedFiles.size() + removedFiles.size() + modifiedFiles.size() <= 20) {
|
||||||
String addedFilesContent = fileService.getAllFiles(event.getRepository().getHtml_url(), addedFiles);
|
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 modifiedFilesContent = fileService.getAllFiles(event.getRepository().getHtml_url(), modifiedFiles);
|
||||||
|
|
||||||
String allFilesContentString = "[Added Files]: \n" +
|
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_ID = "cli_a860966d8eb69013";
|
||||||
public static final String APP_SECRET = "srCSYZQDaglgSkLSs5MGrfEsCW4fCQE2";
|
public static final String APP_SECRET = "srCSYZQDaglgSkLSs5MGrfEsCW4fCQE2";
|
||||||
public static final String TEMPATE_ID = "AAqxBOlIDzI20";
|
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";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user