This commit is contained in:
jack ning
2025-08-08 18:09:17 +08:00
parent e1c47ad7eb
commit 6929a892f2
30 changed files with 863 additions and 233 deletions

View File

@@ -1,108 +1,109 @@
package com.bytedesk.ai.alibaba.graph;
import com.alibaba.cloud.ai.graph.CompiledGraph;
import com.alibaba.cloud.ai.graph.KeyStrategy;
import com.alibaba.cloud.ai.graph.StateGraph;
import com.alibaba.cloud.ai.graph.action.AsyncNodeAction;
import com.alibaba.cloud.ai.graph.exception.GraphStateException;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
// import com.alibaba.cloud.ai.graph.CompiledGraph;
// import com.alibaba.cloud.ai.graph.KeyStrategy;
// import com.alibaba.cloud.ai.graph.StateGraph;
// import com.alibaba.cloud.ai.graph.action.AsyncNodeAction;
// import com.alibaba.cloud.ai.graph.exception.GraphStateException;
// import org.springframework.ai.chat.client.ChatClient;
// import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
// import org.springframework.ai.chat.model.ChatModel;
// import org.springframework.context.annotation.Bean;
// import org.springframework.stereotype.Component;
// import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
// import java.util.HashMap;
// import java.util.List;
// import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
// import static com.alibaba.cloud.ai.graph.StateGraph.END;
// import static com.alibaba.cloud.ai.graph.StateGraph.START;
// import static com.alibaba.cloud.ai.graph.action.AsyncEdgeAction.edge_async;
import static com.alibaba.cloud.ai.graph.StateGraph.END;
import static com.alibaba.cloud.ai.graph.StateGraph.START;
import static com.alibaba.cloud.ai.graph.action.AsyncEdgeAction.edge_async;
// import com.alibaba.cloud.ai.graph.node.HttpNode;
// import com.alibaba.cloud.ai.graph.node.HttpNode.RetryConfig;
// import com.alibaba.cloud.ai.graph.node.QuestionClassifierNode;
// import com.alibaba.cloud.ai.graph.node.VariableAggregatorNode;
import com.alibaba.cloud.ai.graph.node.HttpNode;
import com.alibaba.cloud.ai.graph.node.HttpNode.RetryConfig;
import com.alibaba.cloud.ai.graph.node.QuestionClassifierNode;
import com.alibaba.cloud.ai.graph.node.VariableAggregatorNode;
// @Component
// @ConditionalOnBean(name = {"primaryZhipuaiChatModel", "primaryOllamaChatModel", "primaryDashscopeChatModel", "primaryDeepseekChatModel", "primaryBaiduChatModel", "primaryTencentChatModel", "primaryVolcengineChatModel", "primaryOpenaiChatModel", "primaryOpenrouterChatModel", "primarySiliconflowChatModel", "primaryGiteeChatModel"})
// public class GraphBuilder {
@Component
public class GraphBuilder {
// @Bean
// public CompiledGraph buildGraph(ChatModel chatModel) throws GraphStateException {
// ChatClient chatClient = ChatClient.builder(chatModel).defaultAdvisors(new SimpleLoggerAdvisor()).build();
@Bean
public CompiledGraph buildGraph(ChatModel chatModel) throws GraphStateException {
ChatClient chatClient = ChatClient.builder(chatModel).defaultAdvisors(new SimpleLoggerAdvisor()).build();
// // new stateGraph
// StateGraph stateGraph = new StateGraph(() -> {
// Map<String, KeyStrategy> strategies = new HashMap<>();
// strategies.put("output", (o1, o2) -> o2);
// strategies.put("httpNode3_output", (o1, o2) -> o2);
// strategies.put("questionClassifyNode1_output", (o1, o2) -> o2);
// strategies.put("end1_output", (o1, o2) -> o2);
// strategies.put("questionClassifyNode2_output", (o1, o2) -> o2);
// strategies.put("review", (o1, o2) -> o2);
// strategies.put("httpNode1_output", (o1, o2) -> o2);
// strategies.put("httpNode2_output", (o1, o2) -> o2);
// return strategies;
// });
// // add nodes
// // —— QuestionClassifierNode [1711529036587] ——
// QuestionClassifierNode questionClassifyNode1 = QuestionClassifierNode.builder().chatClient(chatClient)
// .inputTextKey("review").categories(List.of("正面评价", "负面评价")).outputKey("questionClassifyNode1_output")
// .classificationInstructions(List.of("请根据输入内容选择对应分类")).build();
// stateGraph.addNode("questionClassifyNode1", AsyncNodeAction.node_async(questionClassifyNode1));
// new stateGraph
StateGraph stateGraph = new StateGraph(() -> {
Map<String, KeyStrategy> strategies = new HashMap<>();
strategies.put("output", (o1, o2) -> o2);
strategies.put("httpNode3_output", (o1, o2) -> o2);
strategies.put("questionClassifyNode1_output", (o1, o2) -> o2);
strategies.put("end1_output", (o1, o2) -> o2);
strategies.put("questionClassifyNode2_output", (o1, o2) -> o2);
strategies.put("review", (o1, o2) -> o2);
strategies.put("httpNode1_output", (o1, o2) -> o2);
strategies.put("httpNode2_output", (o1, o2) -> o2);
return strategies;
});
// add nodes
// —— QuestionClassifierNode [1711529036587] ——
QuestionClassifierNode questionClassifyNode1 = QuestionClassifierNode.builder().chatClient(chatClient)
.inputTextKey("review").categories(List.of("正面评价", "负面评价")).outputKey("questionClassifyNode1_output")
.classificationInstructions(List.of("请根据输入内容选择对应分类")).build();
stateGraph.addNode("questionClassifyNode1", AsyncNodeAction.node_async(questionClassifyNode1));
// // —— HttpNode [1711529059204] ——
// HttpNode httpNode1 = HttpNode.builder().url("https://www.example.com")
// .retryConfig(new RetryConfig(3, 100, true)).outputKey("httpNode1_output").build();
// stateGraph.addNode("httpNode1", AsyncNodeAction.node_async(httpNode1));
// —— HttpNode [1711529059204] ——
HttpNode httpNode1 = HttpNode.builder().url("https://www.example.com")
.retryConfig(new RetryConfig(3, 100, true)).outputKey("httpNode1_output").build();
stateGraph.addNode("httpNode1", AsyncNodeAction.node_async(httpNode1));
// // —— QuestionClassifierNode [1711529066687] ——
// QuestionClassifierNode questionClassifyNode2 = QuestionClassifierNode.builder().chatClient(chatClient)
// .inputTextKey("review").categories(List.of("售后问题", "运输问题")).outputKey("questionClassifyNode2_output")
// .classificationInstructions(List.of("请根据输入内容选择对应分类")).build();
// stateGraph.addNode("questionClassifyNode2", AsyncNodeAction.node_async(questionClassifyNode2));
// —— QuestionClassifierNode [1711529066687] ——
QuestionClassifierNode questionClassifyNode2 = QuestionClassifierNode.builder().chatClient(chatClient)
.inputTextKey("review").categories(List.of("售后问题", "运输问题")).outputKey("questionClassifyNode2_output")
.classificationInstructions(List.of("请根据输入内容选择对应分类")).build();
stateGraph.addNode("questionClassifyNode2", AsyncNodeAction.node_async(questionClassifyNode2));
// // —— HttpNode [1711529077513] ——
// HttpNode httpNode2 = HttpNode.builder().url("https://www.example.com")
// .retryConfig(new RetryConfig(3, 100, true)).outputKey("httpNode2_output").build();
// stateGraph.addNode("httpNode2", AsyncNodeAction.node_async(httpNode2));
// —— HttpNode [1711529077513] ——
HttpNode httpNode2 = HttpNode.builder().url("https://www.example.com")
.retryConfig(new RetryConfig(3, 100, true)).outputKey("httpNode2_output").build();
stateGraph.addNode("httpNode2", AsyncNodeAction.node_async(httpNode2));
// // —— HttpNode [1711529078719] ——
// HttpNode httpNode3 = HttpNode.builder().url("https://www.example.com")
// .retryConfig(new RetryConfig(3, 100, true)).outputKey("httpNode3_output").build();
// stateGraph.addNode("httpNode3", AsyncNodeAction.node_async(httpNode3));
// —— HttpNode [1711529078719] ——
HttpNode httpNode3 = HttpNode.builder().url("https://www.example.com")
.retryConfig(new RetryConfig(3, 100, true)).outputKey("httpNode3_output").build();
stateGraph.addNode("httpNode3", AsyncNodeAction.node_async(httpNode3));
// // —— VariableAggregatorNode [1718995432944] ——
// VariableAggregatorNode variableAggregatorNode1 = VariableAggregatorNode.builder()
// .variables(List.of(List.of("httpNode1_output", "body"), List.of("httpNode2_output", "body"),
// List.of("httpNode3_output", "body")))
// .outputKey("output").outputType("string").build();
// stateGraph.addNode("variableAggregatorNode1", AsyncNodeAction.node_async(variableAggregatorNode1));
// —— VariableAggregatorNode [1718995432944] ——
VariableAggregatorNode variableAggregatorNode1 = VariableAggregatorNode.builder()
.variables(List.of(List.of("httpNode1_output", "body"), List.of("httpNode2_output", "body"),
List.of("httpNode3_output", "body")))
.outputKey("output").outputType("string").build();
stateGraph.addNode("variableAggregatorNode1", AsyncNodeAction.node_async(variableAggregatorNode1));
// // add edges
// stateGraph.addEdge(START, "questionClassifyNode1");
// stateGraph.addEdge("httpNode1", "variableAggregatorNode1");
// stateGraph.addEdge("httpNode2", "variableAggregatorNode1");
// stateGraph.addEdge("httpNode3", "variableAggregatorNode1");
// stateGraph.addEdge("variableAggregatorNode1", END);
// stateGraph.addConditionalEdges("questionClassifyNode1", edge_async(state -> {
// String value = state.value("questionClassifyNode1_output", String.class).orElse("");
// if (value.contains("正面评价"))
// return "正面评价";
// if (value.contains("负面评价"))
// return "负面评价";
// return null;
// }), Map.of("正面评价", "httpNode1", "负面评价", "questionClassifyNode2"));
// stateGraph.addConditionalEdges("questionClassifyNode2", edge_async(state -> {
// String value = state.value("questionClassifyNode2_output", String.class).orElse("");
// if (value.contains("售后问题"))
// return "售后问题";
// if (value.contains("运输问题"))
// return "运输问题";
// return null;
// }), Map.of("售后问题", "httpNode2", "运输问题", "httpNode3"));
// add edges
stateGraph.addEdge(START, "questionClassifyNode1");
stateGraph.addEdge("httpNode1", "variableAggregatorNode1");
stateGraph.addEdge("httpNode2", "variableAggregatorNode1");
stateGraph.addEdge("httpNode3", "variableAggregatorNode1");
stateGraph.addEdge("variableAggregatorNode1", END);
stateGraph.addConditionalEdges("questionClassifyNode1", edge_async(state -> {
String value = state.value("questionClassifyNode1_output", String.class).orElse("");
if (value.contains("正面评价"))
return "正面评价";
if (value.contains("负面评价"))
return "负面评价";
return null;
}), Map.of("正面评价", "httpNode1", "负面评价", "questionClassifyNode2"));
stateGraph.addConditionalEdges("questionClassifyNode2", edge_async(state -> {
String value = state.value("questionClassifyNode2_output", String.class).orElse("");
if (value.contains("售后问题"))
return "售后问题";
if (value.contains("运输问题"))
return "运输问题";
return null;
}), Map.of("售后问题", "httpNode2", "运输问题", "httpNode3"));
// return stateGraph.compile();
// }
return stateGraph.compile();
}
}
// }

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-07-14 17:38:38
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-07-18 16:07:39
* @LastEditTime: 2025-08-08 17:50:51
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -13,50 +13,50 @@
*/
package com.bytedesk.ai.alibaba.graph;
import com.alibaba.cloud.ai.graph.CompiledGraph;
import com.alibaba.cloud.ai.graph.NodeOutput;
import com.alibaba.cloud.ai.graph.OverAllState;
import com.alibaba.cloud.ai.graph.async.AsyncGenerator;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
// import com.alibaba.cloud.ai.graph.CompiledGraph;
// import com.alibaba.cloud.ai.graph.NodeOutput;
// import com.alibaba.cloud.ai.graph.OverAllState;
// import com.alibaba.cloud.ai.graph.async.AsyncGenerator;
// import org.springframework.beans.factory.annotation.Qualifier;
// import org.springframework.http.MediaType;
// import org.springframework.web.bind.annotation.PostMapping;
// import org.springframework.web.bind.annotation.RequestBody;
// import org.springframework.web.bind.annotation.RequestMapping;
// import org.springframework.web.bind.annotation.RestController;
// import reactor.core.publisher.Flux;
import java.util.Map;
import java.util.HashMap;
// import java.util.Map;
// import java.util.HashMap;
@RestController
@RequestMapping("/springai/alibaba/graph/run")
public class GraphRunController {
// @RestController
// @RequestMapping("/springai/alibaba/graph/run")
// public class GraphRunController {
private CompiledGraph graph;
// private CompiledGraph graph;
public GraphRunController(@Qualifier("buildGraph") CompiledGraph graph) {
this.graph = graph;
}
// public GraphRunController(@Qualifier("buildGraph") CompiledGraph graph) {
// this.graph = graph;
// }
// http://127.0.0.1:9003/springai/alibaba/graph/run/stream
@PostMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<NodeOutput> stream(@RequestBody Map<String, Object> inputs) throws Exception {
AsyncGenerator<NodeOutput> nodeOutputs = graph.stream(inputs);
return Flux.fromStream(nodeOutputs.stream());
}
// // http://127.0.0.1:9003/springai/alibaba/graph/run/stream
// @PostMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
// public Flux<NodeOutput> stream(@RequestBody Map<String, Object> inputs) throws Exception {
// AsyncGenerator<NodeOutput> nodeOutputs = graph.stream(inputs);
// return Flux.fromStream(nodeOutputs.stream());
// }
// http://127.0.0.1:9003/springai/alibaba/graph/run/invoke
@PostMapping(value = "/invoke")
public OverAllState invoke(@RequestBody Map<String, Object> inputs) throws Exception {
return graph.invoke(inputs).orElse(null);
}
// // http://127.0.0.1:9003/springai/alibaba/graph/run/invoke
// @PostMapping(value = "/invoke")
// public OverAllState invoke(@RequestBody Map<String, Object> inputs) throws Exception {
// return graph.invoke(inputs).orElse(null);
// }
// http://127.0.0.1:9003/springai/alibaba/graph/run/start
@PostMapping(value = "/start")
public Map<String, Object> startInvoke(@RequestBody Map<String, Object> inputs) throws Exception {
Map<String, Object> startInputs = new HashMap<>();
startInputs.put("review", inputs.get("review")); // null
return graph.invoke(startInputs).get().data();
}
// // http://127.0.0.1:9003/springai/alibaba/graph/run/start
// @PostMapping(value = "/start")
// public Map<String, Object> startInvoke(@RequestBody Map<String, Object> inputs) throws Exception {
// Map<String, Object> startInputs = new HashMap<>();
// startInputs.put("review", inputs.get("review")); // null
// return graph.invoke(startInputs).get().data();
// }
}
// }

