Your Name 740860fde7
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: hardcode canvas vision to qwen3-vl and downscale pick-object input
2026-02-20 22:33:51 +08:00

47 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/app/(auth)/auth";
import { callQwen3Vl } from "@/lib/ai/qwen3-vl";
export async function POST(request: NextRequest) {
console.log("[Auto-title] API called");
try {
const session = await auth();
if (!session?.user?.id) {
console.log("[Auto-title] Unauthorized");
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { imageUrl } = await request.json();
console.log("[Auto-title] Image URL:", imageUrl);
if (!imageUrl) {
return NextResponse.json({ error: "Image URL is required" }, { status: 400 });
}
console.log("[Auto-title] 使用硬编码模型: qwen3-vl");
// 构造 Prompt
const prompt = "请用2-4个字概括这张图片的主体内容,作为文件标题。直接返回标题,不要包含任何标点符号或其他文字。";
const { text, model } = await callQwen3Vl({
imageUrl,
prompt,
temperature: 0.2,
maxTokens: 50,
});
let title = (text || "").trim();
title = title.replace(/[\s\p{P}\p{S}]+/gu, "");
if (title.length > 4) title = title.slice(0, 4);
if (title.length < 2) title = "新画布";
console.log("[Auto-title] Generated title:", title, "model:", model);
return NextResponse.json({ title });
} catch (error) {
console.error("[Auto-title] Error:", error);
// 失败时返回默认标题,不报错中断流程
return NextResponse.json({ title: "新画布" });
}
}