ai评论生成
This commit is contained in:
@@ -10327,6 +10327,7 @@ const AIConfigComponent = ({
|
||||
const [enableHomepageEntry, setEnableHomepageEntry] = useState(true);
|
||||
const [enableVideoCardEntry, setEnableVideoCardEntry] = useState(true);
|
||||
const [enablePlayPageEntry, setEnablePlayPageEntry] = useState(true);
|
||||
const [enableAIComments, setEnableAIComments] = useState(false);
|
||||
|
||||
// 权限控制
|
||||
const [allowRegularUsers, setAllowRegularUsers] = useState(true);
|
||||
@@ -10357,6 +10358,7 @@ const AIConfigComponent = ({
|
||||
setEnableHomepageEntry(config.AIConfig.EnableHomepageEntry !== false);
|
||||
setEnableVideoCardEntry(config.AIConfig.EnableVideoCardEntry !== false);
|
||||
setEnablePlayPageEntry(config.AIConfig.EnablePlayPageEntry !== false);
|
||||
setEnableAIComments(config.AIConfig.EnableAIComments || false);
|
||||
setAllowRegularUsers(config.AIConfig.AllowRegularUsers !== false);
|
||||
setTemperature(config.AIConfig.Temperature ?? 0.7);
|
||||
setMaxTokens(config.AIConfig.MaxTokens ?? 1000);
|
||||
@@ -10390,6 +10392,7 @@ const AIConfigComponent = ({
|
||||
EnableHomepageEntry: enableHomepageEntry,
|
||||
EnableVideoCardEntry: enableVideoCardEntry,
|
||||
EnablePlayPageEntry: enablePlayPageEntry,
|
||||
EnableAIComments: enableAIComments,
|
||||
AllowRegularUsers: allowRegularUsers,
|
||||
Temperature: temperature,
|
||||
MaxTokens: maxTokens,
|
||||
@@ -10659,6 +10662,7 @@ const AIConfigComponent = ({
|
||||
{ key: 'homepage', label: '首页入口', desc: '在首页显示AI问片入口', state: enableHomepageEntry, setState: setEnableHomepageEntry },
|
||||
{ key: 'videocard', label: '视频卡片入口', desc: '在视频卡片菜单中显示AI问片选项', state: enableVideoCardEntry, setState: setEnableVideoCardEntry },
|
||||
{ key: 'playpage', label: '播放页入口', desc: '在视频播放页显示AI问片功能', state: enablePlayPageEntry, setState: setEnablePlayPageEntry },
|
||||
{ key: 'aicomments', label: 'AI评论功能', desc: '在播放页生成AI评论(独立于豆瓣评论)', state: enableAIComments, setState: setEnableAIComments },
|
||||
].map((item) => (
|
||||
<div key={item.key} className='flex items-center justify-between py-2'>
|
||||
<div>
|
||||
|
||||
@@ -57,6 +57,7 @@ export async function POST(request: NextRequest) {
|
||||
EnableHomepageEntry,
|
||||
EnableVideoCardEntry,
|
||||
EnablePlayPageEntry,
|
||||
EnableAIComments,
|
||||
AllowRegularUsers,
|
||||
Temperature,
|
||||
MaxTokens,
|
||||
@@ -93,6 +94,7 @@ export async function POST(request: NextRequest) {
|
||||
EnableHomepageEntry: boolean;
|
||||
EnableVideoCardEntry: boolean;
|
||||
EnablePlayPageEntry: boolean;
|
||||
EnableAIComments: boolean;
|
||||
AllowRegularUsers: boolean;
|
||||
Temperature?: number;
|
||||
MaxTokens?: number;
|
||||
@@ -132,6 +134,7 @@ export async function POST(request: NextRequest) {
|
||||
typeof EnableHomepageEntry !== 'boolean' ||
|
||||
typeof EnableVideoCardEntry !== 'boolean' ||
|
||||
typeof EnablePlayPageEntry !== 'boolean' ||
|
||||
typeof EnableAIComments !== 'boolean' ||
|
||||
typeof AllowRegularUsers !== 'boolean' ||
|
||||
(Temperature !== undefined && typeof Temperature !== 'number') ||
|
||||
(MaxTokens !== undefined && typeof MaxTokens !== 'number') ||
|
||||
@@ -181,6 +184,7 @@ export async function POST(request: NextRequest) {
|
||||
EnableHomepageEntry,
|
||||
EnableVideoCardEntry,
|
||||
EnablePlayPageEntry,
|
||||
EnableAIComments,
|
||||
AllowRegularUsers,
|
||||
Temperature,
|
||||
MaxTokens,
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { generateAIComments, AIComment } from '@/lib/ai-comment-generator';
|
||||
import { getConfig } from '@/lib/config';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
interface AICommentsResponse {
|
||||
comments: AIComment[];
|
||||
total: number;
|
||||
movieName: string;
|
||||
isAiGenerated: true;
|
||||
generatedAt: string;
|
||||
}
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const searchParams = request.nextUrl.searchParams;
|
||||
const movieName = searchParams.get('name');
|
||||
const movieInfo = searchParams.get('info');
|
||||
const count = parseInt(searchParams.get('count') || '10');
|
||||
|
||||
// 参数验证
|
||||
if (!movieName) {
|
||||
return NextResponse.json(
|
||||
{ error: '缺少影片名称参数' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
if (count < 1 || count > 50) {
|
||||
return NextResponse.json(
|
||||
{ error: '评论数量必须在1-50之间' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// 读取AI配置
|
||||
const config = await getConfig();
|
||||
const aiConfig = config.AIConfig;
|
||||
|
||||
// 检查AI功能是否启用
|
||||
if (!aiConfig?.Enabled) {
|
||||
return NextResponse.json(
|
||||
{ error: 'AI功能未启用' },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
|
||||
// 检查AI评论功能是否启用
|
||||
if (!aiConfig?.EnableAIComments) {
|
||||
return NextResponse.json(
|
||||
{ error: 'AI评论功能未启用' },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
|
||||
// 检查必要的配置
|
||||
if (!aiConfig.CustomApiKey || !aiConfig.CustomBaseURL || !aiConfig.CustomModel) {
|
||||
return NextResponse.json(
|
||||
{ error: 'AI配置不完整,请在管理面板配置' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
// 生成AI评论
|
||||
const comments = await generateAIComments({
|
||||
movieName,
|
||||
movieInfo: movieInfo || undefined,
|
||||
count,
|
||||
aiConfig: {
|
||||
CustomApiKey: aiConfig.CustomApiKey,
|
||||
CustomBaseURL: aiConfig.CustomBaseURL,
|
||||
CustomModel: aiConfig.CustomModel,
|
||||
Temperature: aiConfig.Temperature,
|
||||
MaxTokens: aiConfig.MaxTokens,
|
||||
EnableWebSearch: aiConfig.EnableWebSearch,
|
||||
WebSearchProvider: aiConfig.WebSearchProvider,
|
||||
TavilyApiKey: aiConfig.TavilyApiKey,
|
||||
SerperApiKey: aiConfig.SerperApiKey,
|
||||
SerpApiKey: aiConfig.SerpApiKey,
|
||||
},
|
||||
});
|
||||
|
||||
// 返回结果
|
||||
const response: AICommentsResponse = {
|
||||
comments,
|
||||
total: comments.length,
|
||||
movieName,
|
||||
isAiGenerated: true,
|
||||
generatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
return NextResponse.json(response, {
|
||||
headers: {
|
||||
'Cache-Control': 'public, max-age=3600, s-maxage=3600', // 缓存1小时
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('AI评论生成失败:', error);
|
||||
|
||||
// 返回友好的错误信息
|
||||
const errorMessage = error instanceof Error ? error.message : 'AI评论生成失败';
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: errorMessage,
|
||||
details: process.env.NODE_ENV === 'development' ? String(error) : undefined
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,7 @@ export default async function RootLayout({
|
||||
let aiEnableHomepageEntry = false;
|
||||
let aiEnableVideoCardEntry = false;
|
||||
let aiEnablePlayPageEntry = false;
|
||||
let aiEnableComments = false;
|
||||
let aiDefaultMessageNoVideo = '';
|
||||
let aiDefaultMessageWithVideo = '';
|
||||
let enableMovieRequest = true;
|
||||
@@ -133,6 +134,7 @@ export default async function RootLayout({
|
||||
aiEnableHomepageEntry = config.AIConfig?.EnableHomepageEntry || false;
|
||||
aiEnableVideoCardEntry = config.AIConfig?.EnableVideoCardEntry || false;
|
||||
aiEnablePlayPageEntry = config.AIConfig?.EnablePlayPageEntry || false;
|
||||
aiEnableComments = config.AIConfig?.EnableAIComments || false;
|
||||
aiDefaultMessageNoVideo = config.AIConfig?.DefaultMessageNoVideo || '';
|
||||
aiDefaultMessageWithVideo = config.AIConfig?.DefaultMessageWithVideo || '';
|
||||
// 求片功能配置
|
||||
@@ -198,6 +200,9 @@ export default async function RootLayout({
|
||||
AI_ENABLE_HOMEPAGE_ENTRY: aiEnableHomepageEntry,
|
||||
AI_ENABLE_VIDEOCARD_ENTRY: aiEnableVideoCardEntry,
|
||||
AI_ENABLE_PLAYPAGE_ENTRY: aiEnablePlayPageEntry,
|
||||
AIConfig: {
|
||||
EnableAIComments: aiEnableComments,
|
||||
},
|
||||
AI_DEFAULT_MESSAGE_NO_VIDEO: aiDefaultMessageNoVideo,
|
||||
AI_DEFAULT_MESSAGE_WITH_VIDEO: aiDefaultMessageWithVideo,
|
||||
ENABLE_MOVIE_REQUEST: enableMovieRequest,
|
||||
|
||||
@@ -50,9 +50,11 @@ import { getTMDBImageUrl } from '@/lib/tmdb.search';
|
||||
import { DanmakuFilterConfig, EpisodeFilterConfig, SearchResult } from '@/lib/types';
|
||||
import { base58Decode, getVideoResolutionFromM3u8, processImageUrl } from '@/lib/utils';
|
||||
import { useEnableComments } from '@/hooks/useEnableComments';
|
||||
import { useEnableAIComments } from '@/hooks/useEnableAIComments';
|
||||
import { usePlaySync } from '@/hooks/usePlaySync';
|
||||
|
||||
import AIChatPanel from '@/components/AIChatPanel';
|
||||
import AIComments from '@/components/AIComments';
|
||||
import CorrectDialog from '@/components/CorrectDialog';
|
||||
import DanmakuFilterSettings from '@/components/DanmakuFilterSettings';
|
||||
import DetailPanel from '@/components/DetailPanel';
|
||||
@@ -87,6 +89,7 @@ function PlayPageClient() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const enableComments = useEnableComments();
|
||||
const enableAIComments = useEnableAIComments();
|
||||
const { addDownloadTask } = useDownload();
|
||||
const { siteName } = useSite();
|
||||
|
||||
@@ -8719,6 +8722,28 @@ function PlayPageClient() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* AI评论区域 */}
|
||||
{videoTitle && enableAIComments && (
|
||||
<div className='mt-6 -mx-3 md:mx-0 md:px-4'>
|
||||
<div className='bg-white/50 dark:bg-gray-800/50 backdrop-blur-sm rounded-xl border border-blue-200/50 dark:border-blue-700/50 overflow-hidden'>
|
||||
{/* 标题 */}
|
||||
<div className='px-3 md:px-6 py-4 border-b border-blue-200 dark:border-blue-700'>
|
||||
<h3 className='text-lg font-semibold text-gray-900 dark:text-white flex items-center gap-2'>
|
||||
<svg className='w-5 h-5 text-blue-600 dark:text-blue-400' fill='currentColor' viewBox='0 0 24 24'>
|
||||
<path d='M13 10V3L4 14h7v7l9-11h-7z' />
|
||||
</svg>
|
||||
AI生成评论
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
{/* 评论内容 */}
|
||||
<div className='p-3 md:p-6'>
|
||||
<AIComments movieName={videoTitle} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user