@@ -1,16 +1,17 @@
11 import { generateResponse } from "@/src/lib/chat";
22 import { db } from "@/src/lib/db";
33 import { threads } from "@/src/lib/db/schema";
4+import { debug } from "@/src/lib/debug";
45 import { createMessage } from "@/src/lib/messages";
56 import ollama from "ollama";
67
7-export async function generateTitle(model: string, message: string): Promise<string | null> {
8+export async function generateTitle(model: string, message: string): Promise<string> {
89 const response = await ollama.generate({
910 model: model,
10- prompt: `Create a concise summary of the following message: "${message}. Return only alphanumeric characters and spaces."`,
11+ prompt: `Create a concise summary using only alphanumeric characters and spaces of the following message: "${message}."`,
1112 });
1213
13- return response.response || message.substring(0, 100);
14+ return response.response ?? message.substring(0, 100);
1415 }
1516
1617 export function generateSystemPrompt(options: {
@@ -78,9 +79,11 @@ export async function createThread(
7879 time: string,
7980 timezone: string
8081 ) {
81- let title = await generateTitle(model, userMessage);
82- if (!title) {
83- title = userMessage.substring(0, 100);
82+ let title = userMessage.substring(0, 100);
83+ try {
84+ title = await generateTitle(model, userMessage);
85+ } catch (error) {
86+ debug(`[Threads] Error generating title:`, error);
8487 }
8588
8689 const newThread = await db