diff --git a/app/routers/chat.py b/app/routers/chat.py index ae44547..986c131 100644 --- a/app/routers/chat.py +++ b/app/routers/chat.py @@ -1,8 +1,9 @@ """ FILE: app/routers/chat.py DESCRIPTION: Haupt-Chat-Interface (RAG & Interview). Enthält Intent-Router (Keywords/LLM) und Prompt-Construction. -VERSION: 2.7.0 (WP-22 Semantic Graph Routing) +VERSION: 2.7.1 (WP-22 Semantic Graph Routing) STATUS: Active +FIX: Umstellung auf llm.get_prompt() zur Behebung des 500 Server Errors (Dictionary replace crash). DEPENDENCIES: app.config, app.models.dto, app.services.llm_service, app.core.retriever, app.services.feedback_service EXTERNAL_CONFIG: config/decision_engine.yaml, config/types.yaml """ @@ -199,7 +200,8 @@ async def _classify_intent(query: str, llm: LLMService) -> tuple[str, str]: # 3. SLOW PATH: LLM Router if settings.get("llm_fallback_enabled", False): - router_prompt_template = llm.prompts.get("router_prompt", "") + # FIX: Nutze get_prompt statt direktem Zugriff auf dict + router_prompt_template = llm.get_prompt("router_prompt") if router_prompt_template: prompt = router_prompt_template.replace("{query}", query) @@ -262,7 +264,8 @@ async def chat_endpoint( logger.info(f"[{query_id}] Interview Type: {target_type}. Fields: {len(fields_list)}") fields_str = "\n- " + "\n- ".join(fields_list) - template = llm.prompts.get(prompt_key, "") + # FIX: Nutze get_prompt() zur Auflösung der provider-spezifischen Templates + template = llm.get_prompt(prompt_key) final_prompt = template.replace("{context_str}", "Dialogverlauf...") \ .replace("{query}", request.message) \ .replace("{target_type}", target_type) \ @@ -276,7 +279,6 @@ async def chat_endpoint( prepend_instr = strategy.get("prepend_instruction", "") # --- WP-22: Semantic Graph Routing (Teil C) --- - # Wir laden die konfigurierten Edge-Boosts für diesen Intent edge_boosts = strategy.get("edge_boosts", {}) if edge_boosts: logger.info(f"[{query_id}] Applying Edge Boosts: {edge_boosts}") @@ -286,7 +288,6 @@ async def chat_endpoint( mode="hybrid", top_k=request.top_k, explain=request.explain, - # WP-22: Boosts an den Retriever weitergeben boost_edges=edge_boosts ) retrieve_result = await retriever.search(query_req) @@ -299,7 +300,6 @@ async def chat_endpoint( top_k=3, filters={"type": inject_types}, explain=False, - # WP-22: Boosts auch hier anwenden (Konsistenz) boost_edges=edge_boosts ) strategy_result = await retriever.search(strategy_req) @@ -313,8 +313,12 @@ async def chat_endpoint( else: context_str = _build_enriched_context(hits) - template = llm.prompts.get(prompt_key, "{context_str}\n\n{query}") + # FIX: Nutze get_prompt() zur Auflösung der provider-spezifischen Templates + template = llm.get_prompt(prompt_key) + if not template: + template = "{context_str}\n\n{query}" + if prepend_instr: context_str = f"{prepend_instr}\n\n{context_str}" @@ -322,7 +326,7 @@ async def chat_endpoint( sources_hits = hits # --- GENERATION --- - system_prompt = llm.prompts.get("system_prompt", "") + system_prompt = llm.get_prompt("system_prompt") # Chat nutzt IMMER realtime priority answer_text = await llm.generate_raw_response(