ruff reformatted

This commit is contained in:
春河晴
2025-04-08 15:31:13 +09:00
parent 0d7068acab
commit 7840a6080d
40 changed files with 1227 additions and 1336 deletions

View File

@@ -2,27 +2,36 @@ from dataclasses import dataclass
from typing import List
import random
@dataclass
class Identity:
"""身份特征类"""
identity_detail: List[str] # 身份细节描述
height: int # 身高(厘米)
weight: int # 体重(千克)
age: int # 年龄
gender: str # 性别
appearance: str # 外貌特征
_instance = None
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance
def __init__(self, identity_detail: List[str] = None, height: int = 0, weight: int = 0,
age: int = 0, gender: str = "", appearance: str = ""):
def __init__(
self,
identity_detail: List[str] = None,
height: int = 0,
weight: int = 0,
age: int = 0,
gender: str = "",
appearance: str = "",
):
"""初始化身份特征
Args:
identity_detail: 身份细节描述列表
height: 身高(厘米)
@@ -39,23 +48,24 @@ class Identity:
self.age = age
self.gender = gender
self.appearance = appearance
@classmethod
def get_instance(cls) -> 'Identity':
def get_instance(cls) -> "Identity":
"""获取Identity单例实例
Returns:
Identity: 单例实例
"""
if cls._instance is None:
cls._instance = cls()
return cls._instance
@classmethod
def initialize(cls, identity_detail: List[str], height: int, weight: int,
age: int, gender: str, appearance: str) -> 'Identity':
def initialize(
cls, identity_detail: List[str], height: int, weight: int, age: int, gender: str, appearance: str
) -> "Identity":
"""初始化身份特征
Args:
identity_detail: 身份细节描述列表
height: 身高(厘米)
@@ -63,7 +73,7 @@ class Identity:
age: 年龄
gender: 性别
appearance: 外貌特征
Returns:
Identity: 初始化后的身份特征实例
"""
@@ -75,8 +85,8 @@ class Identity:
instance.gender = gender
instance.appearance = appearance
return instance
def get_prompt(self,x_person,level):
def get_prompt(self, x_person, level):
"""
获取身份特征的prompt
"""
@@ -86,7 +96,7 @@ class Identity:
prompt_identity = ""
else:
prompt_identity = ""
if level == 1:
identity_detail = self.identity_detail
random.shuffle(identity_detail)
@@ -96,7 +106,7 @@ class Identity:
prompt_identity += f",{detail}"
prompt_identity += ""
return prompt_identity
def to_dict(self) -> dict:
"""将身份特征转换为字典格式"""
return {
@@ -105,13 +115,13 @@ class Identity:
"weight": self.weight,
"age": self.age,
"gender": self.gender,
"appearance": self.appearance
"appearance": self.appearance,
}
@classmethod
def from_dict(cls, data: dict) -> 'Identity':
def from_dict(cls, data: dict) -> "Identity":
"""从字典创建身份特征实例"""
instance = cls.get_instance()
for key, value in data.items():
setattr(instance, key, value)
return instance
return instance