|
@@ -15,6 +15,8 @@ import com.qmth.ops.biz.service.LlmClientService;
|
|
import com.qmth.ops.biz.service.LlmOrgConfigService;
|
|
import com.qmth.ops.biz.service.LlmOrgConfigService;
|
|
import com.qmth.ops.biz.service.LlmPromptTemplateService;
|
|
import com.qmth.ops.biz.service.LlmPromptTemplateService;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -24,6 +26,8 @@ import javax.annotation.Resource;
|
|
@Aac(auth = true, signType = SignatureType.SECRET)
|
|
@Aac(auth = true, signType = SignatureType.SECRET)
|
|
public class LlmController {
|
|
public class LlmController {
|
|
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(LlmController.class);
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private LlmOrgConfigService llmOrgConfigService;
|
|
private LlmOrgConfigService llmOrgConfigService;
|
|
|
|
|
|
@@ -131,6 +135,22 @@ public class LlmController {
|
|
return balance;
|
|
return balance;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @PostMapping(AiConstants.LLM_BALANCE_CONSUME_PATH)
|
|
|
|
+ public LlmAppBalance consumeBalance(@RequestAttribute AccessOrg accessOrg,
|
|
|
|
+ @RequestHeader(AiConstants.LLM_APP_TYPE) LlmAppType type) {
|
|
|
|
+ LlmAppBalance balance = new LlmAppBalance();
|
|
|
|
+ LlmOrgConfig config = llmOrgConfigService.findByOrgAndAppType(accessOrg.getOrg().getId(), type);
|
|
|
|
+ if (config != null && config.getLeftCount() > 0) {
|
|
|
|
+ log.warn("Consume balance for org:{} appType:{} permitCount:{} leftCount:{}",
|
|
|
|
+ accessOrg.getOrg().getCode(), type, config.getPermitCount(), config.getLeftCount());
|
|
|
|
+ llmOrgConfigService.consume(config);
|
|
|
|
+
|
|
|
|
+ balance.setPermitCount(config.getPermitCount());
|
|
|
|
+ balance.setLeftCount(config.getLeftCount() - 1);
|
|
|
|
+ }
|
|
|
|
+ return balance;
|
|
|
|
+ }
|
|
|
|
+
|
|
@PostMapping(AiConstants.LLM_PROMPT_TEMPLATE_PATH)
|
|
@PostMapping(AiConstants.LLM_PROMPT_TEMPLATE_PATH)
|
|
public PromptTemplate getPromptTemplate(@RequestAttribute AccessOrg accessOrg,
|
|
public PromptTemplate getPromptTemplate(@RequestAttribute AccessOrg accessOrg,
|
|
@RequestHeader(AiConstants.LLM_APP_TYPE) LlmAppType type) {
|
|
@RequestHeader(AiConstants.LLM_APP_TYPE) LlmAppType type) {
|