Skip to content

Commit

Permalink
Merge branch 'chuanSir123/refactoring-v3-mvp' into refactoring-v3-mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
lss233 committed Feb 16, 2025
2 parents 9e87134 + d744593 commit 2987efa
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 123 deletions.
90 changes: 61 additions & 29 deletions data/dispatch_rules/rules.yaml
Original file line number Diff line number Diff line change
@@ -1,90 +1,122 @@
- rule_id: chat_normal
name: 普通聊天
description: 普通聊天,使用默认参数
type: prefix
priority: 5
workflow_id: chat:normal
priority: 5
enabled: true
rule_groups:
- operator: and
rules:
- type: prefix
config:
prefix: /chat
metadata:
category: chat
permission: user
temperature: 0.7
prefix: /chat
- rule_id: chat_creative
name: 创意聊天
description: 创意聊天,使用更高的温度参数
type: keyword
priority: 5
workflow_id: chat:creative
priority: 5
enabled: true
rule_groups:
- operator: and
rules:
- type: keyword
config:
keywords:
- 创意
- 发散
- brainstorm
metadata:
category: chat
permission: user
temperature: 0.9
keywords:
- 创意
- 发散
- brainstorm
- rule_id: chat_roleplay
name: 角色扮演
description: 角色扮演聊天,自动提取角色设定
type: regex
priority: 8
workflow_id: chat:roleplay
priority: 8
enabled: true
rule_groups:
- operator: and
rules:
- type: regex
config:
pattern: ^扮演(.+?)[::]
metadata:
category: chat
permission: user
temperature: 0.8
pattern: ^扮演(.+?)[::]
- rule_id: game_dice
name: 骰子
description: 骰子游戏,支持 XdY 格式
type: regex
priority: 5
workflow_id: game:dice
priority: 5
enabled: true
rule_groups:
- operator: and
rules:
- type: regex
config:
pattern: ^[.。]roll\s*(\d+)?d(\d+)
metadata: {}
pattern: ^[.。]roll\s*(\d+)?d(\d+)
- rule_id: game_gacha
name: 抽卡
description: 抽卡模拟器
type: keyword
priority: 5
workflow_id: game:gacha
priority: 5
enabled: true
rule_groups:
- operator: and
rules:
- type: keyword
config:
keywords:
- 抽卡
- 十连
- 单抽
metadata: {}
keywords:
- 抽卡
- 十连
- 单抽
- rule_id: system_help
name: 帮助命令
description: 显示帮助信息
type: prefix
priority: 10
workflow_id: system:help
priority: 10
enabled: true
rule_groups:
- operator: and
rules:
- type: prefix
config:
prefix: /help
metadata:
category: system
permission: user
prefix: /help
- rule_id: system_clear_memory
name: 清空记忆
description: 清空当前对话的记忆
type: prefix
priority: 10
workflow_id: system:clear_memory
priority: 10
enabled: true
rule_groups:
- operator: and
rules:
- type: prefix
config:
prefix: /清空记忆
metadata:
category: system
permission: user
prefix: /清空记忆
- rule_id: fallback
name: 默认规则
description: 当上述规则均没有匹配成功时,执行此工作流。
type: fallback
workflow_id: chat:memory_store
priority: 0
workflow_id: chat:normal
enabled: true
rule_groups:
- operator: and
rules:
- type: fallback
config: {}
metadata: {}
21 changes: 21 additions & 0 deletions data/workflows/chat/memory_store.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 记录聊天内容
description: 默默记下大家的聊天内容,可以使用查询记忆模块读取出来。
blocks:
- type: internal:get_message
name: 6233e64c-433e-4087-9035-cb96914349f7
params: {}
position:
x: 100
y: 138
connected_to:
- target: 86354196-f249-4393-9620-941b01bc344e
mapping:
from: msg
to: user_msg
- type: internal:chat_memory_store
name: 86354196-f249-4393-9620-941b01bc344e
params:
scope_type: group
position:
x: 420
y: 138
28 changes: 16 additions & 12 deletions framework/workflow/core/dispatch/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@ async def dispatch(self, source: IMAdapter, message: IMMessage):

for rule in active_rules:
if rule.match(message, self.workflow_registry):
self.logger.debug(f"Matched rule {rule}, executing workflow")
with self.container.scoped() as scoped_container:
scoped_container.register(IMAdapter, source)
scoped_container.register(IMMessage, message)
workflow = rule.get_workflow(scoped_container)
executor = WorkflowExecutor(workflow)
scoped_container.register(Workflow, workflow)
scoped_container.register(WorkflowExecutor, executor)
try:
try:
self.logger.debug(f"Matched rule {rule}, executing workflow")
with self.container.scoped() as scoped_container:
scoped_container.register(IMAdapter, source)
scoped_container.register(IMMessage, message)
workflow = rule.get_workflow(scoped_container)
if workflow is None:
self.logger.error(f"Workflow {rule} not found")
continue
executor = WorkflowExecutor(workflow)
scoped_container.register(Workflow, workflow)
scoped_container.register(WorkflowExecutor, executor)
return await executor.run()
except Exception as e:
self.logger.error(f"Workflow execution failed: {e}")
raise e
except Exception as e:
self.logger.exception(e)
self.logger.error(f"Workflow execution failed: {e}")
raise e
self.logger.debug("No matching rule found for message")
return None
Loading

0 comments on commit 2987efa

Please sign in to comment.