update
This commit is contained in:
@@ -550,6 +550,36 @@ Kein weiterer Text, nur das JSON-Array.
|
||||
"""
|
||||
|
||||
|
||||
def _build_topic_suggest_prompt(problem: str, existing_topics: list[str]) -> str:
|
||||
template = (TEMPLATES_DIR / "Format" / "Suche.md").read_text(encoding="utf-8")
|
||||
existing = "\n".join(f"- {t}" for t in existing_topics) if existing_topics else "(keine)"
|
||||
return template.replace("{problem}", problem).replace("{existing}", existing)
|
||||
|
||||
|
||||
async def suggest_topics(problem: str, existing_topics: list[str] | None = None) -> list[dict]:
|
||||
try:
|
||||
prompt = _build_topic_suggest_prompt(problem, existing_topics or [])
|
||||
returncode, stdout, stderr = await _run_claude(
|
||||
"topic-suggest-" + str(uuid.uuid4()), prompt, 120, tools=None, model=MODEL_BAUSTEIN_GEN
|
||||
)
|
||||
if returncode != 0:
|
||||
return []
|
||||
items = _parse_json(stdout)
|
||||
if not isinstance(items, list):
|
||||
return []
|
||||
result = []
|
||||
for item in items:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
title = str(item.get("title", "")).strip()[:100]
|
||||
if not title:
|
||||
continue
|
||||
result.append({"title": title, "reason": str(item.get("reason", "")).strip()})
|
||||
return result
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
|
||||
async def sort_bausteine(topic: str, bausteine: list[dict], instructions: str = "") -> None:
|
||||
_sorting.add(topic)
|
||||
try:
|
||||
|
||||
@@ -68,3 +68,12 @@ class SuggestionResponse(BaseModel):
|
||||
example: str
|
||||
status: str
|
||||
created_at: str
|
||||
|
||||
|
||||
class TopicSuggestRequest(BaseModel):
|
||||
problem: str = Field(min_length=1, max_length=2000)
|
||||
|
||||
|
||||
class TopicSuggestion(BaseModel):
|
||||
title: str
|
||||
reason: str
|
||||
|
||||
@@ -11,10 +11,11 @@ from database import (
|
||||
create_baustein as db_create_baustein, list_bausteine, get_baustein, delete_baustein as db_delete_baustein,
|
||||
list_suggestions, get_suggestion, update_suggestion, delete_suggestion,
|
||||
)
|
||||
from generator import generate_guide, rework_guide, cancel_guide, generate_suggestions, generate_baustein_detail, rework_baustein, sort_bausteine, is_suggestions_generating, is_sorting
|
||||
from generator import generate_guide, rework_guide, cancel_guide, generate_suggestions, generate_baustein_detail, rework_baustein, sort_bausteine, suggest_topics, is_suggestions_generating, is_sorting
|
||||
from models import (
|
||||
GuideCreateRequest, GuideReworkRequest, GuideResponse,
|
||||
BausteinCreateRequest, BausteinReworkRequest, BausteinSortRequest, BausteinResponse, SuggestionResponse,
|
||||
TopicSuggestRequest, TopicSuggestion,
|
||||
)
|
||||
from paths import final_paths
|
||||
|
||||
@@ -26,6 +27,13 @@ async def get_formats():
|
||||
return FORMAT_META
|
||||
|
||||
|
||||
@router.post("/topic-suggestions", response_model=list[TopicSuggestion])
|
||||
async def topic_suggestions(req: TopicSuggestRequest):
|
||||
guides = await list_guides()
|
||||
existing_topics = sorted({g["topic"] for g in guides})
|
||||
return await suggest_topics(req.problem.strip(), existing_topics)
|
||||
|
||||
|
||||
@router.post("/guides", response_model=GuideResponse)
|
||||
async def create(req: GuideCreateRequest):
|
||||
now = datetime.now(timezone.utc).isoformat()
|
||||
|
||||
Reference in New Issue
Block a user