@@ -416,46 +416,15 @@ def _broadcast(
416416 self .event_loop .create_task (persona .process_message (message ))
417417 return
418418
419- def on_slash_cmd_message (self , room_id : str , message : Message ):
419+ async def refresh_personas (self ):
420420 """
421- Routes & handles a message containing a slash command. Returns `True` if
422- the message specified a valid slash command recognized by
423- `PersonaManager`, `False` otherwise. Notes:
421+ Method that reloads all persona classes defined locally under
422+ `.jupyter/personas`, and re-initializes each persona class available in
423+ the current chat.
424424
425- - Each message may have exactly one slash command, which must be
426- specified by the first word of the message.
427-
428- - This method will return `True` even if the command was not handled
429- successfully. `False` is just meant to indicate that the control flow
430- should return back to `route_message()`. This allows AI personas to
431- receive custom slash commands that only they recognize.
432- """
433- first_word = get_first_word (message .body )
434- assert first_word and first_word .startswith ("/" )
435-
436- command_id = first_word [1 :]
437- if command_id == "refresh-personas" :
438- self .handle_refresh_personas_command (message )
439- return True
440-
441- # If command is unrecognized, log an error
442- self .log .warning (f"Unrecognized slash command: '/{ command_id } '" )
443- return False
444-
445- def handle_refresh_personas_command (self , _ : Message ) -> None :
425+ This method is public because it is called by `jupyter_ai_chat_commands`
426+ when the `/refresh-personas` slash command is sent.
446427 """
447- Handles the '/refresh-personas' slash command.
448-
449- TODO: How do we show status/completion in the UI?
450- """
451- self .log .info (
452- f"Received '/refresh-personas'. Refreshing personas in chat '{ self .room_id } '..."
453- )
454-
455- # Refresh personas in background task
456- asyncio .create_task (self ._refresh_personas ())
457-
458- async def _refresh_personas (self ):
459428 # Shutdown all personas
460429 await self .shutdown_personas ()
461430
0 commit comments