ruff reformatted
This commit is contained in:
@@ -2,35 +2,46 @@ from typing import Optional
|
||||
from .personality import Personality
|
||||
from .identity import Identity
|
||||
|
||||
|
||||
class Individuality:
|
||||
"""个体特征管理类"""
|
||||
|
||||
_instance = None
|
||||
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls._instance is None:
|
||||
cls._instance = super().__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.personality: Optional[Personality] = None
|
||||
self.identity: Optional[Identity] = None
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls) -> 'Individuality':
|
||||
def get_instance(cls) -> "Individuality":
|
||||
"""获取Individuality单例实例
|
||||
|
||||
|
||||
Returns:
|
||||
Individuality: 单例实例
|
||||
"""
|
||||
if cls._instance is None:
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
|
||||
def initialize(self, bot_nickname: str, personality_core: str, personality_sides: list,
|
||||
identity_detail: list, height: int, weight: int, age: int,
|
||||
gender: str, appearance: str) -> None:
|
||||
|
||||
def initialize(
|
||||
self,
|
||||
bot_nickname: str,
|
||||
personality_core: str,
|
||||
personality_sides: list,
|
||||
identity_detail: list,
|
||||
height: int,
|
||||
weight: int,
|
||||
age: int,
|
||||
gender: str,
|
||||
appearance: str,
|
||||
) -> None:
|
||||
"""初始化个体特征
|
||||
|
||||
|
||||
Args:
|
||||
bot_nickname: 机器人昵称
|
||||
personality_core: 人格核心特点
|
||||
@@ -44,50 +55,43 @@ class Individuality:
|
||||
"""
|
||||
# 初始化人格
|
||||
self.personality = Personality.initialize(
|
||||
bot_nickname=bot_nickname,
|
||||
personality_core=personality_core,
|
||||
personality_sides=personality_sides
|
||||
bot_nickname=bot_nickname, personality_core=personality_core, personality_sides=personality_sides
|
||||
)
|
||||
|
||||
|
||||
# 初始化身份
|
||||
self.identity = Identity.initialize(
|
||||
identity_detail=identity_detail,
|
||||
height=height,
|
||||
weight=weight,
|
||||
age=age,
|
||||
gender=gender,
|
||||
appearance=appearance
|
||||
identity_detail=identity_detail, height=height, weight=weight, age=age, gender=gender, appearance=appearance
|
||||
)
|
||||
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""将个体特征转换为字典格式"""
|
||||
return {
|
||||
"personality": self.personality.to_dict() if self.personality else None,
|
||||
"identity": self.identity.to_dict() if self.identity else None
|
||||
"identity": self.identity.to_dict() if self.identity else None,
|
||||
}
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict) -> 'Individuality':
|
||||
def from_dict(cls, data: dict) -> "Individuality":
|
||||
"""从字典创建个体特征实例"""
|
||||
instance = cls.get_instance()
|
||||
if data.get("personality"):
|
||||
instance.personality = Personality.from_dict(data["personality"])
|
||||
if data.get("identity"):
|
||||
instance.identity = Identity.from_dict(data["identity"])
|
||||
return instance
|
||||
|
||||
def get_prompt(self,type,x_person,level):
|
||||
return instance
|
||||
|
||||
def get_prompt(self, type, x_person, level):
|
||||
"""
|
||||
获取个体特征的prompt
|
||||
"""
|
||||
if type == "personality":
|
||||
return self.personality.get_prompt(x_person,level)
|
||||
return self.personality.get_prompt(x_person, level)
|
||||
elif type == "identity":
|
||||
return self.identity.get_prompt(x_person,level)
|
||||
return self.identity.get_prompt(x_person, level)
|
||||
else:
|
||||
return ""
|
||||
|
||||
def get_traits(self,factor):
|
||||
|
||||
def get_traits(self, factor):
|
||||
"""
|
||||
获取个体特征的特质
|
||||
"""
|
||||
@@ -101,5 +105,3 @@ class Individuality:
|
||||
return self.personality.agreeableness
|
||||
elif factor == "neuroticism":
|
||||
return self.personality.neuroticism
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user