Update main application and services for WP-25 release, introducing Agentic Multi-Stream RAG capabilities. Enhance lifespan management, global error handling, and integrate LLMService with DecisionEngine for improved retrieval and synthesis. Update dependencies and versioning across modules, ensuring compatibility with new multi-stream architecture. Refactor chat router to support new intent classification and retrieval strategies, while maintaining stability and performance improvements.
This commit is contained in:
1 parent
67d7154328
commit
008167268f
8 files changed
+647
-447
No files matched your search
+37
-26
@@ -6,11 +6,13 @@ DESCRIPTION: Hybrid-Client für Ollama, Google GenAI (Gemini) und OpenRouter.
|
||||
WP-20 Fix: Bulletproof Prompt-Auflösung für format() Aufrufe.
|
||||
WP-22/JSON: Optionales JSON-Schema + strict (für OpenRouter structured outputs).
|
||||
FIX: Intelligente Rate-Limit Erkennung (429 Handling), v1-API Sync & Timeouts.
|
||||
VERSION: 3.3.9
|
||||
WP-25: Integration der DecisionEngine für Agentic Multi-Stream RAG.
|
||||
VERSION: 3.4.1
|
||||
STATUS: Active
|
||||
FIX:
|
||||
- Importiert clean_llm_text von app.core.registry zur Vermeidung von Circular Imports.
|
||||
- Wendet clean_llm_text auf Text-Antworten in generate_raw_response an.
|
||||
- 100% Wiederherstellung der v3.3.9 Logik (Rate-Limits, Retries, Async-Threads).
|
||||
- Integration des WP-25 DecisionEngine Bridges in generate_rag_response.
|
||||
- WP-25 Empty-Response-Guard für Cloud-Provider.
|
||||
"""
|
||||
import httpx
|
||||
import yaml
|
||||
@@ -29,7 +31,6 @@ from app.core.registry import clean_llm_text
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LLMService:
|
||||
# GLOBALER SEMAPHOR für Hintergrund-Last Steuerung (WP-06)
|
||||
_background_semaphore = None
|
||||
@@ -37,6 +38,9 @@ class LLMService:
|
||||
def __init__(self):
|
||||
self.settings = get_settings()
|
||||
self.prompts = self._load_prompts()
|
||||
|
||||
# WP-25: Lazy Initialization der DecisionEngine zur Vermeidung von Circular Imports
|
||||
self._decision_engine = None
|
||||
|
||||
# Initialisiere Semaphore einmalig auf Klassen-Ebene
|
||||
if LLMService._background_semaphore is None:
|
||||
@@ -71,6 +75,14 @@ class LLMService:
|
||||
)
|
||||
logger.info("🛰️ LLMService: OpenRouter Integration active.")
|
||||
|
||||
@property
|
||||
def decision_engine(self):
|
||||
"""Lazy Initialization der Decision Engine (WP-25)."""
|
||||
if self._decision_engine is None:
|
||||
from app.core.retrieval.decision_engine import DecisionEngine
|
||||
self._decision_engine = DecisionEngine()
|
||||
return self._decision_engine
|
||||
|
||||
def _load_prompts(self) -> dict:
|
||||
"""Lädt die Prompt-Konfiguration aus der YAML-Datei."""
|
||||
path = Path(self.settings.PROMPTS_PATH)
|
||||
@@ -132,14 +144,18 @@ class LLMService:
|
||||
max_retries, base_delay, model_override,
|
||||
json_schema, json_schema_name, strict_json_schema
|
||||
)
|
||||
# WP-14 Fix: Bereinige Text-Antworten vor Rückgabe
|
||||
return clean_llm_text(res) if not force_json else res
|
||||
else:
|
||||
res = await self._dispatch(
|
||||
target_provider, prompt, system, force_json,
|
||||
max_retries, base_delay, model_override,
|
||||
json_schema, json_schema_name, strict_json_schema
|
||||
)
|
||||
|
||||
# WP-25 Empty Response Fix: Wenn Cloud-Provider leer antworten, Fallback auf Ollama
|
||||
if (not res or len(res.strip()) < 5) and target_provider != "ollama":
|
||||
logger.warning(f"⚠️ [WP-25] Empty response from {target_provider}. Falling back to OLLAMA.")
|
||||
res = await self._execute_ollama(prompt, system, force_json, max_retries, base_delay)
|
||||
|
||||
res = await self._dispatch(
|
||||
target_provider, prompt, system, force_json,
|
||||
max_retries, base_delay, model_override,
|
||||
json_schema, json_schema_name, strict_json_schema
|
||||
)
|
||||
# WP-14 Fix: Bereinige Text-Antworten vor Rückgabe
|
||||
return clean_llm_text(res) if not force_json else res
|
||||
|
||||
@@ -295,21 +311,16 @@ class LLMService:
|
||||
logger.warning(f"⚠️ Ollama attempt {attempt} failed. Retrying in {wait_time}s...")
|
||||
await asyncio.sleep(wait_time)
|
||||
|
||||
async def generate_rag_response(self, query: str, context_str: str) -> str:
|
||||
"""Vollständiges RAG Chat-Interface."""
|
||||
provider = self.settings.MINDNET_LLM_PROVIDER
|
||||
system_prompt = self.get_prompt("system_prompt", provider)
|
||||
rag_template = self.get_prompt("rag_template", provider)
|
||||
|
||||
final_prompt = rag_template.format(context_str=context_str, query=query)
|
||||
|
||||
# RAG Aufrufe im Chat nutzen nun standardmäßig max_retries=2 (überschreibbar)
|
||||
# Durch den Aufruf von generate_raw_response wird die Bereinigung automatisch angewendet.
|
||||
return await self.generate_raw_response(
|
||||
final_prompt,
|
||||
system=system_prompt,
|
||||
priority="realtime"
|
||||
)
|
||||
async def generate_rag_response(self, query: str, context_str: Optional[str] = None) -> str:
|
||||
"""
|
||||
WP-25 UPDATE: Der primäre Einstiegspunkt für den MindNet Chat.
|
||||
Delegiert nun an die DecisionEngine für Agentic Multi-Stream RAG.
|
||||
Falls context_str bereits vorhanden ist (Legacy), wird dieser ignoriert zugunsten
|
||||
der präzisen Multi-Stream Orchestrierung.
|
||||
"""
|
||||
logger.info(f"🚀 [WP-25] Chat Query intercepted: {query[:50]}...")
|
||||
# Die DecisionEngine übernimmt nun das gesamte Management (Routing, Retrieval, Synthesis)
|
||||
return await self.decision_engine.ask(query)
|
||||
|
||||
async def close(self):
|
||||
"""Schließt die HTTP-Verbindungen."""
|
||||
|
||||
Reference in new issue
Block a user