Skip to content

Commit

Permalink
Extract Persona Identity model into a separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonKirill authored Jan 26, 2025
2 parents 91caf32 + ca484ab commit 51f06e6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions neon_data_models/models/api/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from typing import List, Tuple, Optional, Literal
from pydantic import Field, model_validator, computed_field

Expand All @@ -33,8 +32,21 @@
_DEFAULT_MQ_TO_ROLE = {"user": "user", "llm": "assistant"}


class LLMPersona(BaseModel):
class LLMPersonaIdentity(BaseModel):
name: str = Field(description="Unique name for this persona")
user_id: Optional[str] = Field(
None, description="`user_id` of the user who created this persona.")

@computed_field
@property
def id(self) -> str:
persona_id = self.name
if self.user_id:
persona_id += f"_{self.user_id}"
return persona_id


class LLMPersona(LLMPersonaIdentity):
description: Optional[str] = Field(
None, description="Human-readable description of this persona")
system_prompt: str = Field(
Expand All @@ -43,8 +55,6 @@ class LLMPersona(BaseModel):
enabled: bool = Field(
True, description="Flag used to mark a defined persona as "
"available for use.")
user_id: Optional[str] = Field(
None, description="`user_id` of the user who created this persona.")

@model_validator(mode='after')
def validate_request(self):
Expand All @@ -53,14 +63,6 @@ def validate_request(self):
self.system_prompt = self.description
return self

@computed_field
@property
def id(self) -> str:
persona_id = self.name
if self.user_id:
persona_id += f"_{self.user_id}"
return persona_id


class LLMRequest(BaseModel):
query: str = Field(description="Incoming user prompt")
Expand Down

0 comments on commit 51f06e6

Please sign in to comment.