Fix: SyntaxError im User-Prompt durch \n innerhalb f-String behoben
- ersetzt echten Zeilenumbruch durch escape-Zeichen `\n` innerhalb f-Strings - Prompt wird nun korrekt an GPT übergeben
This commit is contained in:
@@ -96,6 +96,32 @@ system_prompt = {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# === GPT BEWERTUNG ===
|
||||||
|
def classify_company(row, wikipedia_url=""):
|
||||||
|
user_prompt = {
|
||||||
|
"role": "user",
|
||||||
|
"content": (
|
||||||
|
f"{row[0]};{row[1]};{row[2]};{row[4]};{row[5]}\n"
|
||||||
|
f"Wikipedia-Link: {wikipedia_url}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
response = openai.chat.completions.create(
|
||||||
|
model="gpt-3.5-turbo",
|
||||||
|
messages=[system_prompt, user_prompt],
|
||||||
|
temperature=0
|
||||||
|
)
|
||||||
|
full_text = response.choices[0].message.content.strip()
|
||||||
|
lines = full_text.splitlines()
|
||||||
|
csv_line = next((l for l in lines if ";" in l and not l.lower().startswith("wikipedia-branche")), "")
|
||||||
|
parts = [v.strip().strip('"') for v in csv_line.split(";")] if csv_line else []
|
||||||
|
if len(parts) != 8:
|
||||||
|
print("⚠️ Antwort unvollständig → Setze alles auf 'k.A.'")
|
||||||
|
parts = ["k.A."] * 8
|
||||||
|
with open(LOG_CSV, "a", newline="", encoding="utf-8") as log:
|
||||||
|
writer = csv.writer(log, delimiter=";")
|
||||||
|
writer.writerow([row[0], *parts, full_text])
|
||||||
|
return parts
|
||||||
|
|
||||||
# === WIKIPEDIA DATEN LADEN ===
|
# === WIKIPEDIA DATEN LADEN ===
|
||||||
# Positivliste für Wikipedia-Kategorien, die auf Unternehmen hinweisen können
|
# Positivliste für Wikipedia-Kategorien, die auf Unternehmen hinweisen können
|
||||||
WHITELIST_KATEGORIEN = [
|
WHITELIST_KATEGORIEN = [
|
||||||
@@ -120,7 +146,6 @@ def get_wikipedia_data(name, website_hint=""):
|
|||||||
for title in results:
|
for title in results:
|
||||||
try:
|
try:
|
||||||
page = wikipedia.page(title)
|
page = wikipedia.page(title)
|
||||||
# Titelprüfung verbessern
|
|
||||||
if any(x in page.title.lower() for x in ["krankenkasse", "versicherung"]):
|
if any(x in page.title.lower() for x in ["krankenkasse", "versicherung"]):
|
||||||
continue
|
continue
|
||||||
url = page.url
|
url = page.url
|
||||||
@@ -131,7 +156,6 @@ def get_wikipedia_data(name, website_hint=""):
|
|||||||
continue
|
continue
|
||||||
if name.lower().split()[0] not in page.title.lower():
|
if name.lower().split()[0] not in page.title.lower():
|
||||||
continue
|
continue
|
||||||
url = page.url
|
|
||||||
soup = BeautifulSoup(html, 'html.parser')
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
infobox = soup.find("table", class_=["infobox", "infobox vcard"])
|
infobox = soup.find("table", class_=["infobox", "infobox vcard"])
|
||||||
if not infobox:
|
if not infobox:
|
||||||
@@ -165,33 +189,6 @@ def get_wikipedia_data(name, website_hint=""):
|
|||||||
continue
|
continue
|
||||||
return "", "k.A.", "k.A."
|
return "", "k.A.", "k.A."
|
||||||
|
|
||||||
# === GPT BEWERTUNG ===
|
|
||||||
def classify_company(row, wikipedia_url=""):
|
|
||||||
user_prompt = {
|
|
||||||
"role": "user",
|
|
||||||
"content": (
|
|
||||||
f"{row[0]};{row[1]};{row[2]};{row[4]};{row[5]}
|
|
||||||
"
|
|
||||||
f"Wikipedia-Link: {wikipedia_url}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
response = openai.chat.completions.create(
|
|
||||||
model="gpt-3.5-turbo",
|
|
||||||
messages=[system_prompt, user_prompt],
|
|
||||||
temperature=0
|
|
||||||
)
|
|
||||||
full_text = response.choices[0].message.content.strip()
|
|
||||||
lines = full_text.splitlines()
|
|
||||||
csv_line = next((l for l in lines if ";" in l and not l.lower().startswith("wikipedia-branche")), "")
|
|
||||||
parts = [v.strip().strip('"') for v in csv_line.split(";")] if csv_line else []
|
|
||||||
if len(parts) != 8:
|
|
||||||
print("⚠️ Antwort unvollständig → Setze alles auf 'k.A.'")
|
|
||||||
parts = ["k.A."] * 8
|
|
||||||
with open(LOG_CSV, "a", newline="", encoding="utf-8") as log:
|
|
||||||
writer = csv.writer(log, delimiter=";")
|
|
||||||
writer.writerow([row[0], *parts, full_text])
|
|
||||||
return parts
|
|
||||||
|
|
||||||
# === VERARBEITUNG ===
|
# === VERARBEITUNG ===
|
||||||
for i in range(start, min(start + DURCHLÄUFE, len(sheet_values))):
|
for i in range(start, min(start + DURCHLÄUFE, len(sheet_values))):
|
||||||
row = sheet_values[i]
|
row = sheet_values[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user