2024-10-24 16:35:51 -04:00
|
|
|
'use server';
|
|
|
|
|
|
2024-11-15 12:18:17 -05:00
|
|
|
import { CoreMessage, type CoreUserMessage, generateText } from 'ai';
|
2024-10-24 16:35:51 -04:00
|
|
|
import { cookies } from 'next/headers';
|
|
|
|
|
|
2024-11-05 17:15:51 +03:00
|
|
|
import { customModel } from '@/ai';
|
|
|
|
|
|
2024-10-30 16:01:24 +05:30
|
|
|
export async function saveModelId(model: string) {
|
2024-10-24 16:35:51 -04:00
|
|
|
const cookieStore = await cookies();
|
2024-10-30 16:01:24 +05:30
|
|
|
cookieStore.set('model-id', model);
|
2024-10-24 16:35:51 -04:00
|
|
|
}
|
2024-11-05 17:15:51 +03:00
|
|
|
|
|
|
|
|
export async function generateTitleFromUserMessage({
|
|
|
|
|
message,
|
|
|
|
|
}: {
|
|
|
|
|
message: CoreUserMessage;
|
|
|
|
|
}) {
|
|
|
|
|
const { text: title } = await generateText({
|
2024-11-15 10:15:49 -05:00
|
|
|
model: customModel('gpt-4o-mini'),
|
2024-11-05 17:15:51 +03:00
|
|
|
system: `\n
|
|
|
|
|
- you will generate a short title based on the first message a user begins a conversation with
|
|
|
|
|
- ensure it is not more than 80 characters long
|
|
|
|
|
- the title should be a summary of the user's message
|
|
|
|
|
- do not use quotes or colons`,
|
|
|
|
|
prompt: JSON.stringify(message),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return title;
|
|
|
|
|
}
|