From fe8dde8c7384d0826d4b4f13a3fa32b6ff141322 Mon Sep 17 00:00:00 2001 From: Wonder Date: Mon, 13 Oct 2025 18:43:42 +0800 Subject: [PATCH] =?UTF-8?q?=20=F0=9F=94=84Update:=20=E5=BC=95=E5=85=A5=20A?= =?UTF-8?q?I=20=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gitea-webhook/pom.xml | 7 +++++ .../webhook/constant/AIConstant.java | 7 +++++ .../hezhaohui/webhook/service/AIService.java | 30 +++++++++++++++++++ .../webhook/service/AIServiceTest.java | 12 ++++++++ 4 files changed, 56 insertions(+) create mode 100644 gitea-webhook/src/main/java/cn/hezhaohui/webhook/constant/AIConstant.java create mode 100644 gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/AIService.java create mode 100644 gitea-webhook/src/test/java/cn/hezhaohui/webhook/service/AIServiceTest.java diff --git a/gitea-webhook/pom.xml b/gitea-webhook/pom.xml index 3351ff7..bf1bdc1 100644 --- a/gitea-webhook/pom.xml +++ b/gitea-webhook/pom.xml @@ -35,6 +35,13 @@ hutool-http 5.8.27 + + + + cn.hutool + hutool-json + 5.8.27 + \ No newline at end of file diff --git a/gitea-webhook/src/main/java/cn/hezhaohui/webhook/constant/AIConstant.java b/gitea-webhook/src/main/java/cn/hezhaohui/webhook/constant/AIConstant.java new file mode 100644 index 0000000..d9e2d0e --- /dev/null +++ b/gitea-webhook/src/main/java/cn/hezhaohui/webhook/constant/AIConstant.java @@ -0,0 +1,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"; +} diff --git a/gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/AIService.java b/gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/AIService.java new file mode 100644 index 0000000..cae3b95 --- /dev/null +++ b/gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/AIService.java @@ -0,0 +1,30 @@ +package cn.hezhaohui.webhook.service; + +import cn.hezhaohui.webhook.constant.AIConstant; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONUtil; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class AIService { + public String getAIResponse(String prompt) { + Map body = new HashMap<>(); + body.put("model", AIConstant.AI_MODEL); + body.put("messages", List.of(Map.of("role", "user", "content", prompt))); + + String jsonBody = JSONUtil.toJsonStr(body); + + HttpResponse response = HttpRequest.post(AIConstant.AI_URL) + .header("Content-Type", "application/json") + .header("Authorization", "Bearer " + AIConstant.AI_TOKEN) + .body(jsonBody) + .execute(); + return "AI response: " + response.body(); + } +} diff --git a/gitea-webhook/src/test/java/cn/hezhaohui/webhook/service/AIServiceTest.java b/gitea-webhook/src/test/java/cn/hezhaohui/webhook/service/AIServiceTest.java new file mode 100644 index 0000000..d28d6ad --- /dev/null +++ b/gitea-webhook/src/test/java/cn/hezhaohui/webhook/service/AIServiceTest.java @@ -0,0 +1,12 @@ +package cn.hezhaohui.webhook.service; + +import junit.framework.TestCase; +public class AIServiceTest extends TestCase { + + public void testGetAIResponse() { + AIService aiService = new AIService(); + String response = aiService.getAIResponse("你好"); + System.out.println(response); + assertNotNull(response); + } +} \ No newline at end of file