feat: 盲盒想法输入增加 AI 灵感推荐
输入框下方展示灵感建议标签,点击即填入,降低创作门槛: - 房间有 ≥2 条想法时调用 DeepSeek 生成贴合调性的推荐 - 想法不足或 AI 失败时 fallback 到 18 条静态灵感随机选 4 条 - 提交新想法后自动刷新推荐,支持手动换一批
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { requireMembership } from "@/lib/blindbox";
|
||||
import { apiHandler, ApiError, requireUserId } from "@/lib/api";
|
||||
import { suggestIdeas } from "@/lib/ai";
|
||||
|
||||
export const GET = apiHandler(async (req) => {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const roomId = searchParams.get("roomId");
|
||||
const userId = searchParams.get("userId");
|
||||
|
||||
requireUserId(userId);
|
||||
if (!roomId) throw new ApiError("roomId 不能为空");
|
||||
|
||||
await requireMembership(roomId, userId!);
|
||||
|
||||
const recentIdeas = await prisma.blindBoxIdea.findMany({
|
||||
where: { roomId, status: "in_pool" },
|
||||
orderBy: { createdAt: "desc" },
|
||||
take: 10,
|
||||
select: { content: true },
|
||||
});
|
||||
|
||||
if (recentIdeas.length < 2) {
|
||||
return NextResponse.json({ suggestions: [], source: "none" });
|
||||
}
|
||||
|
||||
const suggestions = await suggestIdeas(recentIdeas.map((i) => i.content));
|
||||
|
||||
if (suggestions.length === 0) {
|
||||
return NextResponse.json({ suggestions: [], source: "none" });
|
||||
}
|
||||
|
||||
return NextResponse.json({ suggestions, source: "ai" });
|
||||
});
|
||||
Reference in New Issue
Block a user