refactor(ai-web): 优化流程编排
This commit is contained in:
@@ -12,5 +12,6 @@ import org.eclipse.collections.api.factory.Lists;
|
||||
@Data
|
||||
public class FeedbackContext {
|
||||
private Feedback feedback;
|
||||
private String optimizedSource;
|
||||
private List<String> pictureDescriptions = Lists.mutable.empty();
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.document.DocumentReader;
|
||||
@@ -42,12 +40,12 @@ import org.springframework.core.io.PathResource;
|
||||
@Slf4j
|
||||
@LiteflowComponent
|
||||
public class EmbeddingNodes {
|
||||
private final ChatClient chatClient;
|
||||
private final ChatClient.Builder chatClientBuilder;
|
||||
private final QdrantClient qdrantClient;
|
||||
private final EmbeddingModel embeddingModel;
|
||||
|
||||
public EmbeddingNodes(@Qualifier("chat") ChatClient.Builder builder, VectorStore vectorStore, EmbeddingModel embeddingModel) {
|
||||
this.chatClient = builder.build();
|
||||
this.chatClientBuilder = builder;
|
||||
this.qdrantClient = (QdrantClient) vectorStore.getNativeClient().orElseThrow();
|
||||
this.embeddingModel = embeddingModel;
|
||||
}
|
||||
@@ -190,7 +188,8 @@ public class EmbeddingNodes {
|
||||
}
|
||||
|
||||
private List<Document> llmSplit(String prompt, String content, Map<String, Object> metadata) {
|
||||
String response = chatClient.prompt()
|
||||
ChatClient client = chatClientBuilder.build();
|
||||
String response = client.prompt()
|
||||
.system(prompt)
|
||||
.user(content)
|
||||
.call()
|
||||
|
||||
@@ -100,12 +100,12 @@ public class FeedbackNodes {
|
||||
}
|
||||
}
|
||||
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "feedback_suggest", nodeName = "大模型建议", nodeType = NodeTypeEnum.COMMON)
|
||||
public void suggest(NodeComponent node) {
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "optimize_source", nodeName = "报障信息优化", nodeType = NodeTypeEnum.COMMON)
|
||||
public void optimizeSource(NodeComponent node) {
|
||||
FeedbackContext context = node.getContextBean(FeedbackContext.class);
|
||||
Feedback feedback = context.getFeedback();
|
||||
ChatClient client = chatClientBuilder.build();
|
||||
String description = client.prompt()
|
||||
String optimizedSource = chatClientBuilder.build()
|
||||
.prompt()
|
||||
// language=TEXT
|
||||
.system("""
|
||||
你是一名专业的IT系统运维工程师,对于用户输入的关于系统的报障信息,你会严格遵循以下步骤进行处理
|
||||
@@ -140,27 +140,39 @@ public class FeedbackNodes {
|
||||
重写的故障描述,以结构化段落呈现,涵盖问题概述、详细症状、重现步骤和相关环境。
|
||||
输出将使用中性、客观语言,避免任何个人意见或建议,以确保报告专注于事实描述。
|
||||
""")
|
||||
.call()
|
||||
.content();
|
||||
Assert.notBlank(description, "Description cannot be blank");
|
||||
String analysis = client.prompt()
|
||||
.system("""
|
||||
你是一名专业的IT系统运维工程师,对于用户输入的报障信息,你会给出专业的意见
|
||||
""")
|
||||
.user(StrUtil.format("""
|
||||
.user(StrUtil.format(
|
||||
"""
|
||||
[故障描述]
|
||||
{}
|
||||
|
||||
[相关截图]
|
||||
{}
|
||||
""",
|
||||
description,
|
||||
feedback.getSource(),
|
||||
ObjectUtil.isEmpty(context.getPictureDescriptions()) ? "无" : StrUtil.join(",", context.getPictureDescriptions())
|
||||
))
|
||||
.call()
|
||||
.content();
|
||||
if (StrUtil.isBlank(optimizedSource)) {
|
||||
log.warn("Optimized source is blank");
|
||||
}
|
||||
context.setOptimizedSource(optimizedSource);
|
||||
}
|
||||
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "feedback_suggest", nodeName = "大模型建议", nodeType = NodeTypeEnum.COMMON)
|
||||
public void suggestFeedback(NodeComponent node) {
|
||||
FeedbackContext context = node.getContextBean(FeedbackContext.class);
|
||||
Feedback feedback = context.getFeedback();
|
||||
ChatClient client = chatClientBuilder.build();
|
||||
String analysis = client.prompt()
|
||||
.system("""
|
||||
你是一名专业的IT系统运维工程师,对于用户输入的报障信息,你会给出专业的意见
|
||||
""")
|
||||
.user(context.getOptimizedSource())
|
||||
.call()
|
||||
.content();
|
||||
feedback.setAnalysis(analysis);
|
||||
Assert.notBlank(description, "Analysis cannot be blank");
|
||||
Assert.notBlank(analysis, "Analysis cannot be blank");
|
||||
String analysisShort = client.prompt()
|
||||
.system("""
|
||||
你是一名专业的文字编辑,对用户输入的内容,用一段话总结内容
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
feedback_check_if_picture_needed,
|
||||
image_read
|
||||
),
|
||||
optimize_source,
|
||||
feedback_suggest,
|
||||
feedback_save
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user