Update components for WP-25b: Implement Lazy-Prompt-Orchestration across ingestion, decision engine, chat interface, and LLM service. Enhance prompt management with hierarchical model support and streamline response generation by removing manual formatting. Bump versions to reflect new features and optimizations.
This commit is contained in:
1 parent
d41da670fc
commit
7026fc4fed
6 files changed
+589
-203
No files matched your search
+27
-25
@@ -1,15 +1,14 @@
|
||||
"""
|
||||
FILE: app/routers/chat.py
|
||||
DESCRIPTION: Haupt-Chat-Interface (WP-25a Agentic Edition).
|
||||
Kombiniert die spezialisierte Interview-Logik und Keyword-Erkennung
|
||||
mit der neuen MoE-Orchestrierung und Pre-Synthesis Kompression.
|
||||
VERSION: 3.0.4 (WP-25a: Optimized MoE & Cascade Delegation)
|
||||
DESCRIPTION: Haupt-Chat-Interface (WP-25b Edition).
|
||||
Kombiniert die spezialisierte Interview-Logik mit der neuen
|
||||
Lazy-Prompt-Orchestration und MoE-Synthese.
|
||||
VERSION: 3.0.5 (WP-25b: Lazy Prompt Integration)
|
||||
STATUS: Active
|
||||
FIX:
|
||||
- WP-25a: Delegation der Fallback-Kaskade an den LLMService (v3.5.2).
|
||||
- WP-25a: Nutzung der zentralisierten Stream-Kompression der DecisionEngine (v1.2.1).
|
||||
- WP-25a: Konsistente Nutzung von MoE-Profilen für Interview- und RAG-Modus.
|
||||
- 100% Erhalt der v3.0.2 Logik (Interview, Schema-Resolution, FastPaths).
|
||||
- WP-25b: Umstellung des Interview-Modus auf Lazy-Prompt (prompt_key + variables).
|
||||
- WP-25b: Delegation der RAG-Phase an die Engine v1.3.0 für konsistente MoE-Steuerung.
|
||||
- WP-25a: Voller Erhalt der v3.0.2 Logik (Interview, Schema-Resolution, FastPaths).
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
@@ -146,7 +145,7 @@ def _collect_all_hits(stream_responses: Dict[str, Any]) -> List[QueryHit]:
|
||||
all_hits = []
|
||||
seen_node_ids = set()
|
||||
for _, response in stream_responses.items():
|
||||
# In v3.0.4 sammeln wir die hits aus den QueryResponse Objekten
|
||||
# Sammeln der Hits aus den QueryResponse Objekten
|
||||
if hasattr(response, 'results'):
|
||||
for hit in response.results:
|
||||
if hit.node_id not in seen_node_ids:
|
||||
@@ -166,8 +165,7 @@ async def chat_endpoint(
|
||||
):
|
||||
start_time = time.time()
|
||||
query_id = str(uuid.uuid4())
|
||||
settings = get_settings()
|
||||
logger.info(f"🚀 [WP-25a] Chat request [{query_id}]: {request.message[:50]}...")
|
||||
logger.info(f"🚀 [WP-25b] Chat request [{query_id}]: {request.message[:50]}...")
|
||||
|
||||
try:
|
||||
# 1. Intent Detection
|
||||
@@ -180,7 +178,7 @@ async def chat_endpoint(
|
||||
sources_hits = []
|
||||
answer_text = ""
|
||||
|
||||
# 2. INTERVIEW MODE (Bitgenaue WP-07 Logik)
|
||||
# 2. INTERVIEW MODE (WP-25b Lazy-Prompt Logik)
|
||||
if intent == "INTERVIEW":
|
||||
target_type = _detect_target_type(request.message, strategy.get("schemas", {}))
|
||||
types_cfg = get_types_config()
|
||||
@@ -194,23 +192,27 @@ async def chat_endpoint(
|
||||
fields_list = fallback.get("fields", []) if isinstance(fallback, dict) else (fallback or [])
|
||||
|
||||
fields_str = "\n- " + "\n- ".join(fields_list)
|
||||
template = llm.get_prompt(strategy.get("prompt_template", "interview_template"))
|
||||
template_key = strategy.get("prompt_template", "interview_template")
|
||||
|
||||
final_prompt = template.replace("{query}", request.message) \
|
||||
.replace("{target_type}", target_type) \
|
||||
.replace("{schema_fields}", fields_str)
|
||||
|
||||
# WP-25a: MoE Call (Kaskade erfolgt intern im LLMService)
|
||||
# WP-25b: Lazy Loading Call
|
||||
# Wir übergeben nur Key und Variablen. Das System formatiert passend zum Modell.
|
||||
answer_text = await llm.generate_raw_response(
|
||||
final_prompt, system=llm.get_prompt("system_prompt"),
|
||||
priority="realtime", profile_name="compression_fast", max_retries=0
|
||||
prompt_key=template_key,
|
||||
variables={
|
||||
"query": request.message,
|
||||
"target_type": target_type,
|
||||
"schema_fields": fields_str
|
||||
},
|
||||
system=llm.get_prompt("system_prompt"),
|
||||
priority="realtime",
|
||||
profile_name="compression_fast",
|
||||
max_retries=0
|
||||
)
|
||||
sources_hits = []
|
||||
|
||||
# 3. RAG MODE (Optimierte MoE Orchestrierung)
|
||||
# 3. RAG MODE (WP-25b Delegation an Engine v1.3.0)
|
||||
else:
|
||||
# Phase A & B: Retrieval & Kompression (Delegation an Engine v1.2.1)
|
||||
# Diese Methode gibt bereits die (evtl. komprimierten) Kontext-Strings zurück.
|
||||
# Phase A & B: Retrieval & Kompression (Delegiert an Engine v1.3.0)
|
||||
formatted_context_map = await engine._execute_parallel_streams(strategy, request.message)
|
||||
|
||||
# Erfassung der Quellen für das Tracing
|
||||
@@ -232,7 +234,7 @@ async def chat_endpoint(
|
||||
|
||||
sources_hits = _collect_all_hits(raw_stream_map)
|
||||
|
||||
# Phase C: Finale MoE Synthese
|
||||
# Phase C: Finale MoE Synthese (Delegiert an Engine v1.3.0)
|
||||
answer_text = await engine._generate_final_answer(
|
||||
intent, strategy, request.message, formatted_context_map
|
||||
)
|
||||
@@ -243,7 +245,7 @@ async def chat_endpoint(
|
||||
try:
|
||||
log_search(
|
||||
query_id=query_id, query_text=request.message, results=sources_hits,
|
||||
mode=f"wp25a_{intent.lower()}", metadata={"strategy": intent, "source": intent_source}
|
||||
mode=f"wp25b_{intent.lower()}", metadata={"strategy": intent, "source": intent_source}
|
||||
)
|
||||
except: pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user