更改为构造注入并完善方法注释
This commit is contained in:
@@ -36,7 +36,7 @@ import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
import org.springframework.ai.vectorstore.filter.FilterExpressionBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -53,10 +53,12 @@ import java.util.Set;
|
||||
@Service
|
||||
public class ArticleVectorStoreImpl implements ArticleVectorStore {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final VectorStore vectorStore;
|
||||
|
||||
@Autowired(required = false)
|
||||
private VectorStore vectorStore;
|
||||
public ArticleVectorStoreImpl(ObjectProvider<VectorStore> vectorStore) {
|
||||
this.vectorStore = vectorStore.getIfAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存文章到向量库
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.ai.converter.BeanOutputConverter;
|
||||
import org.springframework.ai.converter.MapOutputConverter;
|
||||
import org.springframework.ai.vectorstore.SearchRequest;
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -56,14 +56,20 @@ public class CmsAiChatService extends BaseService {
|
||||
private static final String[] USER_MESSAGE_SEARCH = new String[]{"{", "}"};
|
||||
private static final String[] USER_MESSAGE_REPLACE = new String[]{"\\{", "\\}"};
|
||||
|
||||
@Autowired
|
||||
private ChatClient chatClient;
|
||||
@Autowired
|
||||
private ChatMemory chatMemory;
|
||||
@Autowired(required = false)
|
||||
private VectorStore vectorStore;
|
||||
@Autowired
|
||||
private CmsAiProperties properties;
|
||||
private final ChatClient chatClient;
|
||||
private final ChatMemory chatMemory;
|
||||
private final VectorStore vectorStore;
|
||||
private final CmsAiProperties properties;
|
||||
|
||||
public CmsAiChatService(ChatClient chatClient,
|
||||
ChatMemory chatMemory,
|
||||
ObjectProvider<VectorStore> vectorStore,
|
||||
CmsAiProperties properties) {
|
||||
this.chatClient = chatClient;
|
||||
this.chatMemory = chatMemory;
|
||||
this.vectorStore = vectorStore.getIfAvailable();
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天对话消息
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.jeesite.modules.sys.entity.Area;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.ai.chat.messages.Message;
|
||||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -32,8 +31,11 @@ import java.util.stream.Collectors;
|
||||
@RequestMapping("${adminPath}/cms/chat")
|
||||
public class CmsAiChatController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private CmsAiChatService cmsAiChatService;
|
||||
private final CmsAiChatService cmsAiChatService;
|
||||
|
||||
public CmsAiChatController(CmsAiChatService cmsAiChatService) {
|
||||
this.cmsAiChatService = cmsAiChatService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天对话消息
|
||||
|
||||
Reference in New Issue
Block a user