Skip to content

Commit

Permalink
Fixing issue with Persona Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonKirill authored Apr 1, 2024
2 parents 73e9f8a + 9bc4a90 commit e43415e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
19 changes: 12 additions & 7 deletions neon_llm_core/utils/personas/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions neon_llm_core/utils/personas/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e43415e

Please sign in to comment.