返回 oh-my-ppt
image-prompt.ts
根目录 / src / main / agent-runtime / prompt / composers / image-prompt.ts
1 import { HumanMessage, SystemMessage } from '@langchain/core/messages'
2 import { createPromptCatalog } from '../catalog'
3
4 import systemEnTemplate from '../templates/image-prompt/system-en.md?raw'
5 import systemZhTemplate from '../templates/image-prompt/system-zh.md?raw'
6
7 type ImagePromptTemplateVars = {
8 'system-en': {}
9 'system-zh': {}
10 }
11
12 const imagePromptCatalog = createPromptCatalog<ImagePromptTemplateVars>({
13 'system-en': systemEnTemplate.trimEnd(),
14 'system-zh': systemZhTemplate.trimEnd()
15 })
16
17 export type ImagePromptGenerationArgs = {
18 locale: 'zh' | 'en'
19 userPrompt: string
20 pageTitle: string
21 pageOutline: string
22 pageHtml: string
23 }
24
25 /** Static model instructions stay in Markdown; request-specific content is composed here. */
26 export const buildImagePromptGenerationMessages = (
27 args: ImagePromptGenerationArgs
28 ): [SystemMessage, HumanMessage] => {
29 const isZh = args.locale.startsWith('zh')
30 const systemPrompt = imagePromptCatalog.render(isZh ? 'system-zh' : 'system-en', {})
31 const userPrompt = isZh
32 ? `【页面标题】
33 ${args.pageTitle || '(无标题)'}
34
35 【页面大纲】
36 ${args.pageOutline || '(无大纲)'}
37
38 【用户想生成的画面】
39 ${args.userPrompt || '(用户未填写,请根据当前页推断配图主题)'}
40
41 【当前页 HTML/CSS,供分析视觉风格】
42 ${args.pageHtml}
43
44 请输出一条最终配图描述。它应该能直接填入生图模型,而不是风格总结。`
45 : `[Slide title]
46 ${args.pageTitle || '(untitled)'}
47
48 [Slide outline]
49 ${args.pageOutline || '(no outline)'}
50
51 [User desired image]
52 ${args.userPrompt || '(User did not provide one. Infer a visual subject from the current slide.)'}
53
54 [Current slide HTML/CSS for visual style analysis]
55 ${args.pageHtml}
56
57 Output one final visual description that can be pasted directly into an image model. Do not summarize the style.`
58
59 return [new SystemMessage(systemPrompt), new HumanMessage(userPrompt)]
60 }
61
61 lines TYPESCRIPT