This commit is contained in:
2025-07-01 07:11:25 +00:00
parent 6398808c03
commit a48b785508

View File

@@ -894,6 +894,7 @@ def summarize_batch_openai(tasks_data):
# 9. OPENAI API WRAPPER (BRANCH EVALUATION)
# ==============================================================================
@retry_on_failure
@retry_on_failure
def evaluate_branche_chatgpt(crm_branche, beschreibung, wiki_branche, wiki_kategorien, website_summary):
"""
@@ -904,10 +905,10 @@ def evaluate_branche_chatgpt(crm_branche, beschreibung, wiki_branche, wiki_kateg
from config import TARGET_SCHEMA_STRING, FOCUS_BRANCHES_PROMPT_PART, ALLOWED_TARGET_BRANCHES
# NEU: Lazy Loading des Branchenschemas
# Lazy Loading des Branchenschemas
if not ALLOWED_TARGET_BRANCHES:
logger.warning("Branchenschema nicht geladen. Versuche es jetzt zu laden...")
if not initialize_target_schema(): # <<< HIER GEÄNDERT
if not initialize_target_schema():
logger.critical("FEHLER in evaluate_branche_chatgpt: Ziel-Branchenschema konnte auch bei Bedarf nicht geladen werden. Breche Evaluation ab.")
return {
"branch": "FEHLER - SCHEMA FEHLT",
@@ -983,7 +984,7 @@ def evaluate_branche_chatgpt(crm_branche, beschreibung, wiki_branche, wiki_kateg
parsed_branch = False
parsed_confidence = False
for line in lines:
for line in lines:
line_stripped = line.strip()
line_lower = line_stripped.lower() # WICHTIG: Variable wieder einführen
@@ -1008,13 +1009,13 @@ for line in lines:
if result["justification"]: result["justification"] += " " + justification_text
else: result["justification"] = justification_text
if not parsed_branch or not suggested_branch or suggested_branch.lower() in ["k.a.", "n/a"]:
logger.error(f"Fehler in evaluate_branche_chatgpt: Konnte 'Branche:' nicht oder nur leer/k.A. aus Antwort parsen: {chat_response[:500]}...")
crm_short_branch_for_fallback = "k.A."
if crm_branche and isinstance(crm_branche, str) and crm_branche.strip().lower() != "k.a.":
crm_short_branch_for_fallback = crm_branche.strip()
if not parsed_branch or not suggested_branch or suggested_branch.lower() in ["k.a.", "n/a"]:
logger.error(f"Fehler in evaluate_branche_chatgpt: Konnte 'Branche:' nicht oder nur leer/k.A. aus Antwort parsen: {chat_response[:500]}...")
crm_short_branch_for_fallback = "k.A."
if crm_branche and isinstance(crm_branche, str) and crm_branche.strip().lower() != "k.a.":
crm_short_branch_for_fallback = crm_branche.strip()
return {
return {
"branch": crm_short_branch_for_fallback if crm_short_branch_for_fallback.lower() != "k.a." else "FEHLER PARSING",
"confidence": result.get("confidence", "N/A"),
"consistency": "error_parsing",