update
This commit is contained in:
@@ -25,6 +25,7 @@ from database import (
|
||||
delete_pending_suggestions,
|
||||
list_bausteine,
|
||||
update_baustein,
|
||||
update_baustein_sort_orders,
|
||||
)
|
||||
from paths import final_paths, temp_paths
|
||||
|
||||
@@ -327,12 +328,17 @@ async def _fail(guide_id: str, msg: str) -> None:
|
||||
# --- Bausteine ---
|
||||
|
||||
_suggestions_generating: set[str] = set()
|
||||
_sorting: set[str] = set()
|
||||
|
||||
|
||||
def is_suggestions_generating(topic: str) -> bool:
|
||||
return topic in _suggestions_generating
|
||||
|
||||
|
||||
def is_sorting(topic: str) -> bool:
|
||||
return topic in _sorting
|
||||
|
||||
|
||||
def _parse_json(text: str):
|
||||
text = text.strip()
|
||||
text = re.sub(r"^```(?:json)?\s*", "", text)
|
||||
@@ -484,6 +490,8 @@ async def rework_baustein(baustein_id: str, topic: str, title: str, current: dic
|
||||
|
||||
|
||||
def _build_baustein_rework_prompt(topic: str, title: str, current: dict, instructions: str) -> str:
|
||||
spec = (TEMPLATES_DIR / "Format" / "Baustein.md").read_text(encoding="utf-8")
|
||||
|
||||
current_json = json.dumps({
|
||||
"title": title,
|
||||
"description": current.get("description", ""),
|
||||
@@ -499,9 +507,53 @@ AKTUELLER STAND:
|
||||
ANWEISUNGEN VOM NUTZER:
|
||||
{instructions}
|
||||
|
||||
FORMAT-SPEZIFIKATION:
|
||||
{spec}
|
||||
|
||||
Antworte AUSSCHLIESSLICH mit einem JSON-Objekt mit den Feldern "title", "description", "purpose", "examples".
|
||||
"examples" ist ein Array mit Objekten {{"label": "...", "code": "..."}}.
|
||||
Kein weiterer Text, nur das JSON.
|
||||
Orientiere dich an der Spezifikation. Kein weiterer Text, nur das JSON.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
def _build_sort_prompt(topic: str, bausteine: list[dict], instructions: str) -> str:
|
||||
items = "\n".join(
|
||||
f"- id={b['id']} | {b['title']} | {b['description']} | {b['purpose']}"
|
||||
for b in bausteine
|
||||
)
|
||||
if instructions:
|
||||
criterion = f"Sortiere die folgenden Bausteine zum Thema \"{topic}\" STRIKT nach diesem Kriterium:\n\n{instructions}"
|
||||
else:
|
||||
criterion = f"Sortiere die folgenden Bausteine zum Thema \"{topic}\" von Anfaenger zu Experte (erstes = einfachster, letztes = komplexester)."
|
||||
|
||||
return f"""{criterion}
|
||||
|
||||
BAUSTEINE:
|
||||
{items}
|
||||
|
||||
Antworte AUSSCHLIESSLICH mit einem JSON-Array der IDs in der gewuenschten Reihenfolge.
|
||||
Beispiel: [\"id1\", \"id2\", \"id3\"]
|
||||
|
||||
Kein weiterer Text, nur das JSON-Array.
|
||||
"""
|
||||
|
||||
|
||||
async def sort_bausteine(topic: str, bausteine: list[dict], instructions: str = "") -> None:
|
||||
_sorting.add(topic)
|
||||
try:
|
||||
prompt = _build_sort_prompt(topic, bausteine, instructions)
|
||||
returncode, stdout, stderr = await _run_claude("sort-" + topic, prompt, 300, tools=None, model=MODEL_BAUSTEIN_GEN)
|
||||
if returncode != 0:
|
||||
return
|
||||
ids = _parse_json(stdout)
|
||||
if not isinstance(ids, list):
|
||||
return
|
||||
order_map = {bid: i for i, bid in enumerate(ids) if isinstance(bid, str)}
|
||||
if order_map:
|
||||
await update_baustein_sort_orders(topic, order_map)
|
||||
except Exception as e:
|
||||
print(f"[sort] topic={topic} Exception: {type(e).__name__}: {e}")
|
||||
finally:
|
||||
_sorting.discard(topic)
|
||||
|
||||
Reference in New Issue
Block a user