You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB
Java

package com.supervision.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.supervision.model.KgInfo;
import com.supervision.qanything.QanythingService;
import com.supervision.qanything.dto.ChatResult;
import com.supervision.qanything.dto.ResultWrapper;
import com.supervision.service.KGService;
import com.supervision.service.KgInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.security.NoSuchAlgorithmException;
@Slf4j
@Service
@RequiredArgsConstructor
public class KGServiceImpl implements KGService {
@Value("${youdao.qanthing.kbId}")
private String kbId;
private final QanythingService qanythingService;
private final KgInfoService kgInfoService;
@Override
public ChatResult chat(String question) {
Assert.notEmpty(question, "问题不能为空");
try {
ResultWrapper<ChatResult> chat = qanythingService.chat(question, CollUtil.newArrayList(kbId));
if (chat.isSuccess()){
return chat.getResult();
}
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public IPage<KgInfo> hotKG(Page<KgInfo> page) {
return kgInfoService.lambdaQuery().eq(KgInfo::getHotFlag,1).page(page);
}
}