View File

@@ -5,7 +5,7 @@
* @LastEditTime: 2025-07-17 16:20:30
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
* contact: 270580156@qq.com
*
@@ -65,7 +65,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@RequestMapping("/spring/ai/rag")
@RequiredArgsConstructor
@ConditionalOnBean(ChatModel.class)
@ConditionalOnBean({ChatModel.class, VectorStore.class, EmbeddingModel.class})
public class SpringAIRagController {
private final VectorStore vectorStore;

View File

@@ -63,19 +63,19 @@ public abstract class BaseSpringAIService implements SpringAIService {
@Autowired
protected FaqElasticService faqElasticService;
@Autowired
@Autowired(required = false)
protected FaqVectorService faqVectorService;
@Autowired
protected TextElasticService textElasticService;
@Autowired
@Autowired(required = false)
protected TextVectorService textVectorService;
@Autowired
protected ChunkElasticService chunkElasticService;
@Autowired
@Autowired(required = false)
protected ChunkVectorService chunkVectorService;
@Autowired
@@ -544,28 +544,49 @@ public abstract class BaseSpringAIService implements SpringAIService {
}
private void executeVectorSearch(String query, String kbUid, List<FaqProtobuf> searchResultList) {
List<FaqVectorSearchResult> searchResults = faqVectorService.searchFaqVector(query, kbUid, null, null, 5);
for (FaqVectorSearchResult withScore : searchResults) {
FaqVector faqVector = withScore.getFaqVector();
//
FaqProtobuf faqProtobuf = FaqProtobuf.fromFaqVector(faqVector);
searchResultList.add(faqProtobuf);
// 检查 FaqVectorService 是否可用
if (faqVectorService != null) {
try {
List<FaqVectorSearchResult> searchResults = faqVectorService.searchFaqVector(query, kbUid, null, null, 5);
for (FaqVectorSearchResult withScore : searchResults) {
FaqVector faqVector = withScore.getFaqVector();
//
FaqProtobuf faqProtobuf = FaqProtobuf.fromFaqVector(faqVector);
searchResultList.add(faqProtobuf);
}
} catch (Exception e) {
log.warn("FaqVectorService search failed: {}", e.getMessage());
}
}
//
List<TextVectorSearchResult> textResults = textVectorService.searchTextVector(query, kbUid, null, null, 5);
for (TextVectorSearchResult withScore : textResults) {
TextVector textVector = withScore.getTextVector();
//
FaqProtobuf faqProtobuf = FaqProtobuf.fromTextVector(textVector);
searchResultList.add(faqProtobuf);
// 检查 TextVectorService 是否可用
if (textVectorService != null) {
try {
List<TextVectorSearchResult> textResults = textVectorService.searchTextVector(query, kbUid, null, null, 5);
for (TextVectorSearchResult withScore : textResults) {
TextVector textVector = withScore.getTextVector();
//
FaqProtobuf faqProtobuf = FaqProtobuf.fromTextVector(textVector);
searchResultList.add(faqProtobuf);
}
} catch (Exception e) {
log.warn("TextVectorService search failed: {}", e.getMessage());
}
}
//
List<ChunkVectorSearchResult> chunkResults = chunkVectorService.searchChunkVector(query, kbUid, null, null, 5);
for (ChunkVectorSearchResult withScore : chunkResults) {
ChunkVector chunkVector = withScore.getChunkVector();
//
FaqProtobuf faqProtobuf = FaqProtobuf.fromChunkVector(chunkVector);
searchResultList.add(faqProtobuf);
// 检查 ChunkVectorService 是否可用
if (chunkVectorService != null) {
try {
List<ChunkVectorSearchResult> chunkResults = chunkVectorService.searchChunkVector(query, kbUid, null, null, 5);
for (ChunkVectorSearchResult withScore : chunkResults) {
ChunkVector chunkVector = withScore.getChunkVector();
//
FaqProtobuf faqProtobuf = FaqProtobuf.fromChunkVector(chunkVector);
searchResultList.add(faqProtobuf);
}
} catch (Exception e) {
log.warn("ChunkVectorService search failed: {}", e.getMessage());
}
}
}

2
modules/call/.gitattributes vendored Normal file
View File

@@ -0,0 +1,2 @@
/mvnw text eol=lf
*.cmd text eol=crlf

View File

@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip

259
modules/call/mvnw vendored Executable file
View File

@@ -0,0 +1,259 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Apache Maven Wrapper startup batch script, version 3.3.2
#
# Optional ENV vars
# -----------------
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
# MVNW_REPOURL - repo url base for downloading maven distribution
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
# ----------------------------------------------------------------------------
set -euf
[ "${MVNW_VERBOSE-}" != debug ] || set -x
# OS specific support.
native_path() { printf %s\\n "$1"; }
case "$(uname)" in
CYGWIN* | MINGW*)
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
native_path() { cygpath --path --windows "$1"; }
;;
esac
# set JAVACMD and JAVACCMD
set_java_home() {
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
if [ -n "${JAVA_HOME-}" ]; then
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
JAVACCMD="$JAVA_HOME/jre/sh/javac"
else
JAVACMD="$JAVA_HOME/bin/java"
JAVACCMD="$JAVA_HOME/bin/javac"
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
return 1
fi
fi
else
JAVACMD="$(
'set' +e
'unset' -f command 2>/dev/null
'command' -v java
)" || :
JAVACCMD="$(
'set' +e
'unset' -f command 2>/dev/null
'command' -v javac
)" || :
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
return 1
fi
fi
}
# hash string like Java String::hashCode
hash_string() {
str="${1:-}" h=0
while [ -n "$str" ]; do
char="${str%"${str#?}"}"
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
str="${str#?}"
done
printf %x\\n $h
}
verbose() { :; }
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
die() {
printf %s\\n "$1" >&2
exit 1
}
trim() {
# MWRAPPER-139:
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
# Needed for removing poorly interpreted newline sequences when running in more
# exotic environments such as mingw bash on Windows.
printf "%s" "${1}" | tr -d '[:space:]'
}
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
while IFS="=" read -r key value; do
case "${key-}" in
distributionUrl) distributionUrl=$(trim "${value-}") ;;
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
esac
done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
case "${distributionUrl##*/}" in
maven-mvnd-*bin.*)
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
*)
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
distributionPlatform=linux-amd64
;;
esac
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
;;
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
esac
# apply MVNW_REPOURL and calculate MAVEN_HOME
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
distributionUrlName="${distributionUrl##*/}"
distributionUrlNameMain="${distributionUrlName%.*}"
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
exec_maven() {
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
}
if [ -d "$MAVEN_HOME" ]; then
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
exec_maven "$@"
fi
case "${distributionUrl-}" in
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
esac
# prepare tmp dir
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
trap clean HUP INT TERM EXIT
else
die "cannot create temp dir"
fi
mkdir -p -- "${MAVEN_HOME%/*}"
# Download and Install Apache Maven
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
verbose "Downloading from: $distributionUrl"
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
# select .zip or .tar.gz
if ! command -v unzip >/dev/null; then
distributionUrl="${distributionUrl%.zip}.tar.gz"
distributionUrlName="${distributionUrl##*/}"
fi
# verbose opt
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
# normalize http auth
case "${MVNW_PASSWORD:+has-password}" in
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
esac
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
verbose "Found wget ... using wget"
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
verbose "Found curl ... using curl"
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
elif set_java_home; then
verbose "Falling back to use Java to download"
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
cat >"$javaSource" <<-END
public class Downloader extends java.net.Authenticator
{
protected java.net.PasswordAuthentication getPasswordAuthentication()
{
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
}
public static void main( String[] args ) throws Exception
{
setDefault( new Downloader() );
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
}
}
END
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
verbose " - Compiling Downloader.java ..."
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
verbose " - Running Downloader.java ..."
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
fi
# If specified, validate the SHA-256 sum of the Maven distribution zip file
if [ -n "${distributionSha256Sum-}" ]; then
distributionSha256Result=false
if [ "$MVN_CMD" = mvnd.sh ]; then
echo "Checksum validation is not supported for maven-mvnd." >&2
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
exit 1
elif command -v sha256sum >/dev/null; then
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then
distributionSha256Result=true
fi
elif command -v shasum >/dev/null; then
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
distributionSha256Result=true
fi
else
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
exit 1
fi
if [ $distributionSha256Result = false ]; then
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
exit 1
fi
fi
# unzip and move
if command -v unzip >/dev/null; then
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
else
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
fi
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
clean || :
exec_maven "$@"

