diff --git a/neon_llm_core/utils/personas/provider.py b/neon_llm_core/utils/personas/provider.py index aa81702..3e9f128 100644 --- a/neon_llm_core/utils/personas/provider.py +++ b/neon_llm_core/utils/personas/provider.py @@ -65,21 +65,26 @@ def personas(self): @personas.setter def personas(self, data): - now = int(time()) LOG.debug(f'Setting personas={data}') - if data and isinstance(data, list): - self._personas = data - self._persona_last_sync = now - self._persona_handlers_state.clean_up_personas(ignore_items=self._personas) - elif now - self._persona_last_sync > self.PERSONA_STATE_TTL: + if self._should_reset_personas(data=data): LOG.warning(f'Persona state TTL expired, resetting personas config') self._personas = [] self._persona_handlers_state.init_default_handlers() + else: + self._personas = data + self._persona_handlers_state.clean_up_personas(ignore_items=self._personas) + + def _should_reset_personas(self, data) -> bool: + return (not (self._persona_last_sync == 0 and data) + and int(time()) - self._persona_last_sync > self.PERSONA_STATE_TTL) def _fetch_persona_config(self): response = send_mq_request(vhost=LLM_VHOST, request_data={"service_name": self.service_name}, - target_queue=PersonasProvider.GET_CONFIGURED_PERSONAS_QUEUE) + target_queue=PersonasProvider.GET_CONFIGURED_PERSONAS_QUEUE, + timeout=60) + if 'items' in response: + self._persona_last_sync = int(time()) response_data = response.get('items', []) personas = [] for item in response_data: diff --git a/neon_llm_core/utils/personas/state.py b/neon_llm_core/utils/personas/state.py index 94be76d..103e69b 100644 --- a/neon_llm_core/utils/personas/state.py +++ b/neon_llm_core/utils/personas/state.py @@ -42,7 +42,6 @@ def __init__(self, service_name: str, ovos_config: dict): self.service_name = service_name self.ovos_config = ovos_config self.mq_config = ovos_config.get('MQ', {}) - self.init_default_handlers() def init_default_handlers(self): self._created_items = {} @@ -84,5 +83,9 @@ def clean_up_personas(self, ignore_items: List[PersonaModel] = None): ignored_persona_ids = set(persona.id for persona in ignore_items or []) personas_to_remove = connected_personas - ignored_persona_ids for persona_id in personas_to_remove: - LOG.info(f'Removing persona_id = {persona_id}') - self._created_items.pop(persona_id, None) + self.remove_persona(persona_id=persona_id) + + def remove_persona(self, persona_id: str): + LOG.info(f'Removing persona_id = {persona_id}') + self._created_items[persona_id].stop() + self._created_items.pop(persona_id, None) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 4662454..29b0f14 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,5 +1,5 @@ # networking -neon-mq-connector>=0.7.1a4 +neon-mq-connector>=0.7.2a1 ovos-utils~=0.0.32 ovos-config~=0.0.10 pydantic==2.6.3 \ No newline at end of file