Commit 815058dcf398a1c8647da43f3afe88d2aceb17cd
1 parent
ea8b3b64
添加向量库
Showing
4 changed files
with
85 additions
and
66 deletions
src/main/java/com/xly/exception/TtsExceptionFilter.java
| 1 | -package com.xly.exception; | |
| 2 | - | |
| 3 | -import com.fasterxml.jackson.databind.ObjectMapper; | |
| 4 | -import com.xly.tts.bean.TTSResponseDTO; | |
| 5 | -import jakarta.servlet.*; | |
| 6 | -import jakarta.servlet.http.HttpServletRequest; | |
| 7 | -import jakarta.servlet.http.HttpServletResponse; | |
| 8 | -import lombok.RequiredArgsConstructor; | |
| 9 | -import lombok.extern.slf4j.Slf4j; | |
| 10 | -import org.springframework.core.annotation.Order; | |
| 11 | -import org.springframework.http.HttpStatus; | |
| 12 | -import org.springframework.http.MediaType; | |
| 13 | -import org.springframework.stereotype.Component; | |
| 14 | - | |
| 15 | -import java.io.IOException; | |
| 16 | - | |
| 17 | -@Slf4j | |
| 18 | -@Component | |
| 19 | -@Order(1) | |
| 20 | -@RequiredArgsConstructor | |
| 21 | -public class TtsExceptionFilter implements Filter { | |
| 22 | - | |
| 23 | - private final ObjectMapper objectMapper; | |
| 24 | - | |
| 25 | - @Override | |
| 26 | - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |
| 27 | - throws IOException, ServletException { | |
| 28 | - | |
| 29 | - HttpServletRequest httpRequest = (HttpServletRequest) request; | |
| 30 | - HttpServletResponse httpResponse = (HttpServletResponse) response; | |
| 31 | - | |
| 32 | - // 只处理 TTS 相关接口 | |
| 33 | - if (!httpRequest.getRequestURI().contains("/api/tts/")) { | |
| 34 | - chain.doFilter(request, response); | |
| 35 | - return; | |
| 36 | - } | |
| 37 | - | |
| 38 | - try { | |
| 39 | - chain.doFilter(request, response); | |
| 40 | - } catch (Exception ex) { | |
| 41 | - log.error("TTS接口异常: {}", httpRequest.getRequestURI(), ex); | |
| 42 | - | |
| 43 | - // 清除之前的响应 | |
| 44 | - if (httpResponse.isCommitted()) { | |
| 45 | - return; | |
| 46 | - } | |
| 47 | - | |
| 48 | - httpResponse.reset(); | |
| 49 | - httpResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); | |
| 50 | - httpResponse.setContentType(MediaType.APPLICATION_JSON_VALUE); | |
| 51 | - httpResponse.setCharacterEncoding("UTF-8"); | |
| 52 | - | |
| 53 | - TTSResponseDTO errorResult = TTSResponseDTO.error( | |
| 54 | - HttpStatus.INTERNAL_SERVER_ERROR.value(), | |
| 55 | - "语音合成服务异常: " + ex.getMessage() | |
| 56 | - ); | |
| 57 | - | |
| 58 | - String jsonResponse = objectMapper.writeValueAsString(errorResult); | |
| 59 | - httpResponse.getWriter().write(jsonResponse); | |
| 60 | - httpResponse.getWriter().flush(); | |
| 61 | - } | |
| 62 | - } | |
| 63 | -} | |
| 64 | 1 | \ No newline at end of file |
| 2 | +//package com.xly.exception; | |
| 3 | +// | |
| 4 | +//import com.fasterxml.jackson.databind.ObjectMapper; | |
| 5 | +//import com.xly.tts.bean.TTSResponseDTO; | |
| 6 | +//import jakarta.servlet.*; | |
| 7 | +//import jakarta.servlet.http.HttpServletRequest; | |
| 8 | +//import jakarta.servlet.http.HttpServletResponse; | |
| 9 | +//import lombok.RequiredArgsConstructor; | |
| 10 | +//import lombok.extern.slf4j.Slf4j; | |
| 11 | +//import org.springframework.core.annotation.Order; | |
| 12 | +//import org.springframework.http.HttpStatus; | |
| 13 | +//import org.springframework.http.MediaType; | |
| 14 | +//import org.springframework.stereotype.Component; | |
| 15 | +// | |
| 16 | +//import java.io.IOException; | |
| 17 | +// | |
| 18 | +//@Slf4j | |
| 19 | +//@Component | |
| 20 | +//@Order(1) | |
| 21 | +//@RequiredArgsConstructor | |
| 22 | +//public class TtsExceptionFilter implements Filter { | |
| 23 | +// | |
| 24 | +// private final ObjectMapper objectMapper; | |
| 25 | +// | |
| 26 | +// @Override | |
| 27 | +// public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |
| 28 | +// throws IOException, ServletException { | |
| 29 | +// | |
| 30 | +// HttpServletRequest httpRequest = (HttpServletRequest) request; | |
| 31 | +// HttpServletResponse httpResponse = (HttpServletResponse) response; | |
| 32 | +// | |
| 33 | +// // 只处理 TTS 相关接口 | |
| 34 | +// if (!httpRequest.getRequestURI().contains("/api/tts/")) { | |
| 35 | +// chain.doFilter(request, response); | |
| 36 | +// return; | |
| 37 | +// } | |
| 38 | +// | |
| 39 | +// try { | |
| 40 | +// chain.doFilter(request, response); | |
| 41 | +// } catch (Exception ex) { | |
| 42 | +// log.error("TTS接口异常: {}", httpRequest.getRequestURI(), ex); | |
| 43 | +// | |
| 44 | +// // 清除之前的响应 | |
| 45 | +// if (httpResponse.isCommitted()) { | |
| 46 | +// return; | |
| 47 | +// } | |
| 48 | +// | |
| 49 | +// httpResponse.reset(); | |
| 50 | +// httpResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); | |
| 51 | +// httpResponse.setContentType(MediaType.APPLICATION_JSON_VALUE); | |
| 52 | +// httpResponse.setCharacterEncoding("UTF-8"); | |
| 53 | +// | |
| 54 | +// TTSResponseDTO errorResult = TTSResponseDTO.error( | |
| 55 | +// HttpStatus.INTERNAL_SERVER_ERROR.value(), | |
| 56 | +// "语音合成服务异常: " + ex.getMessage() | |
| 57 | +// ); | |
| 58 | +// | |
| 59 | +// String jsonResponse = objectMapper.writeValueAsString(errorResult); | |
| 60 | +// httpResponse.getWriter().write(jsonResponse); | |
| 61 | +// httpResponse.getWriter().flush(); | |
| 62 | +// } | |
| 63 | +// } | |
| 64 | +//} | |
| 65 | 65 | \ No newline at end of file | ... | ... |
src/main/java/com/xly/ocr/service/OcrService.java
| ... | ... | @@ -19,7 +19,7 @@ public class OcrService { |
| 19 | 19 | private static final List<String> ALLOWED_EXTENSIONS = Arrays.asList( |
| 20 | 20 | ".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".gif" |
| 21 | 21 | ); |
| 22 | - private static final long MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB | |
| 22 | + private static final long MAX_FILE_SIZE = 100 * 1024 * 1024; // 10MB | |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * 从 MultipartFile 中提取文字 | ... | ... |
src/main/java/com/xly/tool/DynamicToolProvider.java
| ... | ... | @@ -909,8 +909,20 @@ public class DynamicToolProvider implements ToolProvider { |
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | private Boolean checkMiss(Map<String,Object> returnMap,ParamRule pd) { |
| 912 | + if(ObjectUtil.isEmpty(returnMap)){ | |
| 913 | + returnMap = new HashMap<>(); | |
| 914 | + } | |
| 912 | 915 | Boolean bBhcs = (ObjectUtil.isEmpty(returnMap.get(pd.getSParam()))); |
| 913 | - Boolean bDbZero = (pd.getSParamValue().startsWith("d") && 0 == Double.valueOf(returnMap.get(pd.getSParam()).toString())); | |
| 916 | + Boolean bDbZero = false; | |
| 917 | + if(pd.getSParamValue().startsWith("d")){ | |
| 918 | + try{ | |
| 919 | + String sParam = pd.getSParam().toString(); | |
| 920 | + Object sParamV = returnMap.get(sParam); | |
| 921 | + bDbZero = (ObjectUtil.isEmpty(sParamV) || 0 ==Double.valueOf(sParamV.toString())); | |
| 922 | + }catch (Exception e){ | |
| 923 | + bDbZero = true; | |
| 924 | + } | |
| 925 | + } | |
| 914 | 926 | return bDbZero || bBhcs || (!returnMap.containsKey(pd.getSParamValue()) || (ObjectUtil.isEmpty(returnMap.get(pd.getSParamValue())))); |
| 915 | 927 | } |
| 916 | 928 | ... | ... |
src/main/resources/application.yml
| ... | ... | @@ -9,7 +9,6 @@ logging: |
| 9 | 9 | org.springframework: warn |
| 10 | 10 | ai.djl: DEBUG |
| 11 | 11 | dev.langchain4j: DEBUG |
| 12 | - | |
| 13 | 12 | server: |
| 14 | 13 | port: 8099 |
| 15 | 14 | servlet: |
| ... | ... | @@ -21,6 +20,14 @@ server: |
| 21 | 20 | enabled: true |
| 22 | 21 | mime-types: audio/mpeg |
| 23 | 22 | spring: |
| 23 | + # 将 multipart | |
| 24 | + servlet: | |
| 25 | + multipart: | |
| 26 | + max-file-size: 100MB | |
| 27 | + max-request-size: 100MB | |
| 28 | +# enabled: true | |
| 29 | +# location: D:/xlyweberp/ai/upload-temp # 可选:指定临时文件目录 | |
| 30 | +# file-size-threshold: 2MB # 可选:超过2MB才写入磁盘 | |
| 24 | 31 | main: |
| 25 | 32 | allow-bean-definition-overriding: true |
| 26 | 33 | application: | ... | ... |