1.5.5: Neue evaluate_branche_chatgpt mit erweitertem Logging und exakter Branchenabgleich
- Alle verwendeten Input-Werte (CRM-Branche, externe Beschreibung, Wiki-Daten, Website-Zusammenfassung) werden geloggt. - Bei fehlendem Wikipedia-Eintrag wird explizit die Website-Zusammenfassung als Fallback genutzt. - Normierte Eingabewerte und Ziel-Branchenschema werden für den exakten Vergleich ausgegeben. - Es werden ausschließlich Branchen aus dem Ziel-Schema akzeptiert – ansonsten Rückgabe "k.A." mit Konsistenz "X".
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Version: v1.5.4
|
||||
Version: v1.5.5
|
||||
Datum: {aktuelles Datum}
|
||||
Git-Überschrift (max. 100 Zeichen):
|
||||
1.5.4: Dispatcher und modulare Batch-Prozesse für Wiki, Website und Branch integriert
|
||||
@@ -40,7 +40,7 @@ except ImportError:
|
||||
|
||||
# ==================== KONFIGURATION ====================
|
||||
class Config:
|
||||
VERSION = "v1.5.4"
|
||||
VERSION = "v1.5.5"
|
||||
LANG = "de"
|
||||
CREDENTIALS_FILE = "service_account.json"
|
||||
SHEET_URL = "https://docs.google.com/spreadsheets/d/1u_gHr9JUfmV1-iviRzbSe3575QEp7KLhK5jFV_gJcgo"
|
||||
@@ -1408,15 +1408,16 @@ class WikipediaScraper:
|
||||
def evaluate_branche_chatgpt(crm_branche, beschreibung, wiki_branche, wiki_kategorien, website_summary):
|
||||
def load_target_branches():
|
||||
try:
|
||||
with open("ziel_Branchenschema.csv", "r", encoding="utf-8") as csvfile:
|
||||
with open("ziel_Branchenschema.csv", "r", encoding="utf-8-sig") as csvfile:
|
||||
reader = csv.reader(csvfile)
|
||||
branches = [row[0] for row in reader if row]
|
||||
branches = [row[0].strip() for row in reader if row and row[0].strip()]
|
||||
return branches
|
||||
except Exception as e:
|
||||
debug_print(f"Fehler beim Laden des Ziel-Branchenschemas: {e}")
|
||||
return []
|
||||
target_branches = load_target_branches()
|
||||
target_branches_str = "\n".join(target_branches)
|
||||
|
||||
focus_branches = [
|
||||
"Gutachter / Versicherungen > Baugutachter",
|
||||
"Gutachter / Versicherungen > Technische Gutachten",
|
||||
@@ -1435,6 +1436,8 @@ def evaluate_branche_chatgpt(crm_branche, beschreibung, wiki_branche, wiki_kateg
|
||||
"Versorger > Telekommunikation"
|
||||
]
|
||||
focus_branches_str = "\n".join(focus_branches)
|
||||
|
||||
# API-Key laden
|
||||
try:
|
||||
with open("api_key.txt", "r") as f:
|
||||
api_key = f.read().strip()
|
||||
@@ -1443,13 +1446,13 @@ def evaluate_branche_chatgpt(crm_branche, beschreibung, wiki_branche, wiki_kateg
|
||||
return {"branch": "k.A.", "consistency": "k.A.", "justification": "k.A."}
|
||||
openai.api_key = api_key
|
||||
|
||||
# Falls kein Wikipedia-Artikel vorliegt, nutze die Website-Zusammenfassung als Fallback für die Branchenbeschreibung
|
||||
# Entscheide, welche Branchenbeschreibung genutzt wird.
|
||||
if wiki_branche.strip().lower() == "k.a.":
|
||||
debug_print("Kein Wikipedia-Artikel vorhanden – verwende Website-Zusammenfassung als Branchenbeschreibung-Fallback.")
|
||||
used_description = website_summary
|
||||
else:
|
||||
used_description = beschreibung
|
||||
debug_print(f"Verwendete Angaben: CRM-Branche='{crm_branche}', externe Beschreibung='{beschreibung}', Wiki-Branche='{wiki_branche}', Wiki-Kategorien='{wiki_kategorien}'")
|
||||
debug_print(f"Verwendete Angaben: CRM-Branche='{crm_branche}', externe Beschreibung='{beschreibung}', Wiki-Branche='{wiki_branche}', Wiki-Kategorien='{wiki_kategorien}', Website-Zusammenfassung='{website_summary}'")
|
||||
|
||||
system_prompt = (
|
||||
"Du bist ein Experte im Field Service Management. Deine Aufgabe ist es, ein Unternehmen basierend auf folgenden Angaben einer Branche zuzuordnen.\n\n"
|
||||
@@ -1479,40 +1482,47 @@ def evaluate_branche_chatgpt(crm_branche, beschreibung, wiki_branche, wiki_kateg
|
||||
)
|
||||
result = response.choices[0].message.content.strip()
|
||||
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:
|
||||
debug_print(f"Fehler beim Aufruf der ChatGPT API für Branchenabgleich: {e}")
|
||||
return {"branch": "k.A.", "consistency": "k.A.", "justification": "k.A."}
|
||||
|
||||
|
||||
|
||||
# Ergebnis aus der Antwort parsen
|
||||
chat_branch = None
|
||||
chat_consistency = None
|
||||
chat_justification = ""
|
||||
for line in result.split("\n"):
|
||||
lower_line = line.lower()
|
||||
if lower_line.startswith("branche:"):
|
||||
chat_branch = line.split(":", 1)[1].strip()
|
||||
elif lower_line.startswith("übereinstimmung:"):
|
||||
chat_consistency = line.split(":", 1)[1].strip()
|
||||
elif lower_line.startswith("begründung:"):
|
||||
chat_justification = line.split(":", 1)[1].strip()
|
||||
|
||||
debug_print(f"Aus der Antwort extrahiert: Branche='{chat_branch}', Übereinstimmung='{chat_consistency}', Begründung='{chat_justification}'")
|
||||
|
||||
# Normiere CRM-Branche und ChatGPT-Ergebnis für Vergleich
|
||||
norm_crm = normalize_company_name(crm_branche)
|
||||
norm_chat = normalize_company_name(chat_branch) if chat_branch else ""
|
||||
debug_print(f"Normierte Werte: CRM='{norm_crm}', ChatGPT-Vorschlag='{norm_chat}'")
|
||||
|
||||
# Erzeuge eine Liste normierter Zielbranchen
|
||||
norm_targets = [normalize_company_name(tb) for tb in target_branches]
|
||||
debug_print(f"Normierte Zielbranchen: {norm_targets}")
|
||||
|
||||
# Überprüfe, ob der ChatGPT-Vorschlag im Ziel-Schema enthalten ist
|
||||
if not norm_chat or norm_chat not in norm_targets:
|
||||
debug_print(f"Vorgeschlagene Branche '{chat_branch}' entspricht nicht dem Ziel-Branchenschema.")
|
||||
return {"branch": "k.A.", "consistency": "X", "justification": "Vorgeschlagene Branche entspricht nicht dem Ziel-Branchenschema."}
|
||||
else:
|
||||
# Vergleiche den normierten CRM-Wert mit dem ChatGPT-Vorschlag
|
||||
if norm_crm and norm_crm == norm_chat:
|
||||
chat_consistency = "ok"
|
||||
chat_justification = ""
|
||||
else:
|
||||
chat_consistency = "X"
|
||||
debug_print(f"Endergebnis Branchenbewertung: Branche='{chat_branch}', Übereinstimmung='{chat_consistency}', Begründung='{chat_justification}'")
|
||||
return {"branch": chat_branch, "consistency": chat_consistency, "justification": chat_justification}
|
||||
|
||||
|
||||
def evaluate_servicetechnicians_estimate(company_name, company_data):
|
||||
|
||||
Reference in New Issue
Block a user