@@ -81,10 +81,9 @@ def _init_persona_classes(self) -> None:
81
81
# On exception, log an error and continue.
82
82
# This does not stop the surrounding `for` loop. If a persona
83
83
# fails to load, it should not halt other personas from loading.
84
- self .log .error (
84
+ self .log .exception (
85
85
f" - Unable to load AI persona from entry point `{ persona_ep .name } ` due to an exception printed below."
86
86
)
87
- self .log .exception (e )
88
87
continue
89
88
90
89
if len (persona_classes ) > 0 :
@@ -116,26 +115,35 @@ def _init_personas(self) -> dict[str, BasePersona]:
116
115
117
116
personas : dict [str , BasePersona ] = {}
118
117
for Persona in persona_classes :
119
- persona = Persona (
120
- ychat = self .ychat ,
121
- manager = self ,
122
- config = self .config_manager ,
123
- log = self .log ,
124
- )
118
+ try :
119
+ persona = Persona (
120
+ ychat = self .ychat ,
121
+ manager = self ,
122
+ config = self .config_manager ,
123
+ log = self .log ,
124
+ )
125
+ except Exception as e :
126
+ self .log .exception (
127
+ f"The persona provided by `{ Persona .__module__ } ` "
128
+ "raised an exception while initializing, "
129
+ "printed below."
130
+ )
131
+ continue
132
+
125
133
if persona .id in personas :
126
134
class_name = persona .__class__ .__name__
127
135
self .log .warning (
128
136
f" - WARNING: Skipping persona '{ persona .name } ' from '{ persona .__module__ } ' because another persona has an identical ID '{ persona .id } '. "
129
137
+ f"Personas must all have unique IDs. Please rename the persona class from '{ class_name } ' to something unique to dismiss this warning."
130
138
)
131
139
continue
132
- else :
133
- self .log .info (
134
- f" - Initialized persona '{ persona .name } ' (ID: '{ persona .id } ')."
135
- )
136
- personas [persona .id ] = persona
137
140
138
- elapsed_time_ms = (time_ns () - start_time_ns ) // 1000
141
+ self .log .info (
142
+ f" - Initialized persona '{ persona .name } ' (ID: '{ persona .id } ')."
143
+ )
144
+ personas [persona .id ] = persona
145
+
146
+ elapsed_time_ms = (time_ns () - start_time_ns ) // 1_000_000
139
147
self .log .info (
140
148
f"SUCCESS: Initialized { len (personas )} AI personas for chat room '{ self .ychat .get_id ()} '. Time elapsed: { elapsed_time_ms } ms."
141
149
)
0 commit comments