From 55a039fb1f810b090771d84dcfbc2a7e77ac45bb Mon Sep 17 00:00:00 2001 From: jack ning Date: Wed, 16 Jul 2025 16:19:00 +0800 Subject: [PATCH] update modules/core: mod 9 files --- .../controller/SpringAIPromptController.java | 32 +++++++++++++++++-- .../controller/SpringAIToolsController.java | 18 +++++++++++ .../ai/zhipuai/ZhipuaiController.java | 6 ++-- .../rbac/organization/OrganizationEntity.java | 7 +++- .../organization/OrganizationRequest.java | 5 ++- .../organization/OrganizationResponse.java | 5 ++- .../OrganizationRestController.java | 12 ++++++- .../organization/OrganizationRestService.java | 16 ++++++++-- 8 files changed, 89 insertions(+), 12 deletions(-) diff --git a/modules/ai/src/main/java/com/bytedesk/ai/springai/controller/SpringAIPromptController.java b/modules/ai/src/main/java/com/bytedesk/ai/springai/controller/SpringAIPromptController.java index 7d5898f25e..39a354b06b 100644 --- a/modules/ai/src/main/java/com/bytedesk/ai/springai/controller/SpringAIPromptController.java +++ b/modules/ai/src/main/java/com/bytedesk/ai/springai/controller/SpringAIPromptController.java @@ -2,7 +2,7 @@ * @Author: jackning 270580156@qq.com * @Date: 2025-02-20 10:42:30 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-05-07 11:36:33 + * @LastEditTime: 2025-07-16 16:00:58 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.bytedesk.ai.utils.output.ActorsFilms; +import com.bytedesk.core.config.properties.BytedeskProperties; import com.bytedesk.core.utils.JsonResult; import java.util.HashMap; @@ -64,9 +65,10 @@ import lombok.extern.slf4j.Slf4j; @RestController @RequestMapping("/springai/prompt") @RequiredArgsConstructor -@ConditionalOnProperty(prefix = "spring.ai.ollama.chat.enabled", name = "enabled", havingValue = "true", matchIfMissing = false) +@ConditionalOnProperty(prefix = "spring.ai.ollama.chat", name = "enabled", havingValue = "true", matchIfMissing = false) public class SpringAIPromptController { + private final BytedeskProperties bytedeskProperties; private final ChatClient bytedeskOllamaChatClient; @Qualifier("elasticsearchVectorStore") @@ -95,6 +97,11 @@ public class SpringAIPromptController { public ResponseEntity> templating( @RequestParam(value = "adjective", defaultValue = "funny") String adjective, @RequestParam(value = "topic", defaultValue = "cows") String topic) { + + if (!bytedeskProperties.getDebug()) { + return ResponseEntity.ok(JsonResult.error("Service is not available")); + } + // 使用prompt模板 PromptTemplate promptTemplate = new PromptTemplate(jokeResource); Prompt prompt = promptTemplate.create(Map.of("adjective", adjective, "topic", topic)); @@ -113,6 +120,10 @@ public class SpringAIPromptController { @RequestParam(value = "name", defaultValue = "Bob") String name, @RequestParam(value = "voice", defaultValue = "pirate") String voice) { + if (!bytedeskProperties.getDebug()) { + return ResponseEntity.ok(JsonResult.error("Service is not available")); + } + // 使用prompt模板 // name, The name of the AI assistant. The default value is Bob // voice, The style of voice that the AI assistant will use to reply. The @@ -136,6 +147,10 @@ public class SpringAIPromptController { @RequestParam(value = "message", defaultValue = "Which athletes won the mixed doubles gold medal in curling at the 2022 Winter Olympics?'") String message, @RequestParam(value = "stuff", defaultValue = "false") boolean stuff) { + if (!bytedeskProperties.getDebug()) { + return ResponseEntity.ok(JsonResult.error("Service is not available")); + } + // 使用prompt模板 PromptTemplate promptTemplate = new PromptTemplate(qaPromptResource); Map map = new HashMap<>(); @@ -163,6 +178,11 @@ public class SpringAIPromptController { @GetMapping("/rag") public ResponseEntity> rag( @RequestParam(value = "message", defaultValue = "What is the most popular bike brand?") String message) { + + if (!bytedeskProperties.getDebug()) { + return ResponseEntity.ok(JsonResult.error("Service is not available")); + } + // Step 1 - Load JSON document as Documents log.info("Loading JSON as Documents"); @@ -204,6 +224,10 @@ public class SpringAIPromptController { public ResponseEntity> generate( @RequestParam(value = "actor", defaultValue = "Jeff Bridges") String actor) { + if (!bytedeskProperties.getDebug()) { + return ResponseEntity.ok(JsonResult.error("Service is not available")); + } + // using the low-level ChatModel API directly: var outputParser = new BeanOutputConverter<>(ActorsFilms.class); @@ -244,6 +268,10 @@ public class SpringAIPromptController { @GetMapping("/structured") public ResponseEntity> structured( @RequestParam(value = "message", defaultValue = "Tell me about the actor Jeff Bridges") String message) { + + if (!bytedeskProperties.getDebug()) { + return ResponseEntity.ok(JsonResult.error("Service is not available")); + } StructuredOutputConverter outputConverter = new BeanOutputConverter<>(ActorsFilms.class); String userInputTemplate = """ diff --git a/modules/ai/src/main/java/com/bytedesk/ai/springai/controller/SpringAIToolsController.java b/modules/ai/src/main/java/com/bytedesk/ai/springai/controller/SpringAIToolsController.java index 967a4a7070..53b34bd1b1 100644 --- a/modules/ai/src/main/java/com/bytedesk/ai/springai/controller/SpringAIToolsController.java +++ b/modules/ai/src/main/java/com/bytedesk/ai/springai/controller/SpringAIToolsController.java @@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.RestController; import com.bytedesk.ai.utils.tools.DateTimeTools; import com.bytedesk.ai.utils.tools.WeatherRequest; import com.bytedesk.ai.utils.tools.WeatherService; +import com.bytedesk.core.config.properties.BytedeskProperties; import com.bytedesk.core.utils.BdDateUtils; import com.bytedesk.core.utils.JsonResult; @@ -51,6 +52,7 @@ import lombok.extern.slf4j.Slf4j; @ConditionalOnProperty(prefix = "spring.ai.zhipuai.chat", name = "enabled", havingValue = "true", matchIfMissing = false) public class SpringAIToolsController { + private final BytedeskProperties bytedeskProperties; // private final ChatClient defaultChatClient; @Qualifier("bytedeskZhipuaiChatClient") private final ChatClient bytedeskZhipuaiChatClient; @@ -69,6 +71,10 @@ public class SpringAIToolsController { public ResponseEntity> time( @RequestParam(value = "message", defaultValue = "What day is tomorrow?") String message) { + if (!bytedeskProperties.getDebug()) { + return ResponseEntity.ok(JsonResult.error("Service is not available")); + } + String response = bytedeskZhipuaiChatClient .prompt(message) .tools(new DateTimeTools()) @@ -92,6 +98,10 @@ public class SpringAIToolsController { public ResponseEntity> alarm( @RequestParam(value = "message", defaultValue = "Can you set an alarm 10 minutes from now?") String message) { + if (!bytedeskProperties.getDebug()) { + return ResponseEntity.ok(JsonResult.error("Service is not available")); + } + String response = bytedeskZhipuaiChatClient .prompt(message) .tools(new DateTimeTools()) @@ -108,6 +118,10 @@ public class SpringAIToolsController { public ResponseEntity> methodToolCallback( @RequestParam(value = "message", defaultValue = "What is the current date and time?") String message) { + if (!bytedeskProperties.getDebug()) { + return ResponseEntity.ok(JsonResult.error("Service is not available")); + } + Method method = ReflectionUtils.findMethod(DateTimeTools.class, "getCurrentDateTimeMethodToolCallback"); ToolCallback toolCallback = MethodToolCallback.builder() .toolDefinition(ToolDefinition.builder() @@ -135,6 +149,10 @@ public class SpringAIToolsController { public ResponseEntity> weather( @RequestParam(value = "message", defaultValue = "What is the weather in Beijing?") String message) { + if (!bytedeskProperties.getDebug()) { + return ResponseEntity.ok(JsonResult.error("Service is not available")); + } + ToolCallback toolCallback = FunctionToolCallback .builder("currentWeather", new WeatherService()) .description("Get the weather in location") diff --git a/modules/ai/src/main/java/com/bytedesk/ai/zhipuai/ZhipuaiController.java b/modules/ai/src/main/java/com/bytedesk/ai/zhipuai/ZhipuaiController.java index eb9a67278b..2026580336 100644 --- a/modules/ai/src/main/java/com/bytedesk/ai/zhipuai/ZhipuaiController.java +++ b/modules/ai/src/main/java/com/bytedesk/ai/zhipuai/ZhipuaiController.java @@ -2,7 +2,7 @@ * @Author: jackning 270580156@qq.com * @Date: 2025-02-19 09:39:15 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-07-16 13:48:48 + * @LastEditTime: 2025-07-16 15:45:45 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -438,9 +438,9 @@ public class ZhipuaiController { /** * 语音合成 - * POST http://127.0.0.1:9003/zhipuai/voice + * POST http://127.0.0.1:9003/zhipuai/speech */ - @PostMapping("/voice") + @PostMapping("/speech") public ResponseEntity> generateSpeech(@RequestBody Map request) { if (!bytedeskProperties.getDebug()) { return ResponseEntity.ok(JsonResult.error("Zhipuai service is not available")); diff --git a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationEntity.java b/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationEntity.java index 01d4a673be..8ac3e11440 100644 --- a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationEntity.java +++ b/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationEntity.java @@ -2,7 +2,7 @@ * @Author: jackning 270580156@qq.com * @Date: 2024-01-29 16:20:17 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-07-02 14:07:11 + * @LastEditTime: 2025-07-16 16:13:40 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -109,6 +109,11 @@ public class OrganizationEntity extends BaseEntityNoOrg { // 会员截止日期 private Date vipExpireDate; + // 是否启用,状态:启用/禁用 + @Builder.Default + @Column(name = "is_enabled") + private Boolean enabled = true; + @ManyToOne(fetch = FetchType.LAZY) @JsonBackReference diff --git a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRequest.java b/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRequest.java index 5faf8d1013..9ac9b75cf3 100644 --- a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRequest.java +++ b/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRequest.java @@ -2,7 +2,7 @@ * @Author: jackning 270580156@qq.com * @Date: 2024-02-06 16:02:35 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-07-02 14:07:52 + * @LastEditTime: 2025-07-16 16:14:30 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -70,4 +70,7 @@ public class OrganizationRequest extends BaseRequest { // 会员截止日期 private Date vipExpireDate; + // 是否启用,状态:启用/禁用 + private Boolean enabled; + } diff --git a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationResponse.java b/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationResponse.java index e5572475ef..f918bc36bc 100644 --- a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationResponse.java +++ b/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationResponse.java @@ -2,7 +2,7 @@ * @Author: jackning 270580156@qq.com * @Date: 2024-02-01 21:20:57 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-07-02 14:06:40 + * @LastEditTime: 2025-07-16 16:14:36 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -72,4 +72,7 @@ public class OrganizationResponse extends BaseResponse { // 会员截止日期 private Date vipExpireDate; + // 是否启用,状态:启用/禁用 + private Boolean enabled; + } diff --git a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRestController.java b/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRestController.java index b8d8d78385..ec6795fe64 100644 --- a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRestController.java +++ b/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRestController.java @@ -2,7 +2,7 @@ * @Author: jackning 270580156@qq.com * @Date: 2024-01-29 16:20:17 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-07-15 16:15:07 + * @LastEditTime: 2025-07-16 16:17:08 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -77,6 +77,16 @@ public class OrganizationRestController extends BaseRestController createByAdmin(@RequestBody OrganizationRequest request) { + // + OrganizationResponse response = organizationRestService.createByAdmin(request); + // + return ResponseEntity.ok(JsonResult.success(response)); + } + @ActionAnnotation(title = "组织", action = "更新", description = "organization update") @PostMapping("/update") public ResponseEntity update(@RequestBody OrganizationRequest request) { diff --git a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRestService.java b/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRestService.java index c45d626aea..c3b17c7c5f 100644 --- a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRestService.java +++ b/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationRestService.java @@ -2,7 +2,7 @@ * @Author: jackning 270580156@qq.com * @Date: 2024-01-29 16:20:17 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-06-09 10:33:00 + * @LastEditTime: 2025-07-16 16:18:29 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -42,8 +42,6 @@ public class OrganizationRestService extends BaseRestService