Spaces:
Sleeping
Sleeping
metadata
title: PersonaChatEngine Ai Server
emoji: π
colorFrom: green
colorTo: green
sdk: docker
pinned: false
license: mit
βοΈ AI μλ² (ai_server/)
μν & λ°μ΄ν° νλ¦
κ²μ μλ² μμ² μμ (
app.py
)- μ΅μ μ
λ ₯λ§ μλ λμ:
{ text, npc_id, player_id, ... }
- μ΅μ
: μν/컨ν
μ€νΈ λΆμ‘± μ
rag/docs/npc_config.json
λ±μμ NPC λ©νλ₯Ό μ‘°νν΄ λ³΄κ°
- μ΅μ μ
λ ₯λ§ μλ λμ:
μ μ²λ¦¬Β·ν둬ννΈ κ΅¬μ±(
pipeline/preprocess.py
,utils/context_parser.py
,manager/prompt_builder.py
)- νκ·Έ/컨ν
μ€νΈ/νλ μ΄μ΄ λ°νλ₯Ό λ¬Άμ΄
<SYS>
,<CTX>
,<PLAYER>
,<NPC>
ν¬λ§·μΌλ‘ ꡬμ±
- νκ·Έ/컨ν
μ€νΈ/νλ μ΄μ΄ λ°νλ₯Ό λ¬Άμ΄
μΆλ‘ μμ²(
utils/hf_client.py
,models/fallback_model.py
,pipeline/generator.py
)- 쑰건 λΆμΆ©μ‘± input β
fallback_model.py
μμ λ체 μλ΅ μμ± - 쑰건 μΆ©μ‘± input β
generator.py
μμ payload κ΅¬μ± ν HF Space/predict_main
POST
- 쑰건 λΆμΆ©μ‘± input β
νμ²λ¦¬(
pipeline/postprocess.py
)- λͺ¨λΈ μλ΅μμ λμ¬ ν μ€νΈ, delta, flagλ₯Ό νμ±Β·μ κ·ν
- flags β μκ·Έλͺ¨μ΄λ+threshold, delta β λ²μ ν΄λ¨νΒ·λΌμ΄λ©
κ²μ μλ² μλ΅(
schemas.py
)- νμ€ JSONμΌλ‘ λ°ν
{ "text": "NPCμ λλ΅...", "delta": {"trust": 0.10, "relationship": 0.08}, "flags": {"give_item": true, "npc_main_story": false}, "meta": {"npc_id": "mother_abandoned_factory"} }
π λλ ν 리 ꡬ쑰
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"] | - | μλ΅ μλ―Έ μΌμΉ κ²μ¦ |
π λ°μ΄ν° νλ¦ μμ½
preprocess_input()
- trigger_def β λ©μΈ 쑰건 νμ
- forbidden_trigger_list + trigger_meta β νΉμ fallback κ°μ§
- fallback β μΌλ° fallback μ€νμΌ
build_main_prompt()
- lore + description + npc_persona β λ©μΈ prompt 컨ν μ€νΈ ꡬμ±
build_fallback_prompt()
- fallback_style + trigger_meta β fallback prompt ꡬμ±
postprocess_pipeline()
- flag_def β flag threshold/μμ
- main_res_validate β μλ΅ κ²μ¦
fallback_final_check()
- trigger_meta β delta/action μλ―Έ μΌμΉ κ²μ¦
π ν μ€νΈ
μ λ°μ΄νΈ μμ
π PersonaChatEngine AI Server
κ²μ λ΄ NPC λν μμ§ API μλ²μ
λλ€.
μ΅μ μ
λ ₯λ§μΌλ‘λ λμνλ©°, RAG κΈ°λ° λ¬Έμμ NPC λ©νλ°μ΄ν°λ₯Ό νμ©ν΄ λνλ₯Ό 보κ°ν©λλ€.
βοΈ μ£Όμ κΈ°λ₯
- κ²μ μλ² μμ² μμ λ° μ μ²λ¦¬
- 쑰건 νμ ν λ©μΈ/ν΄λ°± λͺ¨λΈ μΆλ‘
- RAG κΈ°λ° μΈκ³κ΄Β·μν©Β·NPC μ±κ²© λ°μ
- μλ΅ νμ²λ¦¬ λ° JSON νμ€ μλ΅ λ°ν