Browse Source

测试chat各接口联通性

luoshi 1 năm trước cách đây
mục cha
commit
447ffb9563

+ 11 - 18
src/main/java/com/qmth/ops/biz/ai/client/ChatApiClient.java

@@ -48,24 +48,17 @@ public abstract class ChatApiClient {
         if (rateLimiter != null && !rateLimiter.acquire()) {
             throw new ChatRateLimitExceeded(config.getSupplier(), config.getModel(), config.getQpm());
         }
-        try {
-            RequestBody body = RequestBody
-                    .create(MediaType.parse("application/json"), mapper.writeValueAsBytes(buildRequest(request)));
-            Credentials credentials = gerCredentials();
-            Request httpRequest = new Request.Builder().url(config.getUrl())
-                    .addHeader(credentials.getName(), credentials.getValue()).post(body).build();
-
-            Response response = client.newCall(httpRequest).execute();
-            byte[] data = response.body() != null ? response.body().bytes() : null;
-            if (response.isSuccessful()) {
-                return buildResult(data, mapper);
-            } else {
-                return handleError(data, response.code(), mapper);
-            }
-        } finally {
-            if (rateLimiter != null) {
-                rateLimiter.release();
-            }
+        RequestBody body = RequestBody
+                .create(MediaType.parse("application/json"), mapper.writeValueAsBytes(buildRequest(request)));
+        Credentials credentials = gerCredentials();
+        Request httpRequest = new Request.Builder().url(config.getUrl())
+                .addHeader(credentials.getName(), credentials.getValue()).post(body).build();
+        Response response = client.newCall(httpRequest).execute();
+        byte[] data = response.body() != null ? response.body().bytes() : null;
+        if (response.isSuccessful()) {
+            return buildResult(data, mapper);
+        } else {
+            return handleError(data, response.code(), mapper);
         }
     }
 

+ 6 - 0
src/main/java/com/qmth/ops/biz/service/InitService.java

@@ -25,6 +25,9 @@ public class InitService implements SqlProvider, CommandLineRunner {
     @Resource
     private UserPermissionService userPermissionService;
 
+    @Resource
+    private LlmClientService llmClientService;
+
     @Override
     public String get() {
         try {
@@ -54,6 +57,9 @@ public class InitService implements SqlProvider, CommandLineRunner {
             }
             log.info("系统管理员权限更新完成");
         }
+
+        llmClientService.init();
+        log.info("LLM Client初始化完成");
     }
 
 }

+ 0 - 2
src/main/java/com/qmth/ops/biz/service/LlmClientService.java

@@ -11,7 +11,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
-import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
 import java.util.HashMap;
 import java.util.List;
@@ -30,7 +29,6 @@ public class LlmClientService {
 
     private Map<Long, ChatApiClient> chatApiClientMap = new HashMap<>();
 
-    @PostConstruct
     public void init() {
         List<LlmSupplier> supplierList = supplierService.list();
         for (LlmSupplier supplier : supplierList) {

+ 8 - 4
src/main/resources/application.properties

@@ -1,12 +1,16 @@
 server.port=8080
 ##spring.resources.static-locations=classpath:/static/,file:/Users/luoshi/develop/project/ops-web/,file:/Users/luoshi/develop/data/
 
-com.qmth.api.global-auth=false
+##com.qmth.api.global-auth=false
 com.qmth.api.http-trace=true
 
-com.qmth.datasource.url=jdbc:mysql://192.168.10.83:3306/ops_db?useUnicode=true&characterEncoding=UTF-8
-com.qmth.datasource.username=scan
-com.qmth.datasource.password=scan
+com.qmth.auth.time-max-ahead=24h
+com.qmth.auth.time-max-delay=24h
+com.qmth.auth.debug-mode=true
+
+com.qmth.datasource.url=jdbc:mysql://localhost:3306/ops_db?useUnicode=true&characterEncoding=UTF-8
+com.qmth.datasource.username=ops
+com.qmth.datasource.password=ops
 
 com.qmth.fss.config=oss://key:secret@solar.oss-api.qmth.com.cn
 com.qmth.fss.server=http://oss-file.qmth.com.cn/solar