ChatLuna 事件
提示
参见 Koishi 事件
ChatLuna 也提供一些事件,用于监听和处理一些复杂的功能。
通用事件
ChatLuna 的通用会话事件。
事件:chatluna/before-check-sender
- session:
Session会话 - 返回值:
boolean是否继续处理 - 触发方式: serial
在 ChatLuna 处理会话之前,触发该事件。
当返回值为 true,ChatLuna 将不会处理该会话。
聊天事件
ChatLuna 的聊天流程事件。
事件:chatluna/before-chat
- conversationId:
string会话 ID - message:
HumanMessage用户发送的消息 - promptVariables:
ChainValues当前可用的提示词变量 - chatInterface:
ChatInterface当前聊天接口实例 - session:
Session会话 - 触发方式: parallel
在开始调用模型之前触发,可用于检查输入、动态修改提示词变量、注入提示词或提前拦截聊天流程。
事件:chatluna/after-chat
- conversationId:
string会话 ID - sourceMessage:
HumanMessage原始用户消息 - responseMessage:
AIMessage模型返回的消息 - promptVariables:
ChainValues调用时携带的提示词变量,包含chatCount等信息 - chatInterface:
ChatInterface当前聊天接口实例 - session:
Session会话 - 触发方式: parallel
在模型生成回复后触发,可用于对回复进行记录、二次处理或推送至其他系统。
事件:chatluna/clear-chat-history
- conversationId:
string会话 ID - chatInterface:
ChatInterface当前聊天接口实例 - 触发方式: parallel
当会话历史被清空时触发,方便同步清理缓存、外部存储或关联上下文。
事件:chatluna/after-chat-error
- error:
Error对话过程中捕获的异常对象 - conversationId:
string会话 ID - sourceMessage:
HumanMessage原始用户消息 - promptVariables:
ChainValues调用时的提示词变量 - chatInterface:
ChatInterface当前聊天接口实例 - chain:
ChatLunaLLMChainWrapper触发错误的链路实例(可选) - 触发方式: parallel
当聊天流程出现异常时触发,可用于日志上报、兜底回复或通知维护者。
生命周期事件
ChatLuna 的生命周期事件,监听某些模型或者工具的变化。
事件:chatluna/chat-chain-added
- service:
PlatformService平台服务 - chain:
ChatLunaChainInfo聊天链信息 - 触发方式: emit
当一个聊天链(聊天模式)被添加时,触发该事件。
事件:chatluna/chat-chain-removed
- service:
PlatformService平台服务 - chain:
ChatLunaChainInfo聊天链信息 - 触发方式: emit
当一个聊天链(聊天模式)被移除时,触发该事件。
事件:chatluna/tool-updated
- service:
PlatformService平台服务 - 触发方式: emit
当有工具被添加或移除时,触发该事件。
事件:chatluna/model-added
- service:
PlatformService平台服务 - platform:
PlatformClientNames被添加的平台 - client:
BasePlatformClient | BasePlatformClient[]被添加的平台 Client 实现 - 触发方式: emit
当有模型(适配器)被添加时,触发该事件。
事件:chatluna/model-removed
- service:
PlatformService平台服务 - platform:
PlatformClientNames被移除的平台 - client:
BasePlatformClient | BasePlatformClient[]被移除的平台 Client 实现 - 触发方式: emit
当有模型(适配器)被移除时,触发该事件。
事件:chatluna/embeddings-added
- service:
PlatformService平台服务 - platform:
PlatformClientNames被添加的平台 - client:
BasePlatformClient | BasePlatformClient[]被添加的平台 Client 实现 - 触发方式: emit
当有嵌入模型(适配器)被添加时,触发该事件。
事件:chatluna/embeddings-removed
- service:
PlatformService平台服务 - platform:
PlatformClientNames被移除的平台 - client:
BasePlatformClient | BasePlatformClient[]被移除的平台 Client 实现 - 触发方式: emit
当有嵌入模型(适配器)被移除时,触发该事件。
事件:chatluna/vector-store-added
- service:
PlatformService平台服务 - name:
string向量存储数据名称 - 触发方式: emit
当有向量存储数据库被添加时,触发该事件。
事件:chatluna/vector-store-removed
- service:
PlatformService平台服务 - name:
string向量存储数据名称 - 触发方式: emit
当有向量存储数据库被移除时,触发该事件。