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

Function generateTopicTitleWithOptions

src/renderer/src/services/titleService.ts:460–490  ·  view source on GitHub ↗
(
  options: TitleGenerateOptions
)

Source from the content-addressed store, hash-verified

458 * @param options 生成选项
459 */
460export async function generateTopicTitleWithOptions(
461 options: TitleGenerateOptions
462): Promise<TitleGenerationResult> {
463 const { content, extraRequirements, llmId, modelConfigId, maxLength = 15 } = options
464 const { llmConfig, modelConfig } = getConfigsWithOptions(llmId, modelConfigId)
465
466 if (!llmConfig) {
467 return { title: '', success: false, error: '未配置 LLM' }
468 }
469
470 try {
471 const prompt = buildPromptWithRequirements(TOPIC_GENERATION_PROMPT, content, extraRequirements)
472 const result = await generateWithAI(prompt, llmConfig, modelConfig || undefined)
473
474 // 清理结果:移除可能的引号和多余空白
475 let title = result
476 .replace(/^["'""]|["'""]$/g, '')
477 .replace(/^(话题|主题)[::]\s*/i, '')
478 .trim()
479
480 // 截断到最大长度
481 if (title.length > maxLength) {
482 title = title.slice(0, maxLength)
483 }
484
485 return { title, success: true }
486 } catch (error) {
487 console.error('Failed to generate topic title with options:', error)
488 return { title: '', success: false, error: String(error) }
489 }
490}
491
492/**
493 * 批量为消息生成标题(带选项)

Callers 1

useChatTopicsFunction · 0.90

Calls 3

getConfigsWithOptionsFunction · 0.85
generateWithAIFunction · 0.85

Tested by

no test coverage detected