11import { apiV1ChatCompletions } from "@/api/generated/sdk.gen" ;
22import type { MessageUsage } from "@/components/chat-types" ;
33
4- /** Maximum characters for a conversation title */
5- const MAX_TITLE_LENGTH = 25 ;
6-
74/** Result from LLM title generation including usage data */
85export interface TitleGenerationResult {
96 title : string ;
@@ -17,10 +14,7 @@ export interface TitleGenerationResult {
1714 */
1815export function generateSimpleTitle ( userMessage : string ) : string {
1916 const firstLine = userMessage . split ( "\n" ) [ 0 ] . trim ( ) ;
20- if ( ! firstLine ) return "New Chat" ;
21- return firstLine . length > MAX_TITLE_LENGTH
22- ? firstLine . slice ( 0 , MAX_TITLE_LENGTH - 3 ) + "..."
23- : firstLine ;
17+ return firstLine || "New Chat" ;
2418}
2519
2620/**
@@ -43,16 +37,14 @@ export async function generateTitleWithLLM(
4337 {
4438 role : "system" ,
4539 content :
46- "Generate a very short title (2-4 words, max 25 characters ) for a conversation. " +
40+ "Generate a concise title (3-6 words) for a conversation. " +
4741 "Return ONLY the title, no quotes, no punctuation at the end." ,
4842 } ,
4943 {
5044 role : "user" ,
5145 content : userMessage . slice ( 0 , 500 ) , // Limit input to save tokens
5246 } ,
5347 ] ,
54- max_tokens : 20 ,
55- temperature : 0.3 ,
5648 } ,
5749 throwOnError : true ,
5850 } ) ;
@@ -78,13 +70,9 @@ export async function generateTitleWithLLM(
7870 : undefined ;
7971
8072 if ( title && title . length > 0 ) {
81- // Ensure title isn't too long and remove any trailing punctuation
73+ // Remove any trailing punctuation the LLM may have added
8274 const cleaned = title . replace ( / [ . ! ? : ] + $ / , "" ) . trim ( ) ;
83- const finalTitle =
84- cleaned . length > MAX_TITLE_LENGTH
85- ? cleaned . slice ( 0 , MAX_TITLE_LENGTH - 3 ) + "..."
86- : cleaned ;
87- return { title : finalTitle , usage } ;
75+ return { title : cleaned , usage } ;
8876 }
8977
9078 // Fallback if no valid title in response
0 commit comments