File size: 2,761 Bytes
0fc77f3
 
 
2249ab6
 
 
 
 
0fc77f3
 
 
 
 
 
 
 
 
 
 
 
2249ab6
 
0fc77f3
 
2249ab6
0fc77f3
2249ab6
 
 
 
 
0fc77f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from typing import Dict, Any

def build_webtest_prompt(npc_id: str, npc_location: str, player_utt: str) -> str:
    """
    Web Test ์ „์šฉ: ์ตœ์†Œ ์ž…๋ ฅ๊ฐ’(NPC ID, Location, Player ๋ฐœํ™”)์œผ๋กœ
    ๋ชจ๋ธ ํ•™์Šต ํฌ๋งท์— ๋งž๋Š” prompt ๋ฌธ์ž์—ด์„ ์ƒ์„ฑ.
    ์‹ค์ œ API/๊ฒŒ์ž„ ์„œ๋น„์Šค ๊ฒฝ๋กœ์—์„œ๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ.
    """
    pre = {
        "tags": {
            "npc_id": npc_id,
            "location": npc_location,
            "quest_stage": "",
            "relationship": "",
            "trust": "",
            "npc_mood": "",
            "player_reputation": "",
            "style": ""
        },
        "player_state": {},
        "rag_main_docs": [],
        "context": [],
        "player_utterance": player_utt
    }
    return _assemble_prompt_for_model(pre)

def _assemble_prompt_for_model(pre: Dict[str, Any]) -> str:
    """
    Web Test ์ „์šฉ ๋‚ด๋ถ€ ํ•จ์ˆ˜:
    pre dict โ†’ ๋ชจ๋ธ ์ž…๋ ฅ ํฌ๋งท ๋ฌธ์ž์—ด(<SYS>~<NPC>)
    """

    tags = pre.get("tags", {})
    ps = pre.get("player_state", {})
    rag_docs = pre.get("rag_main_docs", [])

    # RAG ๋ฌธ์„œ ๋ถ„๋ฆฌ
    lore_text = ""
    desc_text = ""
    for doc in rag_docs:
        if "LORE:" in doc:
            lore_text += doc + "\n"
        elif "DESCRIPTION:" in doc:
            desc_text += doc + "\n"
        else:
            # fallback: type ๊ธฐ๋ฐ˜ ๋ถ„๋ฆฌ ๊ฐ€๋Šฅ
            if "lore" in doc.lower():
                lore_text += doc + "\n"
            elif "description" in doc.lower():
                desc_text += doc + "\n"

    prompt = [
        "<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','')}",
        f" trust={tags.get('trust','')}",
        f" npc_mood={tags.get('npc_mood','')}",
        f" player_reputation={tags.get('player_reputation','')}",
        f" style={tags.get('style','')}",
        "</SYS>",
        "<RAG>",
        f"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>")

    prompt.append(f"<PLAYER>{pre.get('player_utterance','').rstrip()}")
    prompt.append("<STATE>")
    prompt.append("<NPC>")

    return "\n".join(prompt)