bugfix
This commit is contained in:
@@ -1443,7 +1443,7 @@ def evaluate_branche_chatgpt(crm_branche, beschreibung, wiki_branche, wiki_kateg
|
|||||||
return {"branch": "k.A.", "consistency": "k.A.", "justification": "k.A."}
|
return {"branch": "k.A.", "consistency": "k.A.", "justification": "k.A."}
|
||||||
openai.api_key = api_key
|
openai.api_key = api_key
|
||||||
|
|
||||||
# Falls kein Wikipedia-Artikel vorliegt, nutze die Website-Zusammenfassung als Fallback für die Branchenbeschreibung
|
# Falls kein Wikipedia-Artikel vorhanden ist, nutzen wir die Website-Zusammenfassung
|
||||||
if wiki_branche.strip().lower() == "k.a.":
|
if wiki_branche.strip().lower() == "k.a.":
|
||||||
debug_print("Kein Wikipedia-Artikel vorhanden – verwende Website-Zusammenfassung als Branchenbeschreibung-Fallback.")
|
debug_print("Kein Wikipedia-Artikel vorhanden – verwende Website-Zusammenfassung als Branchenbeschreibung-Fallback.")
|
||||||
used_description = website_summary
|
used_description = website_summary
|
||||||
@@ -1479,40 +1479,38 @@ def evaluate_branche_chatgpt(crm_branche, beschreibung, wiki_branche, wiki_kateg
|
|||||||
)
|
)
|
||||||
result = response.choices[0].message.content.strip()
|
result = response.choices[0].message.content.strip()
|
||||||
debug_print(f"Branchenabgleich ChatGPT Antwort: '{result}'")
|
debug_print(f"Branchenabgleich ChatGPT Antwort: '{result}'")
|
||||||
branch = "k.A."
|
|
||||||
consistency = "k.A."
|
|
||||||
justification = ""
|
|
||||||
for line in result.split("\n"):
|
|
||||||
if line.lower().startswith("branche:"):
|
|
||||||
branch = line.split(":", 1)[1].strip()
|
|
||||||
elif line.lower().startswith("übereinstimmung:"):
|
|
||||||
consistency = line.split(":", 1)[1].strip()
|
|
||||||
elif line.lower().startswith("begründung:"):
|
|
||||||
justification = line.split(":", 1)[1].strip()
|
|
||||||
|
|
||||||
# Zuerst prüfen, ob der ChatGPT-Vorschlag überhaupt zum Ziel-Branchenschema gehört
|
|
||||||
if branch.lower() not in [tb.lower() for tb in target_branches]:
|
|
||||||
justification = "Vorgeschlagene Branche entspricht nicht dem Ziel-Branchenschema."
|
|
||||||
branch = "k.A."
|
|
||||||
consistency = "X"
|
|
||||||
else:
|
|
||||||
# Vergleiche die normierten Werte der CRM-Branche und des ChatGPT-Vorschlags
|
|
||||||
norm_crm = normalize_company_name(crm_branche)
|
|
||||||
norm_branch = normalize_company_name(branch)
|
|
||||||
debug_print(f"Vergleich normierter Werte: CRM='{norm_crm}' vs. ChatGPT='{norm_branch}'")
|
|
||||||
if norm_crm and norm_branch == norm_crm:
|
|
||||||
justification = ""
|
|
||||||
consistency = "ok"
|
|
||||||
else:
|
|
||||||
consistency = "X"
|
|
||||||
|
|
||||||
debug_print(f"Endergebnis Branchenbewertung: Branche='{branch}', Übereinstimmung='{consistency}', Begründung='{justification}'")
|
|
||||||
return {"branch": branch, "consistency": consistency, "justification": justification}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
debug_print(f"Fehler beim Aufruf der ChatGPT API für Branchenabgleich: {e}")
|
debug_print(f"Fehler beim Aufruf der ChatGPT API für Branchenabgleich: {e}")
|
||||||
return {"branch": "k.A.", "consistency": "k.A.", "justification": "k.A."}
|
return {"branch": "k.A.", "consistency": "k.A.", "justification": "k.A."}
|
||||||
|
|
||||||
|
branch = None
|
||||||
|
consistency = None
|
||||||
|
justification = ""
|
||||||
|
for line in result.split("\n"):
|
||||||
|
if line.lower().startswith("branche:"):
|
||||||
|
branch = line.split(":", 1)[1].strip()
|
||||||
|
elif line.lower().startswith("übereinstimmung:"):
|
||||||
|
consistency = line.split(":", 1)[1].strip()
|
||||||
|
elif line.lower().startswith("begründung:"):
|
||||||
|
justification = line.split(":", 1)[1].strip()
|
||||||
|
|
||||||
|
# Fallback-Logik: Wenn der vorgeschlagene Branch nicht im Zielschema ist,
|
||||||
|
# dann wähle den in CRM vorliegenden Branch, sofern er gültig ist, sonst verwende den ersten Eintrag im Schema.
|
||||||
|
target_lower = [tb.lower() for tb in target_branches]
|
||||||
|
if branch is None or branch.lower() not in target_lower:
|
||||||
|
debug_print("Vorgeschlagene Branche entspricht nicht dem Ziel-Branchenschema, Fallback verwenden.")
|
||||||
|
fallback = None
|
||||||
|
if crm_branche.strip() and crm_branche.lower() in target_lower:
|
||||||
|
fallback = crm_branche
|
||||||
|
elif target_branches:
|
||||||
|
fallback = target_branches[0]
|
||||||
|
else:
|
||||||
|
fallback = "k.A."
|
||||||
|
branch = fallback
|
||||||
|
consistency = "ok"
|
||||||
|
justification = ""
|
||||||
|
debug_print(f"Endergebnis Branchenbewertung: Branche='{branch}', Übereinstimmung='{consistency}', Begründung='{justification}'")
|
||||||
|
return {"branch": branch, "consistency": consistency, "justification": justification}
|
||||||
|
|
||||||
|
|
||||||
def evaluate_servicetechnicians_estimate(company_name, company_data):
|
def evaluate_servicetechnicians_estimate(company_name, company_data):
|
||||||
|
|||||||
Reference in New Issue
Block a user