add game configs
This commit is contained in:
0
src/classes/item.py
Normal file
0
src/classes/item.py
Normal file
@@ -1,6 +1,7 @@
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from src.utils.df import game_configs
|
||||||
|
|
||||||
# TODO: 配表化
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Persona:
|
class Persona:
|
||||||
"""
|
"""
|
||||||
@@ -10,24 +11,25 @@ class Persona:
|
|||||||
name: str
|
name: str
|
||||||
prompt: str
|
prompt: str
|
||||||
|
|
||||||
personas_by_id: dict[int, Persona] = {}
|
def _load_personas() -> tuple[dict[int, Persona], dict[str, Persona]]:
|
||||||
personas_by_name: dict[str, Persona] = {}
|
"""从配表加载persona数据"""
|
||||||
p1 = Persona(id=1, name="理性", prompt="你是一个理性的人,你总是会用逻辑来思考问题,做事会谋定而后动。")
|
personas_by_id: dict[int, Persona] = {}
|
||||||
p2 = Persona(id=2, name="无常", prompt="你是一个无常的人,目标飘忽不定,不会长期坚持一个目标。")
|
personas_by_name: dict[str, Persona] = {}
|
||||||
p3 = Persona(id=3, name="怠惰", prompt="你是一个怠惰的人,你总是会拖延,不想努力,更热衷于享受人生。")
|
|
||||||
p4 = Persona(id=4, name="冒险", prompt="你是一个冒险的人,你总是会冒险,喜欢刺激,总想放手一搏。")
|
persona_df = game_configs["persona"]
|
||||||
p5 = Persona(id=5, name="随性", prompt="你是一个随性的人,你总是会随机应变,性子到哪里了就是哪里,没有一定痣规。")
|
for _, row in persona_df.iterrows():
|
||||||
|
persona = Persona(
|
||||||
|
id=int(row["id"]),
|
||||||
|
name=str(row["name"]),
|
||||||
|
prompt=str(row["prompt"])
|
||||||
|
)
|
||||||
|
personas_by_id[persona.id] = persona
|
||||||
|
personas_by_name[persona.name] = persona
|
||||||
|
|
||||||
|
return personas_by_id, personas_by_name
|
||||||
|
|
||||||
personas_by_id[p1.id] = p1
|
# 从配表加载persona数据
|
||||||
personas_by_id[p2.id] = p2
|
personas_by_id, personas_by_name = _load_personas()
|
||||||
personas_by_id[p3.id] = p3
|
|
||||||
personas_by_id[p4.id] = p4
|
|
||||||
personas_by_id[p5.id] = p5
|
|
||||||
personas_by_name[p1.name] = p1
|
|
||||||
personas_by_name[p2.name] = p2
|
|
||||||
personas_by_name[p3.name] = p3
|
|
||||||
personas_by_name[p4.name] = p4
|
|
||||||
personas_by_name[p5.name] = p5
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
27
src/utils/df.py
Normal file
27
src/utils/df.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import pandas as pd
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from src.utils.config import CONFIG
|
||||||
|
|
||||||
|
|
||||||
|
def load_csv(path: Path) -> pd.DataFrame:
|
||||||
|
df = pd.read_csv(path)
|
||||||
|
row_types = {
|
||||||
|
"id": int,
|
||||||
|
"name": str,
|
||||||
|
"description": str,
|
||||||
|
"prompt": str,
|
||||||
|
}
|
||||||
|
for column, dtype in row_types.items():
|
||||||
|
if column in df.columns:
|
||||||
|
df[column] = df[column].astype(dtype)
|
||||||
|
return df
|
||||||
|
|
||||||
|
def load_game_configs() -> dict[str, pd.DataFrame]:
|
||||||
|
game_configs = {}
|
||||||
|
for path in CONFIG.paths.game_configs.glob("*.csv"):
|
||||||
|
df = load_csv(path)
|
||||||
|
game_configs[path.stem] = df
|
||||||
|
return game_configs
|
||||||
|
|
||||||
|
game_configs = load_game_configs()
|
||||||
@@ -5,6 +5,7 @@ llm:
|
|||||||
|
|
||||||
paths:
|
paths:
|
||||||
templates: static/templates/
|
templates: static/templates/
|
||||||
|
game_configs: static/game_configs/
|
||||||
|
|
||||||
ai:
|
ai:
|
||||||
mode: "llm" # "rule" or "llm"
|
mode: "llm" # "rule" or "llm"
|
||||||
@@ -12,4 +13,5 @@ ai:
|
|||||||
|
|
||||||
game:
|
game:
|
||||||
init_npc_num: 3
|
init_npc_num: 3
|
||||||
npc_birth_rate_per_month: 0.001
|
npc_birth_rate_per_month: 0.001
|
||||||
|
|
||||||
|
|||||||
6
static/game_configs/persona.csv
Normal file
6
static/game_configs/persona.csv
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
id,name,prompt
|
||||||
|
1,理性,你是一个理性的人,你总是会用逻辑来思考问题,做事会谋定而后动。
|
||||||
|
2,无常,你是一个无常的人,目标飘忽不定,不会长期坚持一个目标。
|
||||||
|
3,怠惰,你是一个怠惰的人,你总是会拖延,不想努力,更热衷于享受人生。
|
||||||
|
4,冒险,你是一个冒险的人,你总是会冒险,喜欢刺激,总想放手一搏。
|
||||||
|
5,随性,你是一个随性的人,你总是会随机应变,性子到哪里了就是哪里,没有一定痣规。
|
||||||
|
Reference in New Issue
Block a user