Skip to content

Commit 89cefb8

Browse files
committed
refactor(chat_router): Extract prompt builder functions (Step 5)
- Extracted prompt building functions to backend/api/handlers/prompt_builder.py: - get_validator_info_for_prompt() - build_prompt_context_from_chat_request() - truncate_user_message() - get_transparency_disclaimer() - build_minimal_philosophical_prompt() - format_conversation_history() - calculate_confidence_score() - Added ValidatorInfo class to chat_config.py for validator defaults - Updated chat_router.py to import and use new prompt builder functions - Created comprehensive unit tests for prompt_builder.py (26 test cases) - Reduced chat_router.py from ~8,983 LOC to 7,864 LOC (~1,119 lines removed) This is Step 5 of the 10-step refactoring plan to reduce chat_router.py complexity.
1 parent 6485d88 commit 89cefb8

5 files changed

Lines changed: 1529 additions & 1146 deletions

File tree

backend/api/config/chat_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ class FPSConfig:
8282
EXPLICIT_FAKE_ENTITIES: List[str] = None # Will be initialized in __post_init__
8383

8484

85+
@dataclass
86+
class ValidatorInfo:
87+
"""Validator information defaults."""
88+
DEFAULT_VI: str = "19 validators total, chia thành 7 lớp (layers)"
89+
DEFAULT_EN: str = "19 validators total, organized into 7 layers"
90+
DEFAULT_LAYERS: str = "7 layers"
91+
92+
8593
@dataclass
8694
class ChatConfig:
8795
"""Main configuration class aggregating all config sections."""
@@ -94,6 +102,7 @@ class ChatConfig:
94102
cache: CacheConfig = None
95103
validation: ValidationConfig = None
96104
fps: FPSConfig = None
105+
validator_info: ValidatorInfo = None
97106

98107
def __post_init__(self):
99108
"""Initialize nested config objects."""
@@ -116,6 +125,8 @@ def __post_init__(self):
116125
self.fps.EXPLICIT_FAKE_ENTITIES = [
117126
"veridian", "lumeria", "emerald", "daxonia"
118127
]
128+
if self.validator_info is None:
129+
self.validator_info = ValidatorInfo()
119130

120131

121132
# Global config instance (singleton pattern)

0 commit comments

Comments
 (0)