149
modules/call/mvnw.cmd vendored Normal file
View File

@@ -0,0 +1,149 @@
<# : batch portion
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Apache Maven Wrapper startup batch script, version 3.3.2
@REM
@REM Optional ENV vars
@REM MVNW_REPOURL - repo url base for downloading maven distribution
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
@REM ----------------------------------------------------------------------------
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
@SET __MVNW_CMD__=
@SET __MVNW_ERROR__=
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
@SET PSModulePath=
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
)
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
@SET __MVNW_PSMODULEP_SAVE=
@SET __MVNW_ARG0_NAME__=
@SET MVNW_USERNAME=
@SET MVNW_PASSWORD=
@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
@echo Cannot start maven from wrapper >&2 && exit /b 1
@GOTO :EOF
: end batch / begin powershell #>
$ErrorActionPreference = "Stop"
if ($env:MVNW_VERBOSE -eq "true") {
$VerbosePreference = "Continue"
}
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
if (!$distributionUrl) {
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
}
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
"maven-mvnd-*" {
$USE_MVND = $true
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
$MVN_CMD = "mvnd.cmd"
break
}
default {
$USE_MVND = $false
$MVN_CMD = $script -replace '^mvnw','mvn'
break
}
}
# apply MVNW_REPOURL and calculate MAVEN_HOME
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
if ($env:MVNW_REPOURL) {
$MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
}
$distributionUrlName = $distributionUrl -replace '^.*/',''
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
if ($env:MAVEN_USER_HOME) {
$MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
}
$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
exit $?
}
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
}
# prepare tmp dir
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
trap {
if ($TMP_DOWNLOAD_DIR.Exists) {
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
}
}
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
# Download and Install Apache Maven
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
Write-Verbose "Downloading from: $distributionUrl"
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
$webclient = New-Object System.Net.WebClient
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
# If specified, validate the SHA-256 sum of the Maven distribution zip file
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
if ($distributionSha256Sum) {
if ($USE_MVND) {
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
}
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
}
}
# unzip and move
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
try {
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
} catch {
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
Write-Error "fail to move MAVEN_HOME"
}
} finally {
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
}
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"

