Add message actions (#482)
This commit is contained in:
parent
94f563f179
commit
171914941e
20 changed files with 1011 additions and 150 deletions
|
|
@ -1,8 +1,29 @@
|
|||
'use server';
|
||||
|
||||
import { CoreMessage, CoreUserMessage, generateText } from 'ai';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
import { customModel } from '@/ai';
|
||||
|
||||
export async function saveModelId(model: string) {
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.set('model-id', model);
|
||||
}
|
||||
|
||||
export async function generateTitleFromUserMessage({
|
||||
message,
|
||||
}: {
|
||||
message: CoreUserMessage;
|
||||
}) {
|
||||
const { text: title } = await generateText({
|
||||
model: customModel('gpt-3.5-turbo'),
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue