MCPcopy Create free account
hub / github.com/experdot/pointer / generateTopicTitle

Function generateTopicTitle

src/renderer/src/services/titleService.ts:223–253  ·  view source on GitHub ↗
(
  content: string,
  maxLength: number = 15
)

Source from the content-addressed store, hash-verified

221 * @param maxLength Topic 最大长度
222 */
223export async function generateTopicTitle(
224 content: string,
225 maxLength: number = 15
226): Promise<TitleGenerationResult> {
227 const { llmConfig, modelConfig } = getDefaultConfigs()
228
229 if (!llmConfig) {
230 return { title: '', success: false, error: '未配置 LLM' }
231 }
232
233 try {
234 const prompt = TOPIC_GENERATION_PROMPT.replace('{content}', truncateContent(content))
235 const result = await generateWithAI(prompt, llmConfig, modelConfig || undefined)
236
237 // 清理结果:移除可能的引号和多余空白
238 let title = result
239 .replace(/^["'""]|["'""]$/g, '')
240 .replace(/^(话题|主题)[::]\s*/i, '')
241 .trim()
242
243 // 截断到最大长度
244 if (title.length > maxLength) {
245 title = title.slice(0, maxLength)
246 }
247
248 return { title, success: true }
249 } catch (error) {
250 console.error('Failed to generate topic title:', error)
251 return { title: '', success: false, error: String(error) }
252 }
253}
254
255export interface TopicSuggestionResult {
256 shouldCreateTopic: boolean

Callers 1

useChatTopicsFunction · 0.90

Calls 3

getDefaultConfigsFunction · 0.85
truncateContentFunction · 0.85
generateWithAIFunction · 0.85

Tested by

no test coverage detected