Skip to content

Commit

Permalink
fix: 修复npe问题
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyueyi committed Jun 28, 2023
1 parent 6fd553e commit 56902e5
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -39,12 +38,10 @@ public class ChatFacade {
*/
private Supplier<AISourceEnum> aiSourceCache;

@PostConstruct
private void init() {
refreshAiSourceCache(getRecommendAiSource(Collections.emptySet()));
}

public AISourceEnum getRecommendAiSource() {
if (aiSourceCache == null) {
refreshAiSourceCache(Collections.emptySet());
}
AISourceEnum sourceEnum = aiSourceCache.get();
if (sourceEnum == null) {
refreshAiSourceCache(getRecommendAiSource(Collections.emptySet()));
Expand All @@ -70,9 +67,11 @@ private AISourceEnum getRecommendAiSource(Set<AISourceEnum> except) {
AISourceEnum source;
try {
ChatGptIntegration.ChatGptConfig config = SpringUtil.getBean(ChatGptIntegration.ChatGptConfig.class);
if (!except.contains(AISourceEnum.CHAT_GPT_3_5) && !CollectionUtils.isEmpty(config.getConf().get(config.getMain()).getKeys())) {
if (!except.contains(AISourceEnum.CHAT_GPT_3_5) && !CollectionUtils.isEmpty(config.getConf()
.get(config.getMain()).getKeys())) {
source = AISourceEnum.CHAT_GPT_3_5;
} else if (!except.contains(AISourceEnum.XUN_FEI_AI) && StringUtils.isNotBlank(SpringUtil.getBean(XunFeiIntegration.XunFeiConfig.class).getApiKey())) {
} else if (!except.contains(AISourceEnum.XUN_FEI_AI) && StringUtils.isNotBlank(SpringUtil.getBean(XunFeiIntegration.XunFeiConfig.class)
.getApiKey())) {
source = AISourceEnum.XUN_FEI_AI;
} else {
source = AISourceEnum.PAI_AI;
Expand Down

0 comments on commit 56902e5

Please sign in to comment.