Spaces:
Sleeping
Sleeping
File size: 5,312 Bytes
5545b9a e1d7e7b fe1ffb2 e1d7e7b fe1ffb2 e1d7e7b 361d672 e1d7e7b |
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
---
title: PersonaChatEngine Ai Server
emoji: π
colorFrom: green
colorTo: green
sdk: docker
pinned: false
license: mit
---
## βοΈ AI μλ² (ai_server/)
### μν & λ°μ΄ν° νλ¦
1. **κ²μ μλ² μμ² μμ (`app.py`)**
- μ΅μ μ
λ ₯λ§ μλ λμ: `{ text, npc_id, player_id, ... }`
- μ΅μ
: μν/컨ν
μ€νΈ λΆμ‘± μ `rag/docs/npc_config.json` λ±μμ NPC λ©νλ₯Ό μ‘°νν΄ λ³΄κ°
2. **μ μ²λ¦¬Β·ν둬ννΈ κ΅¬μ±(`pipeline/preprocess.py`, `utils/context_parser.py`, `manager/prompt_builder.py`)**
- νκ·Έ/컨ν
μ€νΈ/νλ μ΄μ΄ λ°νλ₯Ό λ¬Άμ΄ `<SYS>`, `<CTX>`, `<PLAYER>`, `<NPC>` ν¬λ§·μΌλ‘ ꡬμ±
3. **μΆλ‘ μμ²(`utils/hf_client.py`, `models/fallback_model.py`, `pipeline/generator.py`)**
- 쑰건 λΆμΆ©μ‘± input β `fallback_model.py`μμ λ체 μλ΅ μμ±
- 쑰건 μΆ©μ‘± input β `generator.py`μμ payload κ΅¬μ± ν HF Space `/predict_main` POST
4. **νμ²λ¦¬(`pipeline/postprocess.py`)**
- λͺ¨λΈ μλ΅μμ **λμ¬ ν
μ€νΈ, delta, flag**λ₯Ό νμ±Β·μ κ·ν
- flags β μκ·Έλͺ¨μ΄λ+threshold, delta β λ²μ ν΄λ¨νΒ·λΌμ΄λ©
5. **κ²μ μλ² μλ΅(`schemas.py`)**
- νμ€ JSONμΌλ‘ λ°ν
```json
{
"text": "NPCμ λλ΅...",
"delta": {"trust": 0.10, "relationship": 0.08},
"flags": {"give_item": true, "npc_main_story": false},
"meta": {"npc_id": "mother_abandoned_factory"}
}
```
---
### π λλ ν 리 ꡬ쑰
```bash
ai-server/
βββ app.py # FastAPI μνΈλ¦¬ν¬μΈνΈ
βββ config.py # μλ² μ€μ λ° λͺ¨λΈ κ²½λ‘ κ΄λ¦¬
βββ schemas.py # μμ²/μλ΅ λ°μ΄ν° ꡬ쑰 μ μ
βββ requirements.txt # μμ‘΄μ± ν¨ν€μ§ λͺ©λ‘
βββ pipeline/ # λν νλ¦ μ²λ¦¬ λͺ¨λ
β βββ preprocess.py # μ
λ ₯ μ μ²λ¦¬ λ° ν둬ννΈ κ΅¬μ±
β βββ postprocess.py # λͺ¨λΈ μΆλ ₯ νμ²λ¦¬
β βββ generator.py # λͺ¨λΈ μΆλ‘ μμ² μ²λ¦¬
βββ rag/ # RAG κΈ°λ° flag ν΄μ λͺ¨λ
β βββ rag_manager.py
β βββ docs/npc_config.json
βββ utils/ # μ νΈλ¦¬ν° λͺ¨λ
β βββ hf_client.py # HF API ν΅μ
β βββ context_parser.py # λν λ§₯λ½ νμ±
βββ models/ # λͺ¨λΈ λ‘λ© λ° fallback μ²λ¦¬
β βββ emotion_model.py # emotion modelμ μ΄μ©ν inference μ§ν
β βββ fallback_model.py # fallback modelμ μ΄μ©ν inference μ§ν
β βββ model_loader.py
βββ manager/
βββ agent_manager.py
βββ dialogue_manager.py # μ 체 pipeline λͺ¨λ κ΄λ¦¬
βββ prompt_builder.py
```
---
### π§© μ΅μ RAG νμ
λ³ λ§€ν (11μ’
)
| **type** | **μ‘°ν μμ ** | **μ‘°ν 쑰건** | **μ¬μ© λͺ¨λ/ν¨μ** | **μ£Όμ λͺ©μ ** |
|----------|--------------|---------------|--------------------|---------------|
| `trigger_def` | preprocess_input | npc_id, quest_stage | retrieve(...) | λ©μΈ κ²½λ‘ μ‘°κ±΄ νμ |
| `fallback` | preprocess_input | npc_id, quest_stage | retrieve(...) | fallback prompt κ΅¬μ± |
| `forbidden_trigger_list` | preprocess_input | npc_id | _load_forbidden_trigger_data | κΈμ§ νΈλ¦¬κ±° κ°μ§ |
| `trigger_meta` | preprocess_input | npc_id, trigger | _load_trigger_meta | νΉμ fallback μ delta/action νμ |
| `lore` | build_main_prompt | npc_id, quest_stage/any | RAG main docs | μΈκ³κ΄/λ°°κ²½ μ€λͺ
|
| `description` | build_main_prompt | npc_id, quest_stage | RAG main docs | νμ¬ μν© μ€λͺ
|
| `flag_def` | postprocess_pipeline | npc_id, quest_stage, flag_name | pre_data["rag_main_docs"] | flag threshold/μμ λ¬Έμ₯ |
| `main_res_validate` | postprocess_pipeline | npc_id, quest_stage | pre_data["rag_main_docs"] | μλ΅ κ²μ¦ κΈ°μ€ |
| `npc_persona` | build_main_prompt | npc_id | retrieve(...) | NPC μ±κ²©Β·νΉμ± λ°μ |
| `dialogue_turn` | postprocess_pipeline | npc_id, quest_stage | retrieve(...) | λν μμ μ°Έμ‘° |
| *(μμ)* | fallback_final_check | pre_data["trigger_meta"] | - | μλ΅ μλ―Έ μΌμΉ κ²μ¦ |
---
### π λ°μ΄ν° νλ¦ μμ½
1. **preprocess_input()**
- trigger_def β λ©μΈ 쑰건 νμ
- forbidden_trigger_list + trigger_meta β νΉμ fallback κ°μ§
- fallback β μΌλ° fallback μ€νμΌ
2. **build_main_prompt()**
- lore + description + npc_persona β λ©μΈ prompt 컨ν
μ€νΈ ꡬμ±
3. **build_fallback_prompt()**
- fallback_style + trigger_meta β fallback prompt ꡬμ±
4. **postprocess_pipeline()**
- flag_def β flag threshold/μμ
- main_res_validate β μλ΅ κ²μ¦
5. **fallback_final_check()**
- trigger_meta β delta/action μλ―Έ μΌμΉ κ²μ¦
---
### π ν
μ€νΈ
μ
λ°μ΄νΈ μμ
---
<!-- app-tab:start -->
# π PersonaChatEngine AI Server
κ²μ λ΄ NPC λν μμ§ API μλ²μ
λλ€.
μ΅μ μ
λ ₯λ§μΌλ‘λ λμνλ©°, RAG κΈ°λ° λ¬Έμμ NPC λ©νλ°μ΄ν°λ₯Ό νμ©ν΄ λνλ₯Ό 보κ°ν©λλ€.
### βοΈ μ£Όμ κΈ°λ₯
- κ²μ μλ² μμ² μμ λ° μ μ²λ¦¬
- 쑰건 νμ ν λ©μΈ/ν΄λ°± λͺ¨λΈ μΆλ‘
- RAG κΈ°λ° μΈκ³κ΄Β·μν©Β·NPC μ±κ²© λ°μ
- μλ΅ νμ²λ¦¬ λ° JSON νμ€ μλ΅ λ°ν
<!-- app-tab:end -->
--- |