changes
This commit is contained in:
@@ -13,6 +13,9 @@ export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { model, messages } = await request.json();
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[Title API] Request received:', { model, messageCount: messages?.length });
|
||||
|
||||
if (!model || !messages || !Array.isArray(messages) || messages.length === 0) {
|
||||
return NextResponse.json({ error: 'Model and messages array are required' }, { status: 400 });
|
||||
}
|
||||
@@ -54,6 +57,9 @@ export async function POST(request: NextRequest) {
|
||||
title = firstUserMessage.slice(0, 30) + (firstUserMessage.length > 30 ? '...' : '');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[Title API] Generated title:', title);
|
||||
|
||||
return NextResponse.json({ title });
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
|
||||
@@ -466,16 +466,25 @@ export default function ChatLayout() {
|
||||
});
|
||||
const titleData = await titleRes.json();
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[Title] API response:', titleData);
|
||||
|
||||
if (titleData.title) {
|
||||
chatTitle = titleData.title;
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[Title] Setting chat title to:', chatTitle);
|
||||
|
||||
// Update title in database
|
||||
await fetch(`/api/chats/${savedChatId}`, {
|
||||
const patchRes = await fetch(`/api/chats/${savedChatId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ title: chatTitle }),
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[Title] PATCH response status:', patchRes.status);
|
||||
|
||||
// Update title in local state
|
||||
setChats((prev) =>
|
||||
prev.map((c) => (c.id === savedChatId ? { ...c, title: chatTitle } : c))
|
||||
|
||||
Reference in New Issue
Block a user