Post Typen Verwalten + Strategy weight

This commit is contained in:
2026-02-14 14:48:03 +01:00
parent 1ebf50ab04
commit 31150000fd
14 changed files with 2624 additions and 43 deletions

View File

@@ -184,8 +184,10 @@ class PostClassifierAgent(BaseAgent):
system_prompt = """Du bist ein Content-Analyst, der LinkedIn-Posts in vordefinierte Kategorien einordnet.
WICHTIG: JEDER Post MUSS kategorisiert werden. Du MUSST für jeden Post den am besten passenden Post-Typ wählen, auch wenn die Übereinstimmung nicht perfekt ist.
Analysiere jeden Post und ordne ihn dem passendsten Post-Typ zu.
Wenn kein Typ wirklich passt, gib "null" als post_type_id zurück.
Es ist NICHT erlaubt, "null" als post_type_id zurückzugeben.
Bewerte die Zuordnung mit einer Confidence zwischen 0.3 und 1.0:
- 0.9-1.0: Sehr sicher, Post passt perfekt zum Typ
@@ -209,12 +211,14 @@ Gib ein JSON-Objekt zurück mit diesem Format:
"classifications": [
{{
"post_id": "uuid-des-posts",
"post_type_id": "uuid-des-typs oder null",
"post_type_id": "uuid-des-typs (IMMER erforderlich, niemals null)",
"confidence": 0.8,
"reasoning": "Kurze Begründung"
}}
]
}}"""
}}
WICHTIG: Jeder Post MUSS einen post_type_id bekommen. Wähle den am besten passenden Typ, auch wenn die Übereinstimmung nicht perfekt ist."""
try:
response = await self.call_openai(
@@ -230,6 +234,8 @@ Gib ein JSON-Objekt zurück mit diesem Format:
# Process and validate results
valid_results = []
unclassified_posts = list(posts) # Track which posts still need classification
for c in classifications:
post_id = c.get("post_id")
post_type_id = c.get("post_type_id")
@@ -244,7 +250,8 @@ Gib ein JSON-Objekt zurück mit diesem Format:
# Validate post_type_id
if post_type_id and post_type_id != "null" and post_type_id not in valid_type_ids:
logger.warning(f"Invalid post_type_id in classification: {post_type_id}")
continue
# Fallback: assign to first available type
post_type_id = list(valid_type_ids - {"null"})[0] if valid_type_ids - {"null"} else None
if post_type_id and post_type_id != "null":
valid_results.append({
@@ -253,6 +260,19 @@ Gib ein JSON-Objekt zurück mit diesem Format:
"classification_method": "semantic",
"classification_confidence": min(1.0, max(0.3, confidence))
})
unclassified_posts = [p for p in unclassified_posts if p.id != matching_post.id]
# FORCE CLASSIFY remaining unclassified posts
if unclassified_posts and post_types:
default_type = post_types[0] # Use first type as fallback
logger.warning(f"Force-classifying {len(unclassified_posts)} posts to default type: {default_type.name}")
for post in unclassified_posts:
valid_results.append({
"post_id": post.id,
"post_type_id": default_type.id,
"classification_method": "semantic_fallback",
"classification_confidence": 0.3
})
return valid_results