Skip to content

Commit 2987efa

Browse files
committed
Merge branch 'chuanSir123/refactoring-v3-mvp' into refactoring-v3-mvp
2 parents 9e87134 + d744593 commit 2987efa

File tree

11 files changed

+212
-123
lines changed

11 files changed

+212
-123
lines changed

data/dispatch_rules/rules.yaml

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,122 @@
11
- rule_id: chat_normal
22
name: 普通聊天
33
description: 普通聊天,使用默认参数
4-
type: prefix
5-
priority: 5
64
workflow_id: chat:normal
5+
priority: 5
76
enabled: true
7+
rule_groups:
8+
- operator: and
9+
rules:
10+
- type: prefix
11+
config:
12+
prefix: /chat
813
metadata:
914
category: chat
1015
permission: user
1116
temperature: 0.7
12-
prefix: /chat
1317
- rule_id: chat_creative
1418
name: 创意聊天
1519
description: 创意聊天,使用更高的温度参数
16-
type: keyword
17-
priority: 5
1820
workflow_id: chat:creative
21+
priority: 5
1922
enabled: true
23+
rule_groups:
24+
- operator: and
25+
rules:
26+
- type: keyword
27+
config:
28+
keywords:
29+
- 创意
30+
- 发散
31+
- brainstorm
2032
metadata:
2133
category: chat
2234
permission: user
2335
temperature: 0.9
24-
keywords:
25-
- 创意
26-
- 发散
27-
- brainstorm
2836
- rule_id: chat_roleplay
2937
name: 角色扮演
3038
description: 角色扮演聊天,自动提取角色设定
31-
type: regex
32-
priority: 8
3339
workflow_id: chat:roleplay
40+
priority: 8
3441
enabled: true
42+
rule_groups:
43+
- operator: and
44+
rules:
45+
- type: regex
46+
config:
47+
pattern: ^扮演(.+?)[::]
3548
metadata:
3649
category: chat
3750
permission: user
3851
temperature: 0.8
39-
pattern: ^扮演(.+?)[::]
4052
- rule_id: game_dice
4153
name: 骰子
4254
description: 骰子游戏,支持 XdY 格式
43-
type: regex
44-
priority: 5
4555
workflow_id: game:dice
56+
priority: 5
4657
enabled: true
58+
rule_groups:
59+
- operator: and
60+
rules:
61+
- type: regex
62+
config:
63+
pattern: ^[.。]roll\s*(\d+)?d(\d+)
4764
metadata: {}
48-
pattern: ^[.。]roll\s*(\d+)?d(\d+)
4965
- rule_id: game_gacha
5066
name: 抽卡
5167
description: 抽卡模拟器
52-
type: keyword
53-
priority: 5
5468
workflow_id: game:gacha
69+
priority: 5
5570
enabled: true
71+
rule_groups:
72+
- operator: and
73+
rules:
74+
- type: keyword
75+
config:
76+
keywords:
77+
- 抽卡
78+
- 十连
79+
- 单抽
5680
metadata: {}
57-
keywords:
58-
- 抽卡
59-
- 十连
60-
- 单抽
6181
- rule_id: system_help
6282
name: 帮助命令
6383
description: 显示帮助信息
64-
type: prefix
65-
priority: 10
6684
workflow_id: system:help
85+
priority: 10
6786
enabled: true
87+
rule_groups:
88+
- operator: and
89+
rules:
90+
- type: prefix
91+
config:
92+
prefix: /help
6893
metadata:
6994
category: system
7095
permission: user
71-
prefix: /help
7296
- rule_id: system_clear_memory
7397
name: 清空记忆
7498
description: 清空当前对话的记忆
75-
type: prefix
76-
priority: 10
7799
workflow_id: system:clear_memory
100+
priority: 10
78101
enabled: true
102+
rule_groups:
103+
- operator: and
104+
rules:
105+
- type: prefix
106+
config:
107+
prefix: /清空记忆
79108
metadata:
80109
category: system
81110
permission: user
82-
prefix: /清空记忆
83111
- rule_id: fallback
84112
name: 默认规则
85113
description: 当上述规则均没有匹配成功时,执行此工作流。
86-
type: fallback
114+
workflow_id: chat:memory_store
87115
priority: 0
88-
workflow_id: chat:normal
89116
enabled: true
117+
rule_groups:
118+
- operator: and
119+
rules:
120+
- type: fallback
121+
config: {}
90122
metadata: {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 记录聊天内容
2+
description: 默默记下大家的聊天内容,可以使用查询记忆模块读取出来。
3+
blocks:
4+
- type: internal:get_message
5+
name: 6233e64c-433e-4087-9035-cb96914349f7
6+
params: {}
7+
position:
8+
x: 100
9+
y: 138
10+
connected_to:
11+
- target: 86354196-f249-4393-9620-941b01bc344e
12+
mapping:
13+
from: msg
14+
to: user_msg
15+
- type: internal:chat_memory_store
16+
name: 86354196-f249-4393-9620-941b01bc344e
17+
params:
18+
scope_type: group
19+
position:
20+
x: 420
21+
y: 138

framework/workflow/core/dispatch/dispatcher.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,22 @@ async def dispatch(self, source: IMAdapter, message: IMMessage):
3232

3333
for rule in active_rules:
3434
if rule.match(message, self.workflow_registry):
35-
self.logger.debug(f"Matched rule {rule}, executing workflow")
36-
with self.container.scoped() as scoped_container:
37-
scoped_container.register(IMAdapter, source)
38-
scoped_container.register(IMMessage, message)
39-
workflow = rule.get_workflow(scoped_container)
40-
executor = WorkflowExecutor(workflow)
41-
scoped_container.register(Workflow, workflow)
42-
scoped_container.register(WorkflowExecutor, executor)
43-
try:
35+
try:
36+
self.logger.debug(f"Matched rule {rule}, executing workflow")
37+
with self.container.scoped() as scoped_container:
38+
scoped_container.register(IMAdapter, source)
39+
scoped_container.register(IMMessage, message)
40+
workflow = rule.get_workflow(scoped_container)
41+
if workflow is None:
42+
self.logger.error(f"Workflow {rule} not found")
43+
continue
44+
executor = WorkflowExecutor(workflow)
45+
scoped_container.register(Workflow, workflow)
46+
scoped_container.register(WorkflowExecutor, executor)
4447
return await executor.run()
45-
except Exception as e:
46-
self.logger.error(f"Workflow execution failed: {e}")
47-
raise e
48+
except Exception as e:
49+
self.logger.exception(e)
50+
self.logger.error(f"Workflow execution failed: {e}")
51+
raise e
4852
self.logger.debug("No matching rule found for message")
4953
return None

0 commit comments

Comments
 (0)