46
modules/call/pom.xml Normal file
View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bytedesk</groupId>
<artifactId>modules</artifactId>
<version>${revision}</version>
</parent>
<artifactId>bytedesk-module-call</artifactId>
<version>${revision}</version>
<name>bytedesk-module-call</name>
<description>https://ai.bytedesk.com</description>
<properties>
</properties>
<dependencies>
<!-- ///////////////////////////////////////////////////////////////////////////// -->
<dependency>
<groupId>com.bytedesk</groupId>
<artifactId>bytedesk-module-core</artifactId>
<version>${revision}</version>
<scope>provided</scope>
</dependency>
<!-- ///////////////////////////////////////////////////////////////////////////// -->
</dependencies>
<build>
<plugins>
<!-- <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin> -->
</plugins>
</build>
</project>

View File

@@ -0,0 +1,13 @@
package com.bytedesk.call;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CallApplication {
public static void main(String[] args) {
SpringApplication.run(CallApplication.class, args);
}
}

View File

@@ -0,0 +1 @@
spring.application.name=call

View File

@@ -0,0 +1,13 @@
package com.bytedesk.call;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class CallApplicationTests {
@Test
void contextLoads() {
}
}

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2024-01-29 16:21:46
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2024-11-20 12:45:50
* @LastEditTime: 2025-08-08 17:47:25
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -25,17 +25,25 @@ import com.bytedesk.core.socket.mqtt.MqttAuthService;
@AllArgsConstructor
public class MqttAuthService {
// private final UserService userService;
// private final TokenRestService tokenRestService;
public Boolean checkValid(String username, String password) {
// 客户端使用accessToken作为password传递避免客户端存储密码
String accessToken = password;
log.debug("auth username {}, accessToken {}", username, accessToken);
// if (!userService.checkToken(username, accessToken)) {
// return false;
// }
log.debug("mqtt auth username {}, accessToken {}", username, accessToken);
return true;
// if (accessToken != null && JwtUtils.validateJwtToken(accessToken)) {
// // 从数据库验证token是否有效未被撤销且未过期
// Optional<TokenEntity> tokenOpt = tokenRestService.findByAccessToken(accessToken);
// if (tokenOpt.isPresent() && tokenOpt.get().isValid()) {
// return true;
// } else {
// log.debug("mqtt auth Token is invalid or revoked");
// return false;
// }
// }
// log.debug("mqtt auth Token is invalid or expired");
// return false;
}
}

