|  | @@ -7,6 +7,7 @@ import com.tzld.piaoquan.content.understanding.dao.mapper.CuPipelineStepMapper;
 | 
											
												
													
														|  |  import com.tzld.piaoquan.content.understanding.dao.mapper.CuPromptMapper;
 |  |  import com.tzld.piaoquan.content.understanding.dao.mapper.CuPromptMapper;
 | 
											
												
													
														|  |  import com.tzld.piaoquan.content.understanding.model.dto.PipelineTreeNode;
 |  |  import com.tzld.piaoquan.content.understanding.model.dto.PipelineTreeNode;
 | 
											
												
													
														|  |  import com.tzld.piaoquan.content.understanding.model.param.ActionParam;
 |  |  import com.tzld.piaoquan.content.understanding.model.param.ActionParam;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.piaoquan.content.understanding.model.param.ContentAnalyseParam;
 | 
											
												
													
														|  |  import com.tzld.piaoquan.content.understanding.model.po.CuPipelineStep;
 |  |  import com.tzld.piaoquan.content.understanding.model.po.CuPipelineStep;
 | 
											
												
													
														|  |  import com.tzld.piaoquan.content.understanding.model.po.CuPipelineStepExample;
 |  |  import com.tzld.piaoquan.content.understanding.model.po.CuPipelineStepExample;
 | 
											
												
													
														|  |  import com.tzld.piaoquan.content.understanding.model.po.CuPrompt;
 |  |  import com.tzld.piaoquan.content.understanding.model.po.CuPrompt;
 | 
											
										
											
												
													
														|  | @@ -38,8 +39,9 @@ public class PipelineServiceImpl implements PipelineService {
 | 
											
												
													
														|  |      private Map<String, Action> actionMap;
 |  |      private Map<String, Action> actionMap;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Override
 |  |      @Override
 | 
											
												
													
														|  | -    public String execute(Long pipelineId) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public void execute(ContentAnalyseParam param) {
 | 
											
												
													
														|  |          // 1.获取pipeline配置
 |  |          // 1.获取pipeline配置
 | 
											
												
													
														|  | 
 |  | +        Long pipelineId = param.getPipelineId();
 | 
											
												
													
														|  |          CuPipelineStepExample example = new CuPipelineStepExample();
 |  |          CuPipelineStepExample example = new CuPipelineStepExample();
 | 
											
												
													
														|  |          example.createCriteria().andPipelineIdEqualTo(pipelineId);
 |  |          example.createCriteria().andPipelineIdEqualTo(pipelineId);
 | 
											
												
													
														|  |          List<CuPipelineStep> stepList = cuPipelineStepMapper.selectByExample(example);
 |  |          List<CuPipelineStep> stepList = cuPipelineStepMapper.selectByExample(example);
 | 
											
										
											
												
													
														|  | @@ -49,23 +51,10 @@ public class PipelineServiceImpl implements PipelineService {
 | 
											
												
													
														|  |          // 2.构建tree结构
 |  |          // 2.构建tree结构
 | 
											
												
													
														|  |          PipelineTreeNode root = buildTree(stepList);
 |  |          PipelineTreeNode root = buildTree(stepList);
 | 
											
												
													
														|  |          // 3.按照步骤执行pipeline每一步动作
 |  |          // 3.按照步骤执行pipeline每一步动作
 | 
											
												
													
														|  | -        String result = null;
 |  | 
 | 
											
												
													
														|  | -        for (CuPipelineStep step : stepList) {
 |  | 
 | 
											
												
													
														|  | -            if (Objects.isNull(step)) {
 |  | 
 | 
											
												
													
														|  | -                throw new CommonException(ExceptionEnum.DATA_ERROR, "step is null pipelineId=" + pipelineId);
 |  | 
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  | -            Action action = actionMap.get(step);
 |  | 
 | 
											
												
													
														|  | -            if (Objects.isNull(action)) {
 |  | 
 | 
											
												
													
														|  | -                throw new CommonException(ExceptionEnum.DATA_ERROR, "action is null pipelineId=" + pipelineId);
 |  | 
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  | -            ActionParam actionParam = new ActionParam();
 |  | 
 | 
											
												
													
														|  | -            actionParam.setInput(result);
 |  | 
 | 
											
												
													
														|  | -            result = action.execute(actionParam);
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        return result;
 |  | 
 | 
											
												
													
														|  | 
 |  | +        executeTreeNodeBFS(root);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public static PipelineTreeNode buildTree(List<CuPipelineStep> stepList) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public PipelineTreeNode buildTree(List<CuPipelineStep> stepList) {
 | 
											
												
													
														|  |          Map<Long, PipelineTreeNode> nodeMap = new HashMap<>();
 |  |          Map<Long, PipelineTreeNode> nodeMap = new HashMap<>();
 | 
											
												
													
														|  |          PipelineTreeNode root = null;
 |  |          PipelineTreeNode root = null;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -95,7 +84,7 @@ public class PipelineServiceImpl implements PipelineService {
 | 
											
												
													
														|  |          return root;
 |  |          return root;
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public void processTreeNodeBFS(PipelineTreeNode root) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public void executeTreeNodeBFS(PipelineTreeNode root) {
 | 
											
												
													
														|  |          if (root == null) {
 |  |          if (root == null) {
 | 
											
												
													
														|  |              return;
 |  |              return;
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
										
											
												
													
														|  | @@ -105,26 +94,38 @@ public class PipelineServiceImpl implements PipelineService {
 | 
											
												
													
														|  |          while (!queue.isEmpty()) {
 |  |          while (!queue.isEmpty()) {
 | 
											
												
													
														|  |              PipelineTreeNode currentNode = queue.poll();
 |  |              PipelineTreeNode currentNode = queue.poll();
 | 
											
												
													
														|  |              CuPipelineStep step = currentNode.getStep();
 |  |              CuPipelineStep step = currentNode.getStep();
 | 
											
												
													
														|  | -            String input = currentNode.getInput();
 |  | 
 | 
											
												
													
														|  | 
 |  | +            String input = currentNode.getInput() == null ? "" : currentNode.getInput();
 | 
											
												
													
														|  |              // 执行action
 |  |              // 执行action
 | 
											
												
													
														|  | -//            String result = executeStep(step, input);
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | 
 |  | +            String result = executeStep(step, input);
 | 
											
												
													
														|  | 
 |  | +            if (Objects.isNull(currentNode.getChildren()) || currentNode.getChildren().isEmpty()) {
 | 
											
												
													
														|  | 
 |  | +                //TODO 保存 result
 | 
											
												
													
														|  | 
 |  | +                continue;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |              for (PipelineTreeNode child : currentNode.getChildren()) {
 |  |              for (PipelineTreeNode child : currentNode.getChildren()) {
 | 
											
												
													
														|  | 
 |  | +                child.setInput(result);
 | 
											
												
													
														|  |                  queue.offer(child);
 |  |                  queue.offer(child);
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    // 模拟执行 Pipeline Step 的方法
 |  | 
 | 
											
												
													
														|  | -    public Object executeStep(CuPipelineStep step, String input) {
 |  | 
 | 
											
												
													
														|  | -        // 这里可以根据 step 的信息 (例如 promptId) 执行实际的操作
 |  | 
 | 
											
												
													
														|  | -        // 并将 inputParameter 作为输入
 |  | 
 | 
											
												
													
														|  | -        // 返回当前步骤的执行结果
 |  | 
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * 执行step 动作
 | 
											
												
													
														|  | 
 |  | +     *
 | 
											
												
													
														|  | 
 |  | +     * @param step
 | 
											
												
													
														|  | 
 |  | +     * @param input
 | 
											
												
													
														|  | 
 |  | +     * @return
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    public String executeStep(CuPipelineStep step, String input) {
 | 
											
												
													
														|  |          CuPrompt cuPrompt = cuPromptMapper.selectByPrimaryKey(step.getPromptId());
 |  |          CuPrompt cuPrompt = cuPromptMapper.selectByPrimaryKey(step.getPromptId());
 | 
											
												
													
														|  |          if (Objects.isNull(cuPrompt) || Objects.isNull(cuPrompt.getId())) {
 |  |          if (Objects.isNull(cuPrompt) || Objects.isNull(cuPrompt.getId())) {
 | 
											
												
													
														|  |              return null;
 |  |              return null;
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -//        String prompt = String.format(cuPrompt.getPromptId(),input);
 |  | 
 | 
											
												
													
														|  | -        return "执行步骤 " + step.getId() + " (Prompt ID: " + step.getPromptId() + "), 输入: " + input;
 |  | 
 | 
											
												
													
														|  | 
 |  | +        String prompt = String.format(cuPrompt.getPrompt(), input);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        Action action = actionMap.get(step.getAction());
 | 
											
												
													
														|  | 
 |  | +        ActionParam actionParam = new ActionParam();
 | 
											
												
													
														|  | 
 |  | +        actionParam.setInput(prompt);
 | 
											
												
													
														|  | 
 |  | +        actionParam.setPrompt(prompt);
 | 
											
												
													
														|  | 
 |  | +        return action.execute(actionParam);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  }
 |  |  }
 |