@@ -61,7 +61,7 @@ def __init__(self, route: ModelRoute, mux_rule: mux_models.MuxRule):
61
61
self ._mux_rule = mux_rule
62
62
63
63
@abstractmethod
64
- def match (self , thing_to_match : mux_models .ThingToMatchMux ) -> bool :
64
+ async def match (self , thing_to_match : mux_models .ThingToMatchMux ) -> bool :
65
65
"""Return True if the rule matches the thing_to_match."""
66
66
pass
67
67
@@ -97,7 +97,7 @@ def create(db_mux_rule: db_models.MuxRule, route: ModelRoute) -> MuxingRuleMatch
97
97
class CatchAllMuxingRuleMatcher (MuxingRuleMatcher ):
98
98
"""A catch all muxing rule matcher."""
99
99
100
- def match (self , thing_to_match : mux_models .ThingToMatchMux ) -> bool :
100
+ async def match (self , thing_to_match : mux_models .ThingToMatchMux ) -> bool :
101
101
logger .info ("Catch all rule matched" )
102
102
return True
103
103
@@ -132,7 +132,7 @@ def _is_matcher_in_filenames(self, detected_client: ClientType, data: dict) -> b
132
132
)
133
133
return is_filename_match
134
134
135
- def match (self , thing_to_match : mux_models .ThingToMatchMux ) -> bool :
135
+ async def match (self , thing_to_match : mux_models .ThingToMatchMux ) -> bool :
136
136
"""
137
137
Return True if the matcher is in one of the request filenames.
138
138
"""
@@ -156,7 +156,7 @@ def _is_request_type_match(self, is_fim_request: bool) -> bool:
156
156
return True
157
157
return False
158
158
159
- def match (self , thing_to_match : mux_models .ThingToMatchMux ) -> bool :
159
+ async def match (self , thing_to_match : mux_models .ThingToMatchMux ) -> bool :
160
160
"""
161
161
Return True if the matcher is in one of the request filenames and
162
162
if the request type matches the MuxMatcherType.
@@ -194,7 +194,7 @@ def _get_user_messages_from_body(self, body: Dict) -> List[str]:
194
194
user_messages .append (msgs_content )
195
195
return user_messages
196
196
197
- def match (self , thing_to_match : mux_models .ThingToMatchMux ) -> bool :
197
+ async def match (self , thing_to_match : mux_models .ThingToMatchMux ) -> bool :
198
198
"""
199
199
Return True if the matcher is the persona description matched with the
200
200
user messages.
@@ -204,14 +204,11 @@ def match(self, thing_to_match: mux_models.ThingToMatchMux) -> bool:
204
204
return False
205
205
206
206
persona_manager = PersonaManager ()
207
- is_persona_matched = persona_manager .check_persona_match (
207
+ is_persona_matched = await persona_manager .check_persona_match (
208
208
persona_name = self ._mux_rule .matcher , queries = user_messages
209
209
)
210
- logger .info (
211
- "Persona rule matched" ,
212
- matcher = self ._mux_rule .matcher ,
213
- is_persona_matched = is_persona_matched ,
214
- )
210
+ if is_persona_matched :
211
+ logger .info ("Persona rule matched" , persona = self ._mux_rule .matcher )
215
212
return is_persona_matched
216
213
217
214
@@ -258,7 +255,7 @@ async def get_match_for_active_workspace(
258
255
try :
259
256
rules = await self .get_ws_rules (self ._active_workspace )
260
257
for rule in rules :
261
- if rule .match (thing_to_match ):
258
+ if await rule .match (thing_to_match ):
262
259
return rule .destination ()
263
260
return None
264
261
except KeyError :
0 commit comments