View File

@@ -30,7 +30,7 @@ import com.bytedesk.kbase.article.elastic.ArticleElasticService;
import com.bytedesk.kbase.article.vector.ArticleVectorService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bytedesk.core.annotation.ActionAnnotation;
@@ -44,7 +44,6 @@ import org.springframework.context.annotation.Description;
@Tag(name = "文章管理", description = "文章管理相关接口")
@RestController
@RequestMapping("/api/v1/article")
@AllArgsConstructor
@Description("Article Management Controller - Knowledge base article content management APIs")
public class ArticleRestController extends BaseRestController<ArticleRequest> {
@@ -52,7 +51,13 @@ public class ArticleRestController extends BaseRestController<ArticleRequest> {
private final ArticleElasticService articleElasticService;
private final ArticleVectorService articleVectorService;
@Autowired(required = false)
private ArticleVectorService articleVectorService;
public ArticleRestController(ArticleRestService articleRestService, ArticleElasticService articleElasticService) {
this.articleRestService = articleRestService;
this.articleElasticService = articleElasticService;
}
@Operation(summary = "查询组织下的文章", description = "根据组织ID查询文章列表")
@ApiResponse(responseCode = "200", description = "查询成功",
@@ -167,9 +172,12 @@ public class ArticleRestController extends BaseRestController<ArticleRequest> {
@PostMapping("/updateVectorIndex")
public ResponseEntity<?> updateVectorIndex(@RequestBody ArticleRequest request) {
articleVectorService.updateVectorIndex(request);
return ResponseEntity.ok(JsonResult.success("update vector index success", request.getUid()));
if (articleVectorService != null) {
articleVectorService.updateVectorIndex(request);
return ResponseEntity.ok(JsonResult.success("update vector index success", request.getUid()));
} else {
return ResponseEntity.ok(JsonResult.error("Vector service is not available"));
}
}
@Operation(summary = "更新所有文章索引", description = "更新所有文章的Elasticsearch索引")
@@ -189,9 +197,12 @@ public class ArticleRestController extends BaseRestController<ArticleRequest> {
@PostMapping("/updateAllVectorIndex")
public ResponseEntity<?> updateAllVectorIndex(@RequestBody ArticleRequest request) {
articleVectorService.updateAllVectorIndex(request);
return ResponseEntity.ok(JsonResult.success("update all vector index success", request.getUid()));
if (articleVectorService != null) {
articleVectorService.updateAllVectorIndex(request);
return ResponseEntity.ok(JsonResult.success("update all vector index success", request.getUid()));
} else {
return ResponseEntity.ok(JsonResult.error("Vector service is not available"));
}
}
@Operation(summary = "搜索文章", description = "输入联想搜索文章")

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2024-03-22 22:59:07
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2024-10-30 10:06:45
* @LastEditTime: 2025-08-08 17:28:50
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -30,13 +30,13 @@ import lombok.AllArgsConstructor;
@Tag(name = "文章匿名管理", description = "文章匿名相关接口")
public class ArticleRestControllerVisitor {
private final ArticleRestService articleService;
private final ArticleRestService articleRestService;
@RequestMapping("/search")
@Operation(summary = "搜索文章", description = "访客搜索文章")
public ResponseEntity<?> searchKb(ArticleRequest request) {
Page<ArticleResponse> page = articleService.queryByOrg(request);
Page<ArticleResponse> page = articleRestService.queryByOrg(request);
return ResponseEntity.ok(JsonResult.success(page));
}

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-05-31 18:10:00
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-05-31 18:10:00
* @LastEditTime: 2025-08-08 17:36:41
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -23,8 +23,8 @@ import com.bytedesk.kbase.article.ArticleEntity;
import com.bytedesk.kbase.article.ArticleRestService;
import com.bytedesk.kbase.article.vector.ArticleVectorService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 文章索引消息监听器
@@ -32,13 +32,17 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class ArticleIndexMessageListener {
private final ArticleRestService articleRestService;
private final ArticleVectorService articleVectorService;
@Autowired(required = false)
private ArticleVectorService articleVectorService;
// private final ArticleElasticService articleElasticService;
public ArticleIndexMessageListener(ArticleRestService articleRestService) {
this.articleRestService = articleRestService;
}
/**
* 监听文章索引队列,处理索引和删除操作
* 使用并发消费者提高吞吐量,但保持消息的顺序处理
@@ -69,7 +73,7 @@ public class ArticleIndexMessageListener {
log.info("处理文章删除索引: {}", article.getTitle());
// 删除向量索引
if (message.getUpdateVectorIndex()) {
if (message.getUpdateVectorIndex() && articleVectorService != null) {
try {
articleVectorService.deleteArticle(article);
} catch (Exception e) {
@@ -91,7 +95,7 @@ public class ArticleIndexMessageListener {
log.info("处理文章创建/更新索引: {}", article.getTitle());
// 创建/更新向量索引
if (message.getUpdateVectorIndex()) {
if (message.getUpdateVectorIndex() && articleVectorService != null) {
try {
articleVectorService.indexVector(article);
} catch (Exception e) {

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-05-31 16:35:20
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-06-03 14:51:23
* @LastEditTime: 2025-08-08 17:39:32
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -25,7 +25,7 @@ import com.bytedesk.kbase.article.ArticleRestService;
import com.bytedesk.kbase.article.elastic.ArticleElasticService;
import com.bytedesk.kbase.article.vector.ArticleVectorService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
/**
@@ -34,14 +34,19 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
@Component
@AllArgsConstructor
public class ArticleMessageConsumer {
private final ArticleElasticService articleElasticService;
private final ArticleRestService articleRestService;
private final ArticleVectorService articleVectorService;
@Autowired(required = false)
private ArticleVectorService articleVectorService;
private final Random random = new Random();
public ArticleMessageConsumer(ArticleElasticService articleElasticService, ArticleRestService articleRestService) {
this.articleElasticService = articleElasticService;
this.articleRestService = articleRestService;
}
/**
* 处理文章索引队列中的消息
* 使用客户端确认模式,只有成功处理后才确认消息
@@ -149,7 +154,7 @@ public class ArticleMessageConsumer {
}
// 这里可以添加对向量索引的处理,如果需要
if (message.getUpdateVectorIndex()) {
if (message.getUpdateVectorIndex() && articleVectorService != null) {
log.info("更新文章向量索引: {}", articleUid);
// 如果有文章向量服务,在这里调用
articleVectorService.indexVector(article);
@@ -184,7 +189,7 @@ public class ArticleMessageConsumer {
}
// 这里可以添加对向量索引删除的处理,如果需要
if (message.getUpdateVectorIndex()) {
if (message.getUpdateVectorIndex() && articleVectorService != null) {
log.info("从向量引擎中删除文章索引: {}", articleUid);
// 如果有文章向量服务,在这里调用
boolean vectorDeleted = articleVectorService.deleteArticle(article);

View File

@@ -34,6 +34,7 @@ import com.bytedesk.kbase.llm_chunk.ChunkStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
/**
* 文章向量检索服务
@@ -44,6 +45,7 @@ import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
@RequiredArgsConstructor
@ConditionalOnBean(org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.class)
public class ArticleVectorService {
private final ElasticsearchVectorStore vectorStore;

View File

@@ -30,6 +30,7 @@ import com.bytedesk.kbase.faq.vector.FaqVectorService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -40,14 +41,19 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Tag(name = "常见问题管理", description = "常见问题管理相关接口")
@RestController
@RequestMapping("/api/v1/faq")
@AllArgsConstructor
public class FaqRestController extends BaseRestController<FaqRequest> {
private final FaqRestService faqRestService;
private final FaqElasticService faqElasticService;
private final FaqVectorService faqVectorService;
@Autowired(required = false)
private FaqVectorService faqVectorService;
public FaqRestController(FaqRestService faqRestService, FaqElasticService faqElasticService) {
this.faqRestService = faqRestService;
this.faqElasticService = faqElasticService;
}
@Operation(summary = "查询组织下的常见问题", description = "根据组织ID查询常见问题列表")
@ApiResponse(responseCode = "200", description = "查询成功",
@@ -186,7 +192,9 @@ public class FaqRestController extends BaseRestController<FaqRequest> {
@PostMapping("/updateVectorIndex")
public ResponseEntity<?> updateVectorIndex(@RequestBody FaqRequest request) {
faqVectorService.updateVectorIndex(request);
if (faqVectorService != null) {
faqVectorService.updateVectorIndex(request);
}
return ResponseEntity.ok(JsonResult.success("update vector index success", request.getUid()));
}
@@ -208,7 +216,9 @@ public class FaqRestController extends BaseRestController<FaqRequest> {
@PostMapping("/updateAllVectorIndex")
public ResponseEntity<?> updateAllVectorIndex(@RequestBody FaqRequest request) {
faqVectorService.updateAllVectorIndex(request);
if (faqVectorService != null) {
faqVectorService.updateAllVectorIndex(request);
}
return ResponseEntity.ok(JsonResult.success("update all vector index success", request.getUid()));
}

View File

@@ -26,6 +26,7 @@ import com.bytedesk.kbase.faq.elastic.FaqElasticService;
import com.bytedesk.kbase.faq.vector.FaqVectorService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
/**
@@ -34,14 +35,19 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
@Component
@AllArgsConstructor
public class FaqIndexConsumer {
private final FaqElasticService faqElasticService;
private final FaqVectorService faqVectorService;
@Autowired(required = false)
private FaqVectorService faqVectorService;
private final FaqRestService faqRestService;
private final Random random = new Random();
public FaqIndexConsumer(FaqElasticService faqElasticService, FaqRestService faqRestService) {
this.faqElasticService = faqElasticService;
this.faqRestService = faqRestService;
}
/**
* 处理FAQ索引队列中的消息
* 使用客户端确认模式,只有成功处理后才确认消息

View File

@@ -35,6 +35,7 @@ import com.bytedesk.kbase.llm_chunk.ChunkStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
/**
* FAQ向量检索服务
@@ -45,6 +46,7 @@ import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
@RequiredArgsConstructor
@ConditionalOnBean(org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.class)
public class FaqVectorService {
private final ElasticsearchVectorStore vectorStore;

View File

@@ -35,11 +35,11 @@ import com.bytedesk.kbase.llm_chunk.vector.ChunkVectorService;
import com.bytedesk.core.utils.BdDateUtils;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
@AllArgsConstructor
public class ChunkEventListener {
private final ChunkElasticService chunkElasticService;
@@ -48,7 +48,14 @@ public class ChunkEventListener {
private final FileRestService fileRestService;
private final ChunkVectorService chunkVectorService;
@Autowired(required = false)
private ChunkVectorService chunkVectorService;
public ChunkEventListener(ChunkElasticService chunkElasticService, ChunkRestService chunkRestService, FileRestService fileRestService) {
this.chunkElasticService = chunkElasticService;
this.chunkRestService = chunkRestService;
this.fileRestService = fileRestService;
}
@EventListener
@@ -104,10 +111,12 @@ public class ChunkEventListener {
// 仅做全文索引
chunkElasticService.indexChunk(chunk);
/// 索引向量
try {
chunkVectorService.indexChunkVector(chunk);
} catch (Exception e) {
log.error("Chunk向量索引失败: {}, 错误: {}", chunk.getName(), e.getMessage());
if (chunkVectorService != null) {
try {
chunkVectorService.indexChunkVector(chunk);
} catch (Exception e) {
log.error("Chunk向量索引失败: {}, 错误: {}", chunk.getName(), e.getMessage());
}
}
}
@@ -119,14 +128,16 @@ public class ChunkEventListener {
// 更新全文索引
chunkElasticService.indexChunk(chunk);
// 更新向量索引
try {
// 先删除旧的向量索引
chunkVectorService.deleteChunkVector(chunk);
// 再创建新的向量索引
chunkVectorService.indexChunkVector(chunk);
} catch (Exception e) {
log.error("文本向量索引更新失败: {}, 错误: {}", chunk.getContent(), e.getMessage());
if (chunkVectorService != null) {
try {
// 先删除旧的向量索引
chunkVectorService.deleteChunkVector(chunk);
// 再创建新的向量索引
chunkVectorService.indexChunkVector(chunk);
} catch (Exception e) {
log.error("文本向量索引更新失败: {}, 错误: {}", chunk.getContent(), e.getMessage());
}
}
}

View File

@@ -28,17 +28,23 @@ import com.bytedesk.kbase.llm_chunk.vector.ChunkVectorService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
@RestController
@RequestMapping("/api/v1/llm/chunk")
@AllArgsConstructor
public class ChunkRestController extends BaseRestController<ChunkRequest> {
private final ChunkRestService chunkRestService;
private final ChunkElasticService chunkElasticService;
private final ChunkVectorService chunkVectorService;
@Autowired(required = false)
private ChunkVectorService chunkVectorService;
public ChunkRestController(ChunkRestService chunkRestService, ChunkElasticService chunkElasticService) {
this.chunkRestService = chunkRestService;
this.chunkElasticService = chunkElasticService;
}
// @PreAuthorize("hasAuthority('KBASE_READ')")
@Override
@@ -138,7 +144,9 @@ public class ChunkRestController extends BaseRestController<ChunkRequest> {
@PostMapping("/updateVectorIndex")
public ResponseEntity<?> updateVectorIndex(@RequestBody ChunkRequest request) {
chunkVectorService.updateVectorIndex(request);
if (chunkVectorService != null) {
chunkVectorService.updateVectorIndex(request);
}
return ResponseEntity.ok(JsonResult.success("update vector index success", request.getUid()));
}
@@ -158,7 +166,9 @@ public class ChunkRestController extends BaseRestController<ChunkRequest> {
@PostMapping("/updateAllVectorIndex")
public ResponseEntity<?> updateAllVectorIndex(@RequestBody ChunkRequest request) {
chunkVectorService.updateAllVectorIndex(request);
if (chunkVectorService != null) {
chunkVectorService.updateAllVectorIndex(request);
}
return ResponseEntity.ok(JsonResult.success("update all vector index success", request.getKbUid()));
}

View File

@@ -33,6 +33,7 @@ import com.bytedesk.kbase.llm_chunk.ChunkStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
/**
* Chunk向量检索服务
@@ -42,6 +43,7 @@ import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
@RequiredArgsConstructor
@ConditionalOnBean(org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.class)
public class ChunkVectorService {
private final ElasticsearchVectorStore vectorStore;

View File

@@ -31,18 +31,25 @@ import com.bytedesk.kbase.llm_text.event.TextUpdateDocEvent;
import com.bytedesk.kbase.llm_text.vector.TextVectorService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
@AllArgsConstructor
public class TextEventListener {
private final TextRestService textRestService;
private final TextElasticService textElasticService;
private final TextVectorService textVectorService;
@Autowired(required = false)
private TextVectorService textVectorService;
private final UploadRestService uploadRestService;
public TextEventListener(TextRestService textRestService, TextElasticService textElasticService, UploadRestService uploadRestService) {
this.textRestService = textRestService;
this.textElasticService = textElasticService;
this.uploadRestService = uploadRestService;
}
@EventListener
public void onUploadCreateEvent(UploadCreateEvent event) {
UploadEntity upload = event.getUpload();
@@ -87,10 +94,12 @@ public class TextEventListener {
textElasticService.indexText(text);
// 进行向量索引
try {
textVectorService.indexTextVector(text);
} catch (Exception e) {
log.error("文本向量索引创建失败: {}, 错误: {}", text.getTitle(), e.getMessage());
if (textVectorService != null) {
try {
textVectorService.indexTextVector(text);
} catch (Exception e) {
log.error("文本向量索引创建失败: {}, 错误: {}", text.getTitle(), e.getMessage());
}
}
}
@@ -103,13 +112,15 @@ public class TextEventListener {
textElasticService.indexText(text);
// 更新向量索引
try {
// 先删除旧的向量索引
textVectorService.deleteTextVector(text);
// 再创建新的向量索引
textVectorService.indexTextVector(text);
} catch (Exception e) {
log.error("文本向量索引更新失败: {}, 错误: {}", text.getTitle(), e.getMessage());
if (textVectorService != null) {
try {
// 先删除旧的向量索引
textVectorService.deleteTextVector(text);
// 再创建新的向量索引
textVectorService.indexTextVector(text);
} catch (Exception e) {
log.error("文本向量索引更新失败: {}, 错误: {}", text.getTitle(), e.getMessage());
}
}
}
@@ -125,9 +136,11 @@ public class TextEventListener {
}
// 从向量索引中删除
boolean vectorDeleted = textVectorService.deleteTextVector(text);
if (!vectorDeleted) {
log.warn("从向量存储中删除Text索引失败: {}", text.getUid());
if (textVectorService != null) {
boolean vectorDeleted = textVectorService.deleteTextVector(text);
if (!vectorDeleted) {
log.warn("从向量存储中删除Text索引失败: {}", text.getUid());
}
}
if (!deleted) {
log.warn("从Elasticsearch中删除Text索引失败: {}", text.getUid());

View File

@@ -28,11 +28,11 @@ import com.bytedesk.kbase.llm_text.vector.TextVectorService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
@RestController
@RequestMapping("/api/v1/llm/text")
@AllArgsConstructor
@Description("Text Management Controller - LLM text content management and vector processing APIs")
public class TextRestController extends BaseRestController<TextRequest> {
@@ -40,7 +40,13 @@ public class TextRestController extends BaseRestController<TextRequest> {
private final TextElasticService textElasticService;
private final TextVectorService textVectorService;
@Autowired(required = false)
private TextVectorService textVectorService;
public TextRestController(TextRestService textRestService, TextElasticService textElasticService) {
this.textRestService = textRestService;
this.textElasticService = textElasticService;
}
// @PreAuthorize("hasAnyRole('SUPER', 'ADMIN')")
@Override
@@ -139,7 +145,9 @@ public class TextRestController extends BaseRestController<TextRequest> {
@PostMapping("/updateVectorIndex")
public ResponseEntity<?> updateVectorIndex(@RequestBody TextRequest request) {
textVectorService.updateVectorIndex(request);
if (textVectorService != null) {
textVectorService.updateVectorIndex(request);
}
return ResponseEntity.ok(JsonResult.success("update vector index success", request.getUid()));
}
@@ -159,7 +167,9 @@ public class TextRestController extends BaseRestController<TextRequest> {
@PostMapping("/updateAllVectorIndex")
public ResponseEntity<?> updateAllVectorIndex(@RequestBody TextRequest request) {
textVectorService.updateAllVectorIndex(request);
if (textVectorService != null) {
textVectorService.updateAllVectorIndex(request);
}
return ResponseEntity.ok(JsonResult.success("update all vector index success", request.getKbUid()));
}

View File

@@ -34,6 +34,7 @@ import com.bytedesk.kbase.llm_text.TextRestService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
/**
* Text向量检索服务
@@ -43,6 +44,7 @@ import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
@RequiredArgsConstructor
@ConditionalOnBean(org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.class)
public class TextVectorService {
private final ElasticsearchVectorStore vectorStore;

View File

@@ -27,6 +27,7 @@ import com.bytedesk.kbase.llm_webpage.vector.WebpageVectorService;
import com.bytedesk.kbase.llm_webpage.service.WebpageCrawlerService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
/**
@@ -35,13 +36,19 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
@Component
@AllArgsConstructor
public class WebpageIndexConsumer {
private final WebpageElasticService webpageElasticService;
private final WebpageVectorService webpageVectorService;
@Autowired(required = false)
private WebpageVectorService webpageVectorService;
private final WebpageRestService webpageRestService;
private final WebpageCrawlerService webpageCrawlerService;
public WebpageIndexConsumer(WebpageElasticService webpageElasticService, WebpageRestService webpageRestService, WebpageCrawlerService webpageCrawlerService) {
this.webpageElasticService = webpageElasticService;
this.webpageRestService = webpageRestService;
this.webpageCrawlerService = webpageCrawlerService;
}
private final Random random = new Random();
/**

View File

@@ -34,6 +34,7 @@ import com.bytedesk.kbase.llm_webpage.WebpageRestService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
/**
* 网页向量检索服务
@@ -44,6 +45,7 @@ import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
@RequiredArgsConstructor
@ConditionalOnBean(org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.class)
public class WebpageVectorService {
private final ElasticsearchVectorStore vectorStore;

View File

@@ -16,6 +16,7 @@
<modules>
<module>ai</module>
<module>call</module>
<module>core</module>
<module>forum</module>
<module>kbase</module>