Fix: generate title from user message — use only text parts (#1279)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
6a02d4fa9a
commit
d366de3c86
3 changed files with 12 additions and 8 deletions
|
|
@ -4,11 +4,13 @@ import { generateText, type UIMessage } from "ai";
|
|||
import { cookies } from "next/headers";
|
||||
import type { VisibilityType } from "@/components/visibility-selector";
|
||||
import { myProvider } from "@/lib/ai/providers";
|
||||
import { titlePrompt } from "@/lib/ai/prompts";
|
||||
import {
|
||||
deleteMessagesByChatIdAfterTimestamp,
|
||||
getMessageById,
|
||||
updateChatVisiblityById,
|
||||
} from "@/lib/db/queries";
|
||||
import { getTextFromMessage } from "@/lib/utils";
|
||||
|
||||
export async function saveChatModelAsCookie(model: string) {
|
||||
const cookieStore = await cookies();
|
||||
|
|
@ -22,12 +24,8 @@ export async function generateTitleFromUserMessage({
|
|||
}) {
|
||||
const { text: title } = await generateText({
|
||||
model: myProvider.languageModel("title-model"),
|
||||
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),
|
||||
system: titlePrompt,
|
||||
prompt: getTextFromMessage(message),
|
||||
});
|
||||
|
||||
return title;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue