dify-spring-boot-starter
  • Guide
  • Getting-started
  • Install
  • Configure
  • Client Builder
  • Features

    • Chat API
    • Workflow API
    • Dataset API
    • Server API
  • Event

    • Instructions
    • Chat event
  • Using configurations
  • Customized Configuration
  • v1.x-SNAPSHOT
  • v0.x
  • Changelog
  • 简体中文
  • English
GitHub
  • Guide
  • Getting-started
  • Install
  • Configure
  • Client Builder
  • Features

    • Chat API
    • Workflow API
    • Dataset API
    • Server API
  • Event

    • Instructions
    • Chat event
  • Using configurations
  • Customized Configuration
  • v1.x-SNAPSHOT
  • v0.x
  • Changelog
  • 简体中文
  • English
GitHub
  • Guide

    • Guide
    • Getting-started
    • Install
    • Configure
    • Client Builder
  • Features

    • Chat API
    • Workflow API
    • Dataset API
    • Server API
  • Event

    • Instructions
    • Chat event

How to Use

Using the spring scan instance, implement the PipelineProcess interface, specifying the generic type as ChatMessagePipelineModel.

Currently only calls to sendChatMessageStream trigger the corresponding chat event.

@Slf4j
@Component
public class ChatInterceptor implements PipelineProcess<ChatMessagePipelineModel> {

    /**
     * 处理
     *
     * @param context 内容
     */
    @Override
    public void process(PipelineContext<ChatMessagePipelineModel> context) {
        log.debug("ChatInterceptor context:{}", context);
    }
}

Custom Filters

Override the support method to implement custom filtering logic


@Slf4j
@Component
public class ChatInterceptor implements PipelineProcess<ChatMessagePipelineModel> {

    /**
     * 是否支持
     *
     * @param context 内容
     * @return 是否支持 true 支持 false 不支持
     */
    @Override
    public boolean support(PipelineContext<ChatMessagePipelineModel> context) {
        return "message_end".equals(context.getModel().getEvent());
    }

    /**
     * 处理
     *
     * @param context 内容
     */
    @Override
    public void process(PipelineContext<ChatMessagePipelineModel> context) {
        log.debug("ChatInterceptor context:{}", context);
    }
}

Customize the execution order

Override the order method, which returns a sort value. The smaller the value, the earlier it is executed.

@Slf4j
@Component
public class ChatInterceptor implements PipelineProcess<ChatMessagePipelineModel> {

    /**
     * 获取排序,越小越靠前
     *
     * @return 排序
     */
    @Override
    public Long order() {
        return 233L;
    }
    
    /**
     * 是否支持
     *
     * @param context 内容
     * @return 是否支持 true 支持 false 不支持
     */
    @Override
    public boolean support(PipelineContext<ChatMessagePipelineModel> context) {
        return "message_end".equals(context.getModel().getEvent());
    }
    
    /**
     * 处理
     *
     * @param context 内容
     */
    @Override
    public void process(PipelineContext<ChatMessagePipelineModel> context) {
        log.debug("ChatInterceptor context:{}", context);
    }
}
Edit this page on GitHub
Last Updated: 2025/8/26 05:42
Prev
Instructions