ruff reformatted
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ with open(config_path, "r", encoding="utf-8") as f:
|
||||
config = toml.load(f)
|
||||
|
||||
# 现在可以导入src模块
|
||||
from src.individuality.scene import get_scene_by_factor, PERSONALITY_SCENES #noqa E402
|
||||
from src.individuality.questionnaire import FACTOR_DESCRIPTIONS #noqa E402
|
||||
from src.individuality.offline_llm import LLM_request_off #noqa E402
|
||||
from src.individuality.scene import get_scene_by_factor, PERSONALITY_SCENES # noqa E402
|
||||
from src.individuality.questionnaire import FACTOR_DESCRIPTIONS # noqa E402
|
||||
from src.individuality.offline_llm import LLM_request_off # noqa E402
|
||||
|
||||
# 加载环境变量
|
||||
env_path = os.path.join(root_path, ".env")
|
||||
@@ -32,13 +32,12 @@ else:
|
||||
|
||||
|
||||
def adapt_scene(scene: str) -> str:
|
||||
|
||||
personality_core = config['personality']['personality_core']
|
||||
personality_sides = config['personality']['personality_sides']
|
||||
personality_core = config["personality"]["personality_core"]
|
||||
personality_sides = config["personality"]["personality_sides"]
|
||||
personality_side = random.choice(personality_sides)
|
||||
identity_details = config['identity']['identity_detail']
|
||||
identity_details = config["identity"]["identity_detail"]
|
||||
identity_detail = random.choice(identity_details)
|
||||
|
||||
|
||||
"""
|
||||
根据config中的属性,改编场景使其更适合当前角色
|
||||
|
||||
@@ -51,10 +50,10 @@ def adapt_scene(scene: str) -> str:
|
||||
try:
|
||||
prompt = f"""
|
||||
这是一个参与人格测评的角色形象:
|
||||
- 昵称: {config['bot']['nickname']}
|
||||
- 性别: {config['identity']['gender']}
|
||||
- 年龄: {config['identity']['age']}岁
|
||||
- 外貌: {config['identity']['appearance']}
|
||||
- 昵称: {config["bot"]["nickname"]}
|
||||
- 性别: {config["identity"]["gender"]}
|
||||
- 年龄: {config["identity"]["age"]}岁
|
||||
- 外貌: {config["identity"]["appearance"]}
|
||||
- 性格核心: {personality_core}
|
||||
- 性格侧面: {personality_side}
|
||||
- 身份细节: {identity_detail}
|
||||
@@ -62,18 +61,18 @@ def adapt_scene(scene: str) -> str:
|
||||
请根据上述形象,改编以下场景,在测评中,用户将根据该场景给出上述角色形象的反应:
|
||||
{scene}
|
||||
保持场景的本质不变,但最好贴近生活且具体,并且让它更适合这个角色。
|
||||
改编后的场景应该自然、连贯,并考虑角色的年龄、身份和性格特点。只返回改编后的场景描述,不要包含其他说明。注意{config['bot']['nickname']}是面对这个场景的人,而不是场景的其他人。场景中不会有其描述,
|
||||
改编后的场景应该自然、连贯,并考虑角色的年龄、身份和性格特点。只返回改编后的场景描述,不要包含其他说明。注意{config["bot"]["nickname"]}是面对这个场景的人,而不是场景的其他人。场景中不会有其描述,
|
||||
现在,请你给出改编后的场景描述
|
||||
"""
|
||||
|
||||
llm = LLM_request_off(model_name=config['model']['llm_normal']['name'])
|
||||
llm = LLM_request_off(model_name=config["model"]["llm_normal"]["name"])
|
||||
adapted_scene, _ = llm.generate_response(prompt)
|
||||
|
||||
|
||||
# 检查返回的场景是否为空或错误信息
|
||||
if not adapted_scene or "错误" in adapted_scene or "失败" in adapted_scene:
|
||||
print("场景改编失败,将使用原始场景")
|
||||
return scene
|
||||
|
||||
|
||||
return adapted_scene
|
||||
except Exception as e:
|
||||
print(f"场景改编过程出错:{str(e)},将使用原始场景")
|
||||
@@ -169,7 +168,7 @@ class PersonalityEvaluator_direct:
|
||||
except Exception as e:
|
||||
print(f"评估过程出错:{str(e)}")
|
||||
return {dim: 3.5 for dim in dimensions}
|
||||
|
||||
|
||||
def run_evaluation(self):
|
||||
"""
|
||||
运行整个评估过程
|
||||
@@ -185,18 +184,23 @@ class PersonalityEvaluator_direct:
|
||||
print(f"- 身份细节:{config['identity']['identity_detail']}")
|
||||
print("\n准备好了吗?按回车键开始...")
|
||||
input()
|
||||
|
||||
|
||||
total_scenarios = len(self.scenarios)
|
||||
progress_bar = tqdm(total=total_scenarios, desc="场景进度", ncols=100, bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}]')
|
||||
progress_bar = tqdm(
|
||||
total=total_scenarios,
|
||||
desc="场景进度",
|
||||
ncols=100,
|
||||
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}]",
|
||||
)
|
||||
|
||||
for _i, scenario_data in enumerate(self.scenarios, 1):
|
||||
# print(f"\n{'-' * 20} 场景 {i}/{total_scenarios} - {scenario_data['场景编号']} {'-' * 20}")
|
||||
|
||||
|
||||
# 改编场景,使其更适合当前角色
|
||||
print(f"{config['bot']['nickname']}祈祷中...")
|
||||
adapted_scene = adapt_scene(scenario_data["场景"])
|
||||
scenario_data["改编场景"] = adapted_scene
|
||||
|
||||
|
||||
print(adapted_scene)
|
||||
print(f"\n请描述{config['bot']['nickname']}在这种情况下会如何反应:")
|
||||
response = input().strip()
|
||||
@@ -220,13 +224,13 @@ class PersonalityEvaluator_direct:
|
||||
|
||||
# 更新进度条
|
||||
progress_bar.update(1)
|
||||
|
||||
|
||||
# if i < total_scenarios:
|
||||
# print("\n按回车键继续下一个场景...")
|
||||
# input()
|
||||
|
||||
# print("\n按回车键继续下一个场景...")
|
||||
# input()
|
||||
|
||||
progress_bar.close()
|
||||
|
||||
|
||||
# 计算平均分
|
||||
for dimension in self.final_scores:
|
||||
if self.dimension_counts[dimension] > 0:
|
||||
@@ -241,26 +245,26 @@ class PersonalityEvaluator_direct:
|
||||
|
||||
# 返回评估结果
|
||||
return self.get_result()
|
||||
|
||||
|
||||
def get_result(self):
|
||||
"""
|
||||
获取评估结果
|
||||
"""
|
||||
return {
|
||||
"final_scores": self.final_scores,
|
||||
"dimension_counts": self.dimension_counts,
|
||||
"final_scores": self.final_scores,
|
||||
"dimension_counts": self.dimension_counts,
|
||||
"scenarios": self.scenarios,
|
||||
"bot_info": {
|
||||
"nickname": config['bot']['nickname'],
|
||||
"gender": config['identity']['gender'],
|
||||
"age": config['identity']['age'],
|
||||
"height": config['identity']['height'],
|
||||
"weight": config['identity']['weight'],
|
||||
"appearance": config['identity']['appearance'],
|
||||
"personality_core": config['personality']['personality_core'],
|
||||
"personality_sides": config['personality']['personality_sides'],
|
||||
"identity_detail": config['identity']['identity_detail']
|
||||
}
|
||||
"nickname": config["bot"]["nickname"],
|
||||
"gender": config["identity"]["gender"],
|
||||
"age": config["identity"]["age"],
|
||||
"height": config["identity"]["height"],
|
||||
"weight": config["identity"]["weight"],
|
||||
"appearance": config["identity"]["appearance"],
|
||||
"personality_core": config["personality"]["personality_core"],
|
||||
"personality_sides": config["personality"]["personality_sides"],
|
||||
"identity_detail": config["identity"]["identity_detail"],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -275,28 +279,28 @@ def main():
|
||||
"extraversion": round(result["final_scores"]["外向性"] / 6, 1),
|
||||
"agreeableness": round(result["final_scores"]["宜人性"] / 6, 1),
|
||||
"neuroticism": round(result["final_scores"]["神经质"] / 6, 1),
|
||||
"bot_nickname": config['bot']['nickname']
|
||||
"bot_nickname": config["bot"]["nickname"],
|
||||
}
|
||||
|
||||
# 确保目录存在
|
||||
save_dir = os.path.join(root_path, "data", "personality")
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
|
||||
|
||||
# 创建文件名,替换可能的非法字符
|
||||
bot_name = config['bot']['nickname']
|
||||
bot_name = config["bot"]["nickname"]
|
||||
# 替换Windows文件名中不允许的字符
|
||||
for char in ['\\', '/', ':', '*', '?', '"', '<', '>', '|']:
|
||||
bot_name = bot_name.replace(char, '_')
|
||||
|
||||
for char in ["\\", "/", ":", "*", "?", '"', "<", ">", "|"]:
|
||||
bot_name = bot_name.replace(char, "_")
|
||||
|
||||
file_name = f"{bot_name}_personality.per"
|
||||
save_path = os.path.join(save_dir, file_name)
|
||||
|
||||
|
||||
# 保存简化的结果
|
||||
with open(save_path, "w", encoding="utf-8") as f:
|
||||
json.dump(simplified_result, f, ensure_ascii=False, indent=4)
|
||||
|
||||
print(f"\n结果已保存到 {save_path}")
|
||||
|
||||
|
||||
# 同时保存完整结果到results目录
|
||||
os.makedirs("results", exist_ok=True)
|
||||
with open("results/personality_result.json", "w", encoding="utf-8") as f:
|
||||
|
||||
@@ -4,9 +4,11 @@ import json
|
||||
from pathlib import Path
|
||||
import random
|
||||
|
||||
|
||||
@dataclass
|
||||
class Personality:
|
||||
"""人格特质类"""
|
||||
|
||||
openness: float # 开放性
|
||||
conscientiousness: float # 尽责性
|
||||
extraversion: float # 外向性
|
||||
@@ -15,45 +17,45 @@ class Personality:
|
||||
bot_nickname: str # 机器人昵称
|
||||
personality_core: str # 人格核心特点
|
||||
personality_sides: List[str] # 人格侧面描述
|
||||
|
||||
|
||||
_instance = None
|
||||
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls._instance is None:
|
||||
cls._instance = super().__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
|
||||
def __init__(self, personality_core: str = "", personality_sides: List[str] = None):
|
||||
if personality_sides is None:
|
||||
personality_sides = []
|
||||
self.personality_core = personality_core
|
||||
self.personality_sides = personality_sides
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls) -> 'Personality':
|
||||
def get_instance(cls) -> "Personality":
|
||||
"""获取Personality单例实例
|
||||
|
||||
|
||||
Returns:
|
||||
Personality: 单例实例
|
||||
"""
|
||||
if cls._instance is None:
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
|
||||
|
||||
def _init_big_five_personality(self):
|
||||
"""初始化大五人格特质"""
|
||||
# 构建文件路径
|
||||
personality_file = Path("data/personality") / f"{self.bot_nickname}_personality.per"
|
||||
|
||||
|
||||
# 如果文件存在,读取文件
|
||||
if personality_file.exists():
|
||||
with open(personality_file, 'r', encoding='utf-8') as f:
|
||||
with open(personality_file, "r", encoding="utf-8") as f:
|
||||
personality_data = json.load(f)
|
||||
self.openness = personality_data.get('openness', 0.5)
|
||||
self.conscientiousness = personality_data.get('conscientiousness', 0.5)
|
||||
self.extraversion = personality_data.get('extraversion', 0.5)
|
||||
self.agreeableness = personality_data.get('agreeableness', 0.5)
|
||||
self.neuroticism = personality_data.get('neuroticism', 0.5)
|
||||
self.openness = personality_data.get("openness", 0.5)
|
||||
self.conscientiousness = personality_data.get("conscientiousness", 0.5)
|
||||
self.extraversion = personality_data.get("extraversion", 0.5)
|
||||
self.agreeableness = personality_data.get("agreeableness", 0.5)
|
||||
self.neuroticism = personality_data.get("neuroticism", 0.5)
|
||||
else:
|
||||
# 如果文件不存在,根据personality_core和personality_core来设置大五人格特质
|
||||
if "活泼" in self.personality_core or "开朗" in self.personality_sides:
|
||||
@@ -62,31 +64,31 @@ class Personality:
|
||||
else:
|
||||
self.extraversion = 0.3
|
||||
self.neuroticism = 0.5
|
||||
|
||||
|
||||
if "认真" in self.personality_core or "负责" in self.personality_sides:
|
||||
self.conscientiousness = 0.9
|
||||
else:
|
||||
self.conscientiousness = 0.5
|
||||
|
||||
|
||||
if "友善" in self.personality_core or "温柔" in self.personality_sides:
|
||||
self.agreeableness = 0.9
|
||||
else:
|
||||
self.agreeableness = 0.5
|
||||
|
||||
|
||||
if "创新" in self.personality_core or "开放" in self.personality_sides:
|
||||
self.openness = 0.8
|
||||
else:
|
||||
self.openness = 0.5
|
||||
|
||||
|
||||
@classmethod
|
||||
def initialize(cls, bot_nickname: str, personality_core: str, personality_sides: List[str]) -> 'Personality':
|
||||
def initialize(cls, bot_nickname: str, personality_core: str, personality_sides: List[str]) -> "Personality":
|
||||
"""初始化人格特质
|
||||
|
||||
|
||||
Args:
|
||||
bot_nickname: 机器人昵称
|
||||
personality_core: 人格核心特点
|
||||
personality_sides: 人格侧面描述
|
||||
|
||||
|
||||
Returns:
|
||||
Personality: 初始化后的人格特质实例
|
||||
"""
|
||||
@@ -96,7 +98,7 @@ class Personality:
|
||||
instance.personality_sides = personality_sides
|
||||
instance._init_big_five_personality()
|
||||
return instance
|
||||
|
||||
|
||||
def to_dict(self) -> Dict:
|
||||
"""将人格特质转换为字典格式"""
|
||||
return {
|
||||
@@ -107,18 +109,18 @@ class Personality:
|
||||
"neuroticism": self.neuroticism,
|
||||
"bot_nickname": self.bot_nickname,
|
||||
"personality_core": self.personality_core,
|
||||
"personality_sides": self.personality_sides
|
||||
"personality_sides": self.personality_sides,
|
||||
}
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: Dict) -> 'Personality':
|
||||
def from_dict(cls, data: Dict) -> "Personality":
|
||||
"""从字典创建人格特质实例"""
|
||||
instance = cls.get_instance()
|
||||
for key, value in data.items():
|
||||
setattr(instance, key, value)
|
||||
return instance
|
||||
|
||||
def get_prompt(self,x_person,level):
|
||||
return instance
|
||||
|
||||
def get_prompt(self, x_person, level):
|
||||
# 开始构建prompt
|
||||
if x_person == 2:
|
||||
prompt_personality = "你"
|
||||
@@ -126,10 +128,10 @@ class Personality:
|
||||
prompt_personality = "我"
|
||||
else:
|
||||
prompt_personality = "他"
|
||||
#person
|
||||
|
||||
# person
|
||||
|
||||
prompt_personality += self.personality_core
|
||||
|
||||
|
||||
if level == 2:
|
||||
personality_sides = self.personality_sides
|
||||
random.shuffle(personality_sides)
|
||||
@@ -140,5 +142,5 @@ class Personality:
|
||||
prompt_personality += f",{side}"
|
||||
|
||||
prompt_personality += "。"
|
||||
|
||||
|
||||
return prompt_personality
|
||||
|
||||
@@ -2,6 +2,7 @@ import json
|
||||
from typing import Dict
|
||||
import os
|
||||
|
||||
|
||||
def load_scenes() -> Dict:
|
||||
"""
|
||||
从JSON文件加载场景数据
|
||||
@@ -10,13 +11,15 @@ def load_scenes() -> Dict:
|
||||
Dict: 包含所有场景的字典
|
||||
"""
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
json_path = os.path.join(current_dir, 'template_scene.json')
|
||||
|
||||
with open(json_path, 'r', encoding='utf-8') as f:
|
||||
json_path = os.path.join(current_dir, "template_scene.json")
|
||||
|
||||
with open(json_path, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
PERSONALITY_SCENES = load_scenes()
|
||||
|
||||
|
||||
def get_scene_by_factor(factor: str) -> Dict:
|
||||
"""
|
||||
根据人格因子获取对应的情景测试
|
||||
|
||||
Reference in New Issue
Block a user