Skip to content

Commit

Permalink
Updated neon_data_models references
Browse files Browse the repository at this point in the history
  • Loading branch information
kirgrim committed Jan 26, 2025
1 parent 2cc7264 commit d412032
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
7 changes: 5 additions & 2 deletions neon_llm_core/rmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
from neon_mq_connector.utils.rabbit_utils import create_mq_callback
from neon_utils.logger import LOG

from neon_data_models.models.api.mq import (LLMProposeResponse,
LLMDiscussResponse, LLMVoteResponse)
from neon_data_models.models.api.mq import (
LLMProposeResponse,
LLMDiscussResponse,
LLMVoteResponse,
)

from neon_llm_core.utils.config import load_config
from neon_llm_core.llm import NeonLLM
Expand Down
18 changes: 11 additions & 7 deletions neon_llm_core/utils/personas/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@
from time import time
from typing import List

from neon_data_models.models.api.llm import (
LLMPersona,
LLMPersonaIdentity,
)

from neon_mq_connector.utils import RepeatingTimer
from neon_mq_connector.utils.client_utils import send_mq_request
from neon_utils.logger import LOG

from neon_llm_core.utils.constants import LLM_VHOST
from neon_llm_core.utils.personas.models import PersonaModel, PersonaDeleteModel
from neon_llm_core.utils.personas.state import PersonaHandlersState


Expand Down Expand Up @@ -65,11 +69,11 @@ def persona_sync_thread(self) -> RepeatingTimer:
return self._persona_sync_thread

@property
def personas(self) -> List[PersonaModel]:
def personas(self) -> List[LLMPersona]:
return self._personas

@personas.setter
def personas(self, data: List[PersonaModel]):
def personas(self, data: List[LLMPersona]):
LOG.debug(f'Setting personas={data}')
if self._should_reset_personas(data=data):
LOG.warning(f'Persona state expired, setting default personas')
Expand All @@ -79,7 +83,7 @@ def personas(self, data: List[PersonaModel]):
self._personas = data
self._persona_handlers_state.clean_up_personas(ignore_items=self._personas)

def _should_reset_personas(self, data: List[PersonaModel]) -> bool:
def _should_reset_personas(self, data: List[LLMPersona]) -> bool:
"""
Checks if personas should be re-initialized after setting a new value
for personas.
Expand Down Expand Up @@ -154,7 +158,7 @@ def parse_persona_response(self, persona_response: dict):
personas.append(persona)
self.personas = personas

def apply_incoming_persona_data(self, persona_data: dict) -> PersonaModel:
def apply_incoming_persona_data(self, persona_data: dict) -> LLMPersona:
"""
Apply and update incoming persona data and return an updated PersonaModel instance.
Expand All @@ -170,7 +174,7 @@ def apply_incoming_persona_data(self, persona_data: dict) -> PersonaModel:
returns: A validated and updated `PersonaModel` instance based on the provided input data.
"""
persona_data.setdefault('name', persona_data.pop('persona_name', None))
persona = PersonaModel.model_validate(obj=persona_data)
persona = LLMPersona.model_validate(obj=persona_data)
self._persona_handlers_state.add_persona_handler(persona=persona)
LOG.info(f"Persona {persona.id} updated successfully")
return persona
Expand All @@ -188,7 +192,7 @@ def remove_persona(self, persona_data: dict):
if (self._persona_handlers_state.has_connected_personas() and
not self._persona_handlers_state.default_personas_running):
persona_data.setdefault('name', persona_data.pop('persona_name', None))
persona = PersonaDeleteModel.model_validate(obj=persona_data)
persona = LLMPersonaIdentity.model_validate(obj=persona_data)
self._persona_handlers_state.remove_persona(persona_id=persona.id)
LOG.info(f"Persona {persona.id} removed successfully")

Expand Down
9 changes: 4 additions & 5 deletions neon_llm_core/utils/personas/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
from threading import Lock
from typing import Dict, List, Optional

from neon_data_models.models.api.llm import LLMPersona
from neon_utils.logger import LOG

from neon_llm_core.chatbot import LLMBot
from neon_llm_core.utils.personas.models import PersonaModel


class PersonaHandlersState:
Expand Down Expand Up @@ -69,11 +68,11 @@ def init_default_personas(self):
LOG.info(f"Initializing default personas for: {self.service_name}")
for persona in self.default_personas:
self.add_persona_handler(
persona=PersonaModel.model_validate(obj=persona)
persona=LLMPersona.model_validate(obj=persona)
)
self.default_personas_running = True

def add_persona_handler(self, persona: PersonaModel) -> Optional[LLMBot]:
def add_persona_handler(self, persona: LLMPersona) -> Optional[LLMBot]:
"""
Creates an `LLMBot` instance for the given persona if the persona does
not yet exist AND the persona is not disabled in configuration.
Expand Down Expand Up @@ -109,7 +108,7 @@ def add_persona_handler(self, persona: PersonaModel) -> Optional[LLMBot]:
self._created_items[persona.id] = bot
return bot

def clean_up_personas(self, ignore_items: List[PersonaModel] = None):
def clean_up_personas(self, ignore_items: List[LLMPersona] = None):
with self.personas_clean_up_lock:
connected_personas = set(self._created_items)
ignored_persona_ids = set(persona.id for persona in ignore_items or [])
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ neon-mq-connector>=0.7.2a17
neon_utils[sentry]~=1.12
ovos-config~=0.0,>=0.0.10
pydantic~=2.6
neon-data-models>=0.0.0a5
neon-data-models>=0.0.0a7

0 comments on commit d412032

Please sign in to comment.