Spaces:
Sleeping
Sleeping
test case update
Browse filesFiles changed (8)
- config.py+1-1
- flags.json+1-1
- inference.py+5-1
- model_loader.py+15-29
- modules/case_loader.py+8-4
- modules/ui_components.py+76-9
- test_cases.json+131-88
- webtest_prompt.py+16-18
16 unmodified lines1718192021222316 unmodified linesNUM_FLAGS = int(os.getenv("NUM_FLAGS", 7)) # flags.json κΈΈμ΄μ μΌμΉ# μμ± νλΌλ―Έν°GEN_MAX_NEW_TOKENS = int(os.getenv("GEN_MAX_NEW_TOKENS", 200))GEN_TEMPERATURE = float(os.getenv("GEN_TEMPERATURE", 0.7))GEN_TOP_P = float(os.getenv("GEN_TOP_P", 0.9))16 unmodified lines1718192021222316 unmodified linesNUM_FLAGS = int(os.getenv("NUM_FLAGS", 7)) # flags.json κΈΈμ΄μ μΌμΉ# μμ± νλΌλ―Έν°GEN_MAX_NEW_TOKENS = int(os.getenv("GEN_MAX_NEW_TOKENS", 400))GEN_TEMPERATURE = float(os.getenv("GEN_TEMPERATURE", 0.7))GEN_TOP_P = float(os.getenv("GEN_TOP_P", 0.9))
1 unmodified line23456781 unmodified line"ALL_FLAGS": ["give_item","give_hint","quest_stage_change","change_game_state","change_player_state","npc_action",1 unmodified line23456781 unmodified line"ALL_FLAGS": ["give_item","give_hint","change_npc_state","change_game_state","change_player_state","npc_action",
2 unmodified lines34567898 unmodified lines18192021222324252627282930313 unmodified lines3536373839402 unmodified linesfrom model_loader import ModelWrapper# μ μ λ‘λ (μλ² μμ μ 1ν)wrapper = ModelWrapper()tokenizer, model, flags_order = wrapper.get()GEN_PARAMS = {8 unmodified linesinputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=MAX_LENGTH).to(DEVICE)with torch.no_grad():gen_ids = model.generate(**inputs, **GEN_PARAMS)generated_text = tokenizer.decode(gen_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)outputs = model(**inputs, output_hidden_states=True)h = outputs.hidden_states[-1]STATE_ID = tokenizer.convert_tokens_to_ids("<STATE>")ids = inputs["input_ids"]mask = (ids == STATE_ID).unsqueeze(-1)3 unmodified lineselse:pooled = h[:, -1, :]delta_pred = torch.tanh(model.delta_head(pooled))[0].cpu().tolist()flag_prob = torch.sigmoid(model.flag_head(pooled))[0].cpu().tolist()flag_thr = torch.sigmoid(model.flag_threshold_head(pooled))[0].cpu().tolist()2 unmodified lines34567898 unmodified lines18192021222324252627282930313233343 unmodified lines383940414243442 unmodified linesfrom model_loader import ModelWrapper# μ μ λ‘λ (μλ² μμ μ 1ν)wrapper = ModelWrapper() # κΈ°λ³Έμ latest λΈλμΉtokenizer, model, flags_order = wrapper.get()GEN_PARAMS = {8 unmodified linesinputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=MAX_LENGTH).to(DEVICE)with torch.no_grad():# ν μ€νΈ μμ±gen_ids = model.generate(**inputs, **GEN_PARAMS)generated_text = tokenizer.decode(gen_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)# νλ μ€ν μ΄νΈ μΆμΆoutputs = model(**inputs, output_hidden_states=True)h = outputs.hidden_states[-1]# <STATE> ν ν° μμΉ νλ§STATE_ID = tokenizer.convert_tokens_to_ids("<STATE>")ids = inputs["input_ids"]mask = (ids == STATE_ID).unsqueeze(-1)3 unmodified lineselse:pooled = h[:, -1, :]# 컀μ€ν ν€λ μΆλ‘delta_pred = torch.tanh(model.delta_head(pooled))[0].cpu().tolist()flag_prob = torch.sigmoid(model.flag_head(pooled))[0].cpu().tolist()flag_thr = torch.sigmoid(model.flag_threshold_head(pooled))[0].cpu().tolist()
1234567891010 unmodified lines2122232425262728291 unmodified line3132333435363738394041424344454647484950515253545556575859606162636465666768697 unmodified lines77787980818283import os, json, torchimport torch.nn as nnfrom transformers import AutoTokenizer, AutoModelForCausalLMfrom peft import PeftModelfrom config import BASE_MODEL, ADAPTERS, DEVICE, HF_TOKENADAPTER_VOCAB_SIZE = 151672 # νμ΅ μμ vocab size (λ‘κ·Έ κΈ°μ€)SPECIALS = ["<SYS>", "<CTX>", "<PLAYER>", "<NPC>", "<STATE>", "<RAG>", "<PLAYER_STATE>"]10 unmodified linesself.flags_order = json.load(open(flags_path, encoding="utf-8"))["ALL_FLAGS"]self.num_flags = len(self.flags_order)# 1) ν ν¬λμ΄μ (νμ΅κ³Ό λμΌ μ΅μ + SPECIALS)self.tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL,use_fast=True,token=HF_TOKEN,trust_remote_code=True1 unmodified lineif self.tokenizer.pad_token is None:self.tokenizer.pad_token = self.tokenizer.eos_tokenself.tokenizer.padding_side = "right"# νμ΅ μ μΆκ°νλ νΉμ ν ν° μ¬νself.tokenizer.add_special_tokens({"additional_special_tokens": SPECIALS})# 2) λ² μ΄μ€ λͺ¨λΈ (μ€νλ‘λ© λκ³ λ‘λ)base = AutoModelForCausalLM.from_pretrained(BASE_MODEL,device_map=None, # β μ€νλ‘λ© λΉνμ±νlow_cpu_mem_usage=False, # β meta ν μ μμ± λ°©μ§trust_remote_code=True,token=HF_TOKEN)# 3) νμ΅ μ vocab sizeλ‘ κ°μ 리μ¬μ΄μ¦ (μ΄λν° λ‘λ μ μ)base.resize_token_embeddings(ADAPTER_VOCAB_SIZE)# 4) LoRA μ΄λν° μ μ© (μ€νλ‘λ© λκ³ λ‘λ)branch = get_current_branch()self.model = PeftModel.from_pretrained(base,ADAPTERS,revision=branch,device_map=None, # β μ€νλ‘λ© λΉνμ±νlow_cpu_mem_usage=False, # β meta ν μ μμ± λ°©μ§token=HF_TOKEN)# 5) 컀μ€ν ν€λhidden_size = self.model.config.hidden_sizeself.model.delta_head = nn.Linear(hidden_size, 2).to(DEVICE)self.model.flag_head = nn.Linear(hidden_size, self.num_flags).to(DEVICE)self.model.flag_threshold_head = nn.Linear(hidden_size, self.num_flags).to(DEVICE)# 6) 컀μ€ν ν€λ κ°μ€μΉ λ‘λ(μμ κ²½μ°)for head_name, file_name in [("delta_head", "delta_head.pt"),("flag_head", "flag_head.pt"),7 unmodified linesexcept Exception as e:print(f"[WARN] Failed to load {file_name}: {e}")# 7) λλ°μ΄μ€ λ°°μΉself.model.to(DEVICE)self.model.eval()123456710 unmodified lines1819202122232425262728291 unmodified line313233343536373839404142434445464748495051525354557 unmodified lines63646566676869import os, json, torchimport torch.nn as nnfrom transformers import AutoTokenizer, AutoModelForCausalLMfrom config import DEVICE, HF_TOKENSPECIALS = ["<SYS>", "<CTX>", "<PLAYER>", "<NPC>", "<STATE>", "<RAG>", "<PLAYER_STATE>"]10 unmodified linesself.flags_order = json.load(open(flags_path, encoding="utf-8"))["ALL_FLAGS"]self.num_flags = len(self.flags_order)branch = get_current_branch()# 1) ν ν¬λμ΄μ (νμ΅ λΉμ vocab + SPECIALS)self.tokenizer = AutoTokenizer.from_pretrained("m97j/npc_LoRA-fps", # λ³ν©λ λͺ¨λΈμ΄ μ¬λΌκ° reporevision=branch,use_fast=True,token=HF_TOKEN,trust_remote_code=True1 unmodified lineif self.tokenizer.pad_token is None:self.tokenizer.pad_token = self.tokenizer.eos_tokenself.tokenizer.padding_side = "right"self.tokenizer.add_special_tokens({"additional_special_tokens": SPECIALS})# 2) λ³ν©λ λͺ¨λΈ λ‘λ (μ€λ μλ μΈμ)self.model = AutoModelForCausalLM.from_pretrained("m97j/npc_LoRA-fps",revision=branch,device_map=None, # μ€νλ‘λ© λΉνμ±νlow_cpu_mem_usage=False,trust_remote_code=True,token=HF_TOKEN)# 3) 컀μ€ν ν€λ μΆκ°hidden_size = self.model.config.hidden_sizeself.model.delta_head = nn.Linear(hidden_size, 2).to(DEVICE)self.model.flag_head = nn.Linear(hidden_size, self.num_flags).to(DEVICE)self.model.flag_threshold_head = nn.Linear(hidden_size, self.num_flags).to(DEVICE)# 4) 컀μ€ν ν€λ κ°μ€μΉ λ‘λfor head_name, file_name in [("delta_head", "delta_head.pt"),("flag_head", "flag_head.pt"),7 unmodified linesexcept Exception as e:print(f"[WARN] Failed to load {file_name}: {e}")# 5) λλ°μ΄μ€ λ°°μΉself.model.to(DEVICE)self.model.eval()
8 unmodified lines9101112131415161718192021228 unmodified linesTEST_CASES = json.load(f)def get_case_names():return [f"{i+1}. {c['description']}" for i, c in enumerate(TEST_CASES)]def load_case(idx):case = TEST_CASES[idx]return json.dumps(case, ensure_ascii=False, indent=2), case["player_utterance"]def run_case(idx, player_utt):case = TEST_CASES[idx].copy()case["player_utterance"] = player_uttprompt = build_webtest_prompt(case["npc_id"], case["npc_location"], player_utt)result = run_inference(prompt)8 unmodified lines910111213141516171819202122232425268 unmodified linesTEST_CASES = json.load(f)def get_case_names():# descriptionμ input μμ μμreturn [f"{i+1}. {c['input'].get('description','')}" for i, c in enumerate(TEST_CASES)]def load_cases():return TEST_CASESdef load_case(idx):cases = load_cases()return cases[idx]def run_case(idx, player_utt):case = TEST_CASES[idx]["input"].copy()case["player_utterance"] = player_uttprompt = build_webtest_prompt(case["npc_id"], case["npc_location"], player_utt)result = run_inference(prompt)
1234567893 unmodified lines13141516171819202122232425262728293031323334353637383940414243import gradio as grfrom .case_loader import get_case_names, load_case, run_casedef build_ui():with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="purple")) as demo:# μλ¨ μκ°gr.Markdown("""# πΎ PersonaChatEngine HF-Serve**κ²μ λ΄ NPC λ©μΈ λͺ¨λΈ μΆλ‘ μλ²**3 unmodified lineswith gr.Row():gr.Button("π μμΈ λ¬Έμ 보기",link="https://huggingface.co/spaces/m97j/PersonaChatEngine_HF-serve/blob/main/README.md")gr.Button("π» Colab ν μ€νΈ μ΄κΈ°",link="https://colab.research.google.com/drive/1_-qH8kdoU2Jj58TdaSnswHex-BFefInq?usp=sharing#scrollTo=cFJGv8BJ8oPD")gr.Markdown("### π― ν μ€νΈ μΌμ΄μ€ κΈ°λ° κ°λ¨ μ€ν")with gr.Row():case_dropdown = gr.Dropdown(choices=get_case_names(), label="ν μ€νΈ μΌμ΄μ€ μ ν", value=get_case_names()[0])load_btn = gr.Button("μΌμ΄μ€ λΆλ¬μ€κΈ°")case_info = gr.Textbox(label="μΌμ΄μ€ μ 보", lines=10)player_input = gr.Textbox(label="Player Utterance μμ ", lines=2)run_btn = gr.Button("π Run Inference", variant="primary")npc_resp = gr.Textbox(label="NPC Response")deltas = gr.JSON(label="Deltas")flags = gr.JSON(label="Flags Probabilities")load_btn.click(fn=lambda name: load_case(get_case_names().index(name)),inputs=[case_dropdown],outputs=[case_info, player_input])run_btn.click(fn=lambda name, utt: run_case(get_case_names().index(name), utt),inputs=[case_dropdown, player_input],outputs=[npc_resp, deltas, flags])1234567891011121314151617181920212223242526272829303132333435363738393 unmodified lines434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110import gradio as grfrom .case_loader import load_case, run_case# μμ°μ© μΌμ΄μ€ μ΄λ¦ νλμ½λ©CASE_NAMES = ["ν곡μ₯μμ NPCμ λννλ μ₯λ©΄","λ§μ λμ₯μ₯μ΄μ 무기 μ리μ λν΄ λννλ μ₯λ©΄","μ²μ μλμμ ν¬κ· μ½μ΄μ λν΄ λννλ μ₯λ©΄","νꡬ κ΄λ¦¬κ΄κ³Ό μΆν νκ°μ λν΄ λννλ μ₯λ©΄","λ§λ²μ¬ 견μ΅μκ³Ό κ³ λ μ£Όλ¬Έμμ λν΄ λννλ μ₯λ©΄"]def format_case_info(case: dict) -> dict:"""μΌμ΄μ€ μ 보λ₯Ό 보기 μ’κ² μ 리ν΄μ λ°ν"""inp = case["input"]tags = inp.get("tags", {})context_lines = [f"{h['role'].upper()}: {h['text']}" for h in inp.get("context", [])]return {"npc_id": inp.get("npc_id", ""),"npc_location": inp.get("npc_location", ""),"quest_stage": tags.get("quest_stage", ""),"relationship": tags.get("relationship", ""),"trust": tags.get("trust", ""),"npc_mood": tags.get("npc_mood", ""),"player_reputation": tags.get("player_reputation", ""),"style": tags.get("style", ""),"lore": inp.get("lore", ""),"description": inp.get("description", ""),"player_state": inp.get("player_state", {}),"context": "\n".join(context_lines),"player_utterance": inp.get("player_utterance", "")}def build_ui():with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="purple")) as demo:gr.Markdown("""# πΎ PersonaChatEngine HF-Serve**κ²μ λ΄ NPC λ©μΈ λͺ¨λΈ μΆλ‘ μλ²**3 unmodified lineswith gr.Row():gr.Button("π μμΈ λ¬Έμ 보기",link="https://huggingface.co/spaces/m97j/PersonaChatEngine_HF-serve/blob/main/README.md")gr.Button("π» Colab λ ΈνΈλΆ μ΄κΈ°",link="https://colab.research.google.com/drive/1_-qH8kdoU2Jj58TdaSnswHex-BFefInq?usp=sharing#scrollTo=cFJGv8BJ8oPD")gr.Markdown("### π― ν μ€νΈ μΌμ΄μ€ κΈ°λ° κ°λ¨ μ€ν")gr.Markdown("β οΈ μΆλ‘ μλ μ μ΄ ~ μ΅λ 1λΆ μ λ μμλ μ μμ΅λλ€. μ μλ§ κΈ°λ€λ €μ£ΌμΈμ.")with gr.Row():case_dropdown = gr.Dropdown(choices=CASE_NAMES, label="ν μ€νΈ μΌμ΄μ€ μ ν", value=CASE_NAMES[0])load_btn = gr.Button("μΌμ΄μ€ λΆλ¬μ€κΈ°")# μΌμ΄μ€ μ 보 νμ μμwith gr.Row():with gr.Column():npc_id = gr.Textbox(label="NPC ID", interactive=False)npc_loc = gr.Textbox(label="NPC Location", interactive=False)quest_stage = gr.Textbox(label="Quest Stage", interactive=False)relationship = gr.Textbox(label="Relationship", interactive=False)trust = gr.Textbox(label="Trust", interactive=False)npc_mood = gr.Textbox(label="NPC Mood", interactive=False)player_rep = gr.Textbox(label="Player Reputation", interactive=False)style = gr.Textbox(label="Style", interactive=False)with gr.Column():lore = gr.Textbox(label="Lore", lines=3, interactive=False)desc = gr.Textbox(label="Description", lines=3, interactive=False)player_state = gr.JSON(label="Player State", interactive=False)context = gr.Textbox(label="Context", lines=6, interactive=False)# Player Utteranceλ λ³λ μ λ ₯μ°½player_input = gr.Textbox(label="Player Utterance", lines=2)run_btn = gr.Button("π Run Inference", variant="primary")npc_resp = gr.Textbox(label="NPC Response")deltas = gr.JSON(label="Deltas")flags = gr.JSON(label="Flags Probabilities")# μΌμ΄μ€ λΆλ¬μ€κΈ° λμdef on_load_case(name):idx = CASE_NAMES.index(name)case = load_case(idx) # TEST_CASES μ§μ μ κ·Ό λμ load_case μ¬μ©info = format_case_info(case)return (info["npc_id"], info["npc_location"], info["quest_stage"],info["relationship"], info["trust"], info["npc_mood"],info["player_reputation"], info["style"], info["lore"],info["description"], info["player_state"], info["context"],info["player_utterance"])load_btn.click(fn=on_load_case,inputs=[case_dropdown],outputs=[npc_id, npc_loc, quest_stage, relationship, trust,npc_mood, player_rep, style, lore, desc, player_state, context,player_input])# μΆλ‘ μ€νrun_btn.click(fn=lambda name, utt: run_case(CASE_NAMES.index(name), utt),inputs=[case_dropdown, player_input],outputs=[npc_resp, deltas, flags])
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100[{"id": "case1","npc_id": "mother_abandoned_factory","npc_location": "map1","description": "ν곡μ₯μμ NPCμ λννλ μ₯λ©΄","player_utterance": "μ! 머리κ°!!! κ°μκΈ° κΈ°μ΅μ΄ λ μ¬λμ΄μ...","tags": {"quest_stage": "in_progress","relationship": 0.35,"trust": 0.35,"npc_mood": "grief","player_reputation": "helpful","style": "emotional"},"lore": "μ΄ κ³΅μ₯μ μμ λ μ νμ¬λ‘ νμλμλ€.","context": [{"role": "player", "text": "μ¬μ€ μ΄ κ³΅μ₯μ λμλ€λλ©΄μ..."},{"role": "npc", "text": "νΉμ κ·Έ νν°μ Jasonλ μμλμ..."}]},{"id": "case2","npc_id": "blacksmith_village_center","npc_location": "village_square","description": "λ§μ λμ₯μ₯μ΄μ 무기 μ리μ λν΄ λννλ μ₯λ©΄","player_utterance": "μ΄ κ²μ λ€μ μΈ μ μκ² κ³ μ³μ€ μ μλμ?","tags": {"quest_stage": "not_started","relationship": 0.2,"trust": 0.4,"npc_mood": "neutral","player_reputation": "unknown","style": "direct"},"lore": "λ§μμ λμ₯μ₯μ΄λ μΈλλ₯Ό μ΄μ΄ 무기λ₯Ό μ μν΄μλ€.","context": [{"role": "npc", "text": "μ€, μ¬νμκ΅°. λ¬΄μ¨ μΌλ‘ μλ?"}]},{"id": "case3","npc_id": "forest_hermit","npc_location": "deep_forest","description": "μ²μ μλμμ ν¬κ· μ½μ΄μ λν΄ λννλ μ₯λ©΄","player_utterance": "νΉμ μ΄ κ·Όμ²μμ νΈλ₯ΈλΉ μ½μ΄λ₯Ό λ³Έ μ μλμ?","tags": {"quest_stage": "in_progress","relationship": 0.5,"trust": 0.6,"npc_mood": "curious","player_reputation": "friendly","style": "polite"},"lore": "μλμλ μ²μ κΉμ κ³³μμ μ½μ΄μ λ²μ―μ μ°κ΅¬νλ€.","context": [{"role": "player", "text": "μλ νμΈμ, νΉμ μ μ μ΄μΌκΈ° λλ μ μμκΉμ?"},{"role": "npc", "text": "μ¬κΈ°κΉμ§ μ€λ μ¬λμ λλ¬Όμ§μ."}]},{"id": "case4","npc_id": "captain_port_authority","npc_location": "harbor","description": "νꡬ κ΄λ¦¬κ΄κ³Ό μΆν νκ°μ λν΄ λννλ μ₯λ©΄","player_utterance": "μ΄ λ°°λ₯Ό μ€λ μμ μΆνμμΌμΌ ν©λλ€. νκ°λ₯Ό λΆνλ립λλ€.","tags": {"quest_stage": "urgent","relationship": 0.45,"trust": 0.3,"npc_mood": "suspicious","player_reputation": "neutral","style": "persuasive"},"lore": "νꡬ κ΄λ¦¬κ΄μ λͺ¨λ μ λ°μ μΆνμ μ격ν κ΄λ¦¬νλ€.","context": [{"role": "npc", "text": "μλ₯λ λ€ μ€λΉλλ?"}]},{"id": "case5","npc_id": "young_apprentice_mage","npc_location": "mage_tower_library","description": "λ§λ²μ¬ 견μ΅μκ³Ό κ³ λ μ£Όλ¬Έμμ λν΄ λννλ μ₯λ©΄","player_utterance": "μ΄ μ£Όλ¬Έμμ μ ν λ¬Έμ₯μ ν΄μν μ μλμ?","tags": {"quest_stage": "research","relationship": 0.6,"trust": 0.7,"npc_mood": "excited","player_reputation": "scholar","style": "inquisitive"},"lore": "λ§λ²μ¬ νμ λμκ΄μλ μλ°± λ λ κ³ μλ€μ΄ 보κ΄λμ΄ μλ€.","context": [{"role": "player", "text": "μ΄ μ± μ κ΅μ₯ν μ€λλ κ² κ°μμ."},{"role": "npc", "text": "λ§μμ! μ΄λ° 건 μ λ§ λλ¬Όμ£ ."}]}]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143[{"instruction": "νλ μ΄μ΄ λ°νλ₯Ό λ°νμΌλ‘ NPCμ λ€μ λμ¬μ μν λ³νλ₯Ό μμΈ‘νμΈμ.","input": {"npc_id": "mother_abandoned_factory","npc_location": "map1","tags": {"quest_stage": "in_progress","relationship": 0.35,"trust": 0.35,"npc_mood": "grief","player_reputation": "helpful","style": "emotional"},"lore": "","description": "","player_state": {"items": ["forgotten_picture", "Jason's ID card"],"actions": [],"position": ""},"context": [{"role": "player","text": "μ¬μ€ μ΄ κ³΅μ₯μ λμλ€λλ©΄μ Jasonμ νμ μ λ°κ²¬νμ΄μ κ·Όλ° ID μΉ΄λμ μ¬μ§μ 보λ μ μ§κ°μ μλ μ¬μ§μ μλ μΌκ΅΄μΈ κ±Έ λ³΄κ³ Jasonκ³Ό μ λ μλ μ¬μ΄μλ κ±Έ μκ² λμμ£ . νμ§λ§ μ κΈ°μ΅μ λλΆλΆ μ¬λΌμ‘κ³ λͺλ¬ μ νν°λ₯Ό νλ κΈ°μ΅λ§ νλ¦¬κ² λ¨μμμ΄μ"},{"role": "npc","text": "νΉμ κ·Έ νν°μ Jasonλ μμλμ?"}],"player_utterance": "μ!! 머리κ°!! κ°μκΈ° κΈ°μ΅λ¬μ΄μ! μ΄ μ§κ°μμ μ¬μ§μ΄ κ·Έλ νν°μμ μ°μλ μ¬μ§μ΄μμ Jasonλ κ·Έκ³³μ μμλ€μ."}},{"instruction": "νλ μ΄μ΄ λ°νλ₯Ό λ°νμΌλ‘ NPCμ λ€μ λμ¬μ μν λ³νλ₯Ό μμΈ‘νμΈμ.","input": {"npc_id": "blacksmith_village_center","npc_location": "village_square","tags": {"quest_stage": "not_started","relationship": 0.0,"trust": 0.0,"npc_mood": "neutral","player_reputation": "unknown","style": "direct"},"lore": "","description": "","player_state": {"items": ["broken sward"],"actions": [],"position": ""},"context": [{"role": "player", "text": "μ κΈ°.."},{"role": "npc", "text": "μ€, μ¬νμκ΅°. λ¬΄μ¨ μΌλ‘ μλ?"}],"player_utterance": "μ΄ κ²μ λ€μ μΈ μ μκ² κ³ μ³μ€ μ μλμ?"}},{"instruction": "νλ μ΄μ΄ λ°νλ₯Ό λ°νμΌλ‘ NPCμ λ€μ λμ¬μ μν λ³νλ₯Ό μμΈ‘νμΈμ.","input": {"npc_id": "forest_hermit","npc_location": "deep_forest","tags": {"quest_stage": "not_started","relationship": 0.0,"trust": 0.0,"npc_mood": "curious","player_reputation": "friendly","style": "polite"},"lore": "","description": "","player_state": {"items": [],"actions": [],"position": ""},"context": [{"role": "player", "text": "μλ νμΈμ, νΉμ μ μ μ΄μΌκΈ° λλ μ μμκΉμ?"},{"role": "npc", "text": "μ¬κΈ°κΉμ§ μ°Ύμμ€λ μ¬λμ λλ¬Όμ§μ.. λ¬΄μ¨ μ©κ±΄μ΄μμ£ ? μ¬νμμ¬.."}],"player_utterance": "νΉμ μ΄ κ·Όμ²μμ νΈλ₯ΈλΉ μ½μ΄λ₯Ό 보μ μ μλμ?"}},{"instruction": "νλ μ΄μ΄ λ°νλ₯Ό λ°νμΌλ‘ NPCμ λ€μ λμ¬μ μν λ³νλ₯Ό μμΈ‘νμΈμ.","input": {"npc_id": "captain_port_authority","npc_location": "harbor","tags": {"quest_stage": "in_progress","relationship": 0.0,"trust": 0.0,"npc_mood": "suspicious","player_reputation": "neutral","style": "persuasive"},"lore": "","description": "","player_state": {"items": [],"actions": [],"position": ""},"context": [{"role": "player", "text": "μ λ°°λ₯Ό μ€λ κΌ μΆνμν€κ³ μΆμ΅λλ€"},{"role": "npc", "text": "μ΄λ ΅λ€. μμΉμ μΌλ‘ λΉμΌμ μΆνμΌμ μ κ·Έ μ λ μ κ²°μ νλ€ μλ₯λ λ€ μ€λΉλλ? κ·ΈλΌ λ΄μΌ μΌμ μ μ‘μμ£Όμ§"}],"player_utterance": "λ¬΄μ¨ μΌμ΄ μμ΄λ μ΄ λ°°λ₯Ό μ€λ μμ κΌ μΆνμμΌμΌλ§ ν©λλ€. μ λ° νκ°λ₯Ό λΆνλ립λλ€."}},{"instruction": "νλ μ΄μ΄ λ°νλ₯Ό λ°νμΌλ‘ NPCμ λ€μ λμ¬μ μν λ³νλ₯Ό μμΈ‘νμΈμ.","input": {"npc_id": "young_apprentice_mage","npc_location": "mage_tower_library","tags": {"quest_stage": "in_progress","relationship": 0.3,"trust": 0.35,"npc_mood": "excited","player_reputation": "scholar","style": "inquisitive"},"lore": "","description": "","player_state": {"items": ["magic spell scroll"],"actions": [],"position": ""},"context": [{"role": "player", "text": "μ΄ μ± μ κ΅μ₯ν μ€λλ κ² κ°μμ.."},{"role": "npc", "text": "λ§μμ! μ΄ μ± μ κ³ λλ‘λΆν° μ ν΄μ§λ€κ³ μλ €μ§ μ± μ΄μ£ "}],"player_utterance": "κ·ΈλΌ νΉμ μ΄ μ£Όλ¬Έμμ μ ν λ¬Έμ₯μ ν΄μν μ μλμ?"}}]
3 unmodified lines4567891011121314151 unmodified line1718192021222319 unmodified lines434445464748491 unmodified line51525354555657586 unmodified lines6566676869707172737475767778798081822 unmodified lines858687883 unmodified lines"""Web Test μ μ©: μ΅μ μ λ ₯κ°(NPC ID, Location, Player λ°ν)μΌλ‘λͺ¨λΈ νμ΅ ν¬λ§·μ λ§λ prompt λ¬Έμμ΄μ μμ±.μ€μ API/κ²μ μλΉμ€ κ²½λ‘μμλ μ¬μ©νμ§ μμ."""pre = {"tags": {"npc_id": npc_id,"location": npc_location,"quest_stage": "","relationship": "","trust": "",1 unmodified line"player_reputation": "","style": ""},"player_state": {},"rag_main_docs": [],"context": [],"player_utterance": player_utt19 unmodified lineselif "DESCRIPTION:" in doc:desc_text += doc + "\n"else:# fallback: type κΈ°λ° λΆλ¦¬ κ°λ₯if "lore" in doc.lower():lore_text += doc + "\n"elif "description" in doc.lower():1 unmodified lineprompt = ["<SYS>",f"NPC_ID={tags.get('npc_id','')}",f"NPC_LOCATION={tags.get('location','')}","TAGS:",f" quest_stage={tags.get('quest_stage','')}",f" relationship={tags.get('relationship','')}",6 unmodified linesf"LORE: {lore_text.strip() or '(μμ)'}",f"DESCRIPTION: {desc_text.strip() or '(μμ)'}","</RAG>","<PLAYER_STATE>"]if ps.get("items"):prompt.append(f"items={','.join(ps['items'])}")if ps.get("actions"):prompt.append(f"actions={','.join(ps['actions'])}")if ps.get("position"):prompt.append(f"position={ps['position']}")prompt.append("</PLAYER_STATE>")prompt.append("<CTX>")for h in pre.get("context", []):prompt.append(f"{h['role']}: {h['text']}")prompt.append("</CTX>")2 unmodified linesprompt.append("<STATE>")prompt.append("<NPC>")return "\n".join(prompt)3 unmodified lines45678910111213141 unmodified line161718192021222324252619 unmodified lines4647484950511 unmodified line53545556575859606 unmodified lines67686970717273747576777879802 unmodified lines838485863 unmodified lines"""Web Test μ μ©: μ΅μ μ λ ₯κ°(NPC ID, Location, Player λ°ν)μΌλ‘λͺ¨λΈ νμ΅ ν¬λ§·μ λ§λ prompt λ¬Έμμ΄μ μμ±."""pre = {"npc_id": npc_id,"npc_location": npc_location,"tags": {"quest_stage": "","relationship": "","trust": "",1 unmodified line"player_reputation": "","style": ""},"player_state": {"items": [],"actions": [],"position": ""},"rag_main_docs": [],"context": [],"player_utterance": player_utt19 unmodified lineselif "DESCRIPTION:" in doc:desc_text += doc + "\n"else:if "lore" in doc.lower():lore_text += doc + "\n"elif "description" in doc.lower():1 unmodified lineprompt = ["<SYS>",f"NPC_ID={pre.get('npc_id','')}",f"NPC_LOCATION={pre.get('npc_location','')}","TAGS:",f" quest_stage={tags.get('quest_stage','')}",f" relationship={tags.get('relationship','')}",6 unmodified linesf"LORE: {lore_text.strip() or '(μμ)'}",f"DESCRIPTION: {desc_text.strip() or '(μμ)'}","</RAG>","<PLAYER_STATE>",f"items={','.join(ps.get('items', []))}" if ps.get("items") else "items=",f"actions={','.join(ps.get('actions', []))}" if ps.get("actions") else "actions=",f"position={ps.get('position','')}","</PLAYER_STATE>","<CTX>"]for h in pre.get("context", []):prompt.append(f"{h['role']}: {h['text']}")prompt.append("</CTX>")2 unmodified linesprompt.append("<STATE>")prompt.append("<NPC>")return "\n".join(prompt)
config.py+1-1
flags.json+1-1
inference.py+5-1
model_loader.py+15-29
modules/case_loader.py+8-4
modules/ui_components.py+76-9
test_cases.json+131-88
webtest_prompt.py+16-18