This commit is contained in:
team3
2026-09-17 19:10:10 +02:00
parent ea54a86db4
commit 33b3975b61
8 changed files with 620 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import secrets
import time
from apscheduler.schedulers.asyncio import AsyncIOScheduler
import httpx
from fastapi import Body, Cookie, FastAPI, HTTPException, Request, Response
from fastapi.responses import StreamingResponse
from fastapi.middleware.cors import CORSMiddleware
@@ -15,6 +16,7 @@ from . import (
db,
events,
features,
ki,
search,
streamproxy,
suggestions,
@@ -231,6 +233,59 @@ async def aehnliche_filme(
return []
@app.post("/api/ki-suche")
async def ki_suche(
response: Response,
beschreibung: str = Body("", embed=True),
mit_sammlung: bool = Body(False, embed=True),
ohne_gesehene: bool = Body(True, embed=True),
include: str = Body("", embed=True),
exclude: str = Body("", embed=True),
stimmen_min: int | None = Body(None, embed=True),
stimmen_max: int | None = Body(None, embed=True),
dauer_min: int | None = Body(None, embed=True),
dauer_max: int | None = Body(None, embed=True),
jahr_min: int | None = Body(None, embed=True),
jahr_max: int | None = Body(None, embed=True),
note_min: float | None = Body(None, embed=True),
note_max: float | None = Body(None, embed=True),
filmabend_sid: str | None = Cookie(None),
):
"""Vorschläge von der KI, bei TMDB nachgeschlagen. Die eigene Sammlung
geht auf Wunsch mit, die gesehenen Filme als Ausschluss. Die Filter
der Leiste sind Vorgaben an die KI und danach ein Sieb."""
sid = sitzung(response, filmabend_sid)
filter_ = {
"include": [g for g in include.split(",") if g],
"exclude": [g for g in exclude.split(",") if g],
"stimmen_min": stimmen_min,
"stimmen_max": stimmen_max,
"dauer_min": dauer_min,
"dauer_max": dauer_max,
"jahr_min": jahr_min,
"jahr_max": jahr_max,
"note_min": note_min,
"note_max": note_max,
}
beschreibung = beschreibung.strip()[: ki.MAX_BESCHREIBUNG]
sammlung = (
[ki.etikett(e) for e in wishlist.alle(sid) if e["mine"]] if mit_sammlung else []
)
if not beschreibung and not sammlung and not ki.vorgaben(filter_):
raise HTTPException(
status_code=400, detail="Beschreib, was du suchst, oder gib die Sammlung mit."
)
gesehen = watched.alle(sid)
try:
vorschlaege = await ki.fragen(
beschreibung, sammlung, [ki.etikett(g) for g in gesehen], filter_
)
except (httpx.HTTPError, KeyError, IndexError):
raise HTTPException(status_code=502, detail="Die KI antwortet gerade nicht.")
ausser = {g["movie_id"] for g in gesehen} if ohne_gesehene else set()
return await ki.aufloesen(vorschlaege, filter_, ausser=ausser)
@app.get("/api/search/{movie_id}")
async def search_detail(movie_id: int):
"""Volle Daten zu einem Suchtreffer. Erst der Katalog, dann TMDB."""