From 9d4bdeead91556cabc30dea4588e9b277656c918 Mon Sep 17 00:00:00 2001 From: NeonKirill Date: Sat, 30 Mar 2024 19:09:58 +0100 Subject: [PATCH 1/4] stopping LLM before removing from created items --- neon_llm_core/utils/personas/state.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/neon_llm_core/utils/personas/state.py b/neon_llm_core/utils/personas/state.py index 94be76d..6eca4c8 100644 --- a/neon_llm_core/utils/personas/state.py +++ b/neon_llm_core/utils/personas/state.py @@ -84,5 +84,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) From 083d78c185504abad09effb740d439fe9da45471 Mon Sep 17 00:00:00 2001 From: NeonKirill Date: Sat, 30 Mar 2024 21:54:00 +0100 Subject: [PATCH 2/4] Fixed resolving persona data --- neon_llm_core/utils/personas/provider.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/neon_llm_core/utils/personas/provider.py b/neon_llm_core/utils/personas/provider.py index aa81702..7c2f7e6 100644 --- a/neon_llm_core/utils/personas/provider.py +++ b/neon_llm_core/utils/personas/provider.py @@ -65,21 +65,22 @@ 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 int(time()) - self._persona_last_sync > self.PERSONA_STATE_TTL: 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 _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: From 97a73895b0bd222d73a4c675dedef18b8748a3e9 Mon Sep 17 00:00:00 2001 From: NeonKirill Date: Mon, 1 Apr 2024 18:47:20 +0200 Subject: [PATCH 3/4] incremented neon mq connector dependency version --- requirements/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 9bc4a9093f005bb27678f0c4e7e0aa0f3bb4e2c5 Mon Sep 17 00:00:00 2001 From: NeonKirill Date: Mon, 1 Apr 2024 19:15:33 +0200 Subject: [PATCH 4/4] fixed issue with redundant default personas initialization --- neon_llm_core/utils/personas/provider.py | 6 +++++- neon_llm_core/utils/personas/state.py | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/neon_llm_core/utils/personas/provider.py b/neon_llm_core/utils/personas/provider.py index 7c2f7e6..3e9f128 100644 --- a/neon_llm_core/utils/personas/provider.py +++ b/neon_llm_core/utils/personas/provider.py @@ -66,7 +66,7 @@ def personas(self): @personas.setter def personas(self, data): LOG.debug(f'Setting personas={data}') - if int(time()) - 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() @@ -74,6 +74,10 @@ def personas(self, data): 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}, diff --git a/neon_llm_core/utils/personas/state.py b/neon_llm_core/utils/personas/state.py index 6eca4c8..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 = {}