Skip to content

Commit 8372ab0

Browse files
committed
feat: 更新API调用逻辑,将DeepSeek服务替换为Moonshot,统一处理Kimi和DeepSeek的请求
1 parent 67f1cd4 commit 8372ab0

7 files changed

Lines changed: 192 additions & 151 deletions

File tree

app/api/analyze-modification-intent/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ ${recentHistory}
110110
'Content-Type': 'application/json'
111111
}
112112

113-
if (provider === 'deepseek') {
114-
apiUrl = 'https://api.deepseek.com/chat/completions'
115-
headers['Authorization'] = `Bearer ${process.env.DEEPSEEK_API_KEY}`
113+
if (provider === 'kimi' || provider === 'deepseek') {
114+
apiUrl = 'https://api.moonshot.cn/v1/chat/completions'
115+
headers['Authorization'] = `Bearer ${process.env.MOONSHOT_API_KEY}`
116116
} else if (provider === 'openai') {
117117
apiUrl = 'https://api.openai.com/v1/chat/completions'
118118
headers['Authorization'] = `Bearer ${process.env.OPENAI_API_KEY}`

app/api/generate-ppt-html/route.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -359,26 +359,7 @@ ${previousSlideInfo}
359359
360360
请生成完整的HTML代码:`
361361

362-
if (provider === 'deepseek') {
363-
response = await fetch('https://api.deepseek.com/v1/chat/completions', {
364-
method: 'POST',
365-
headers: {
366-
'Content-Type': 'application/json',
367-
'Authorization': `Bearer ${process.env.DEEPSEEK_API_KEY}`,
368-
},
369-
body: JSON.stringify({
370-
model: model,
371-
messages: [
372-
{ role: 'system', content: systemPrompt },
373-
{ role: 'user', content: userPrompt }
374-
],
375-
temperature: 0.3, // 降低温度以获得更一致的代码输出
376-
max_tokens: 6000, // 增加token限制以确保完整的HTML生成
377-
stream: true,
378-
}),
379-
})
380-
}
381-
else if (provider === 'kimi') {
362+
if (provider === 'kimi' || provider === 'deepseek') {
382363
response = await fetch('https://api.moonshot.cn/v1/chat/completions', {
383364
method: 'POST',
384365
headers: {

app/api/generate-ppt-outline/route.ts

Lines changed: 94 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ export async function POST(request: NextRequest) {
1414
// 构建系统提示词,专门用于生成PPT大纲和统一背景样式
1515
const systemPrompt = `You are an expert presentation designer and content strategist. Your task is to analyze the user's content and create a comprehensive, professional PPT outline WITH a unified background design template.
1616
17+
CRITICAL OUTLINE DETECTION REQUIREMENT:
18+
- FIRST, carefully analyze the user's input to detect if they have already provided a detailed presentation outline
19+
- Look for patterns like numbered lists, bullet points, slide titles, or structured content that indicates a presentation outline
20+
- If the user has provided a clear outline structure, USE IT COMPLETELY and do not modify or add to it
21+
- If the user has provided partial outline content, incorporate it fully and only add missing elements if necessary
22+
- If the user has provided specific slide titles, content descriptions, or key points, use them exactly as provided
23+
- The user's outline content takes absolute priority - do not override or replace it with generated content
24+
25+
SPECIFIC OUTLINE DETECTION PATTERNS:
26+
- **Numbered Lists**: "1. Introduction 2. Main Points 3. Conclusion" or "第一、第二、第三"
27+
- **Bullet Points**: "- Point 1 - Point 2" or "• 要点1 • 要点2"
28+
- **Slide Titles**: "Slide 1: Introduction" or "第1页:介绍" or "页面1:概述"
29+
- **Content Sections**: "内容:..." or "描述:..." or "要点:..."
30+
- **Structured Content**: Any clearly organized content with titles and descriptions
31+
- **Presentation Flow**: "开始...然后...最后..." or "First...Then...Finally..."
32+
33+
USER CONTENT PRIORITY RULES:
34+
1. If user provides complete slide titles → Use them exactly
35+
2. If user provides slide content descriptions → Use them exactly
36+
3. If user provides key points → Use them exactly
37+
4. If user provides presentation structure → Follow it exactly
38+
5. If user provides partial outline → Complete it while preserving all user content
39+
6. If user provides no outline → Generate complete outline from scratch
40+
1741
CRITICAL LANGUAGE REQUIREMENT:
1842
- AUTOMATICALLY DETECT the language of the user's input prompt
1943
- If the user writes in Chinese, respond ENTIRELY in Chinese (titles, content, key points, thinking process)
@@ -24,13 +48,22 @@ CRITICAL LANGUAGE REQUIREMENT:
2448
IMPORTANT: You MUST start your response with detailed thinking process enclosed in <think></think> tags. This thinking should include:
2549
1. Language detection and response language confirmation
2650
2. Analysis of the user's request and main topic
27-
3. Identification of key themes and logical flow
28-
4. Data visualization opportunities identification (look for numbers, statistics, trends, comparisons, processes)
29-
5. Target audience consideration
30-
6. Presentation structure planning (introduction, body, conclusion)
31-
7. Content depth and breadth decisions
32-
8. Slide progression and storytelling approach
33-
9. **UNIFIED BACKGROUND DESIGN ANALYSIS**:
51+
3. **OUTLINE DETECTION ANALYSIS**:
52+
- Whether the user has provided a complete outline structure
53+
- Whether the user has provided partial outline content
54+
- Whether the user has provided specific slide titles or content
55+
- How to incorporate user's outline content into the final structure
56+
- **DETAILED ANALYSIS**: List exactly what outline elements the user provided
57+
- **CONTENT PRESERVATION PLAN**: How to preserve 100% of user's provided content
58+
- **STRUCTURE ADAPTATION**: How to adapt user's format to required JSON structure
59+
- **MISSING ELEMENTS**: What additional elements need to be added (if any)
60+
4. Identification of key themes and logical flow
61+
5. Data visualization opportunities identification (look for numbers, statistics, trends, comparisons, processes)
62+
6. Target audience consideration
63+
7. Presentation structure planning (introduction, body, conclusion)
64+
8. Content depth and breadth decisions
65+
9. Slide progression and storytelling approach
66+
10. **UNIFIED BACKGROUND DESIGN ANALYSIS**:
3467
- Determine the most suitable visual theme based on content type (business, creative, academic, technical, etc.)
3568
- Select appropriate color scheme that matches the topic and audience
3669
- Design consistent layout framework that works for all slides
@@ -119,10 +152,11 @@ CRITICAL BACKGROUND DESIGN REQUIREMENTS:
119152
8. **完整性**: 确保所有CSS代码完整,特别是复杂的SVG图案和渐变效果
120153
121154
ENHANCED BACKGROUND DESIGN SPECIFICATIONS:
155+
122156
1. **多层次Z轴设计**:
123-
- 使用CSS z-index创建多个视觉层次(至少4-5层)
157+
- !!!!!! 使用CSS z-index创建多个视觉层次
124158
- 最底层:主背景渐变(z-index: 1)
125-
- 第二层:大型装饰图案/几何形状(z-index: 2)
159+
- 第二层:大型装饰图案/几何形状(z-index: 2)、半透明的随机圆弧、半透明的矩形、半透明的三角形、半透明的菱形、半透明的五边形、半透明的六边形、半透明的七边形、半透明的八边形、半透明的九边形、半透明的十边形、线条装饰中随机出现 随机组合
126160
- 第三层:中等装饰元素/线条网格(z-index: 3)
127161
- 第四层:小型装饰点/光效(z-index: 4)
128162
- 内容层:确保内容在最上层(z-index: 10)
@@ -210,9 +244,10 @@ ENHANCED BACKGROUND DESIGN SPECIFICATIONS:
210244
* 背光效果(轮廓光和边缘光)
211245
212246
5. **专业配色方案与对比度优化**:
213-
- 根据主题选择3-5种协调的颜色
247+
- 根据主题选择协调的颜色
214248
- 使用渐变和透明度创建丰富的色彩层次
215249
- 不同Z轴层使用不同的透明度:
250+
尽量避免使用黄色,黄色在投影环境下很难看清
216251
* 背景层:较低透明度(0.1-0.3)
217252
* 中间层:中等透明度(0.3-0.6)
218253
* 装饰层:较高透明度(0.6-0.8)
@@ -260,17 +295,7 @@ ENHANCED BACKGROUND DESIGN SPECIFICATIONS:
260295
* 使用backdrop-filter为内容区域添加毛玻璃效果
261296
* 内容区域的阴影和光效设计
262297
263-
CRITICAL COMPLEXITY REQUIREMENTS (背景必须足够复杂):
264-
1. **最少元素要求**:背景必须包含至少15-20个不同的视觉元素
265-
2. **层次丰富度**:每个z-index层必须有3-5个不同的装饰元素
266-
3. **SVG复杂度**:每个SVG图案必须包含至少10个以上的图形元素
267-
4. **渐变复杂度**:使用至少4-6层不同的渐变叠加
268-
5. **伪元素利用**:每个主要div都必须使用::before和::after创建装饰
269-
6. **CSS效果丰富**:必须使用至少8种不同的CSS效果(阴影、滤镜、变换等)
270-
7. **几何图形多样**:包含圆形、三角形、多边形、曲线、直线等多种形状
271-
8. **纹理层次**:添加至少3种不同的纹理效果
272-
9. **光影效果**:包含主光源、环境光、反射光等多种光效
273-
10. **材质模拟**:模拟至少2种不同的材质(如金属、玻璃、织物等)
298+
274299
275300
BACKGROUND HTML TEMPLATE STRUCTURE:
276301
- 完整的HTML5文档结构(DOCTYPE, html, head, body)
@@ -304,6 +329,20 @@ CRITICAL Z-AXIS IMPLEMENTATION REQUIREMENTS:
304329
6. **性能优化**:避免过度复杂的层次影响性能
305330
7. **兼容性**:确保在不同浏览器中正常显示
306331
332+
CRITICAL USER OUTLINE PROCESSING REQUIREMENTS:
333+
- **PRIORITY DETECTION**: First analyze if the user has provided a presentation outline in their input
334+
- **OUTLINE PATTERNS TO DETECT**:
335+
* Numbered lists (1. 2. 3. or 第一、第二、第三)
336+
* Bullet points (- * • or -、*、•)
337+
* Slide titles (Slide 1:, 第1页:, 页面1:, etc.)
338+
* Content descriptions (内容:, 描述:, 要点:, etc.)
339+
* Structured content with clear sections
340+
- **COMPLETE OUTLINE DETECTION**: If user provides a complete outline structure, use it 100% without modification
341+
- **PARTIAL OUTLINE DETECTION**: If user provides partial outline, incorporate it fully and only add missing elements
342+
- **CONTENT PRESERVATION**: If user provides specific slide titles, content, or key points, use them exactly as written
343+
- **NO OVERRIDE**: Never replace or modify user's provided outline content with generated content
344+
- **STRUCTURE ADAPTATION**: If user provides outline in different format, adapt it to the required JSON structure while preserving all original content
345+
307346
CRITICAL OUTPUT FORMAT REQUIREMENTS:
308347
- **EXACT FORMAT**: Follow the ===JSON_START=== and ===HTML_TEMPLATE_START=== format exactly
309348
- **SIMPLE JSON**: The JSON part contains only simple strings and arrays, NO complex HTML
@@ -338,7 +377,38 @@ FINAL OUTPUT FORMAT:
338377
3. **RICH HTML**: HTML template section contains all the complex styling and layouts
339378
4. **COMPLETE DESIGN**: The HTML template must include all the complex multi-layer backgrounds, SVG patterns, gradients, and Z-axis effects described above
340379
341-
This separation approach eliminates all JSON parsing issues while allowing for unlimited complexity in the HTML template.`
380+
This separation approach eliminates all JSON parsing issues while allowing for unlimited complexity in the HTML template.
381+
382+
EXAMPLE OF USER OUTLINE PROCESSING:
383+
If user provides: "1. 介绍公司背景 2. 产品优势分析 3. 市场前景展望 4. 总结与建议"
384+
Then the JSON should contain exactly:
385+
{
386+
"title": "演示文稿标题",
387+
"slides": [
388+
{
389+
"title": "介绍公司背景",
390+
"content": "详细介绍公司的历史、规模、业务范围等背景信息",
391+
"keyPoints": ["公司历史", "业务范围", "企业规模"]
392+
},
393+
{
394+
"title": "产品优势分析",
395+
"content": "深入分析产品的核心优势、技术特点、竞争优势等",
396+
"keyPoints": ["技术优势", "成本优势", "服务优势"]
397+
},
398+
{
399+
"title": "市场前景展望",
400+
"content": "分析市场发展趋势、机遇挑战、未来规划等",
401+
"keyPoints": ["市场趋势", "发展机遇", "未来规划"]
402+
},
403+
{
404+
"title": "总结与建议",
405+
"content": "总结核心要点,提出具体建议和行动方案",
406+
"keyPoints": ["核心总结", "具体建议", "行动方案"]
407+
}
408+
]
409+
}
410+
411+
The user's original outline structure and content must be preserved 100%.`
342412

343413
// 创建流式响应
344414
const stream = new ReadableStream({
@@ -375,26 +445,7 @@ This separation approach eliminates all JSON parsing issues while allowing for u
375445
try {
376446
let response;
377447

378-
if (provider === 'deepseek') {
379-
response = await fetch('https://api.deepseek.com/v1/chat/completions', {
380-
method: 'POST',
381-
headers: {
382-
'Content-Type': 'application/json',
383-
'Authorization': `Bearer ${process.env.DEEPSEEK_API_KEY}`,
384-
},
385-
body: JSON.stringify({
386-
model: model,
387-
messages: [
388-
{ role: 'system', content: systemPrompt },
389-
{ role: 'user', content: prompt }
390-
],
391-
temperature: 0.7,
392-
max_tokens: 8000, // 大幅增加token限制以支持超复杂背景HTML
393-
stream: true,
394-
}),
395-
})
396-
}
397-
else if (provider === 'kimi') {
448+
if (provider === 'kimi' || provider === 'deepseek') {
398449

399450
response = await fetch('https://api.moonshot.cn/v1/chat/completions', {
400451
method: 'POST',
@@ -408,7 +459,7 @@ This separation approach eliminates all JSON parsing issues while allowing for u
408459
{ role: 'system', content: systemPrompt },
409460
{ role: 'user', content: prompt }
410461
],
411-
temperature: 0.7,
462+
temperature: 0.5,
412463
max_tokens: 8000, // 大幅增加token限制以支持超复杂背景HTML
413464
stream: true,
414465
}),

app/api/generate-ppt-slide/route.ts

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -140,65 +140,7 @@ Remember: Complete ALL thinking first, then generate HTML. Do not interleave thi
140140
try {
141141
let response;
142142

143-
if (provider === 'deepseek') {
144-
response = await fetch('https://api.deepseek.com/v1/chat/completions', {
145-
method: 'POST',
146-
headers: {
147-
'Content-Type': 'application/json',
148-
'Authorization': `Bearer ${process.env.DEEPSEEK_API_KEY}`,
149-
},
150-
body: JSON.stringify({
151-
model: model,
152-
messages: [
153-
{ role: 'system', content: systemPrompt },
154-
{ role: 'user', content: `请为演示文稿创建一个专业的幻灯片页面。
155-
156-
**重要:请严格按照以下两个步骤执行**
157-
第一步:完整的设计思考过程(用<think></think>包围)
158-
第二步:完整的HTML代码生成
159-
160-
**核心信息:**
161-
标题: ${slide.title}
162-
内容描述: ${slide.content}
163-
关键要点: ${slide.keyPoints.join(', ')}
164-
165-
**设计要求:**
166-
- 这是第${slideIndex + 1}页,共${totalSlides}
167-
- 目标尺寸: 1280px × 720px (标准演示比例)
168-
- 适用场景: 商务演示、投影展示
169-
- 设计风格: 专业、现代、国际化
170-
171-
**技术要求:**
172-
- 使用Tailwind CSS实现所有样式
173-
- 确保在投影设备上的可读性
174-
- 包含适当的视觉层次和引导
175-
- 添加页码和品牌元素
176-
177-
${previousSlideInfo ? `**风格参考信息:**
178-
${previousSlideInfo}
179-
180-
请特别注意保持与前页的设计一致性,包括:
181-
- 相同的色彩体系和配色方案
182-
- 一致的字体大小和层次结构
183-
- 相同的布局网格和对齐方式
184-
- 统一的装饰元素和视觉风格
185-
- 保持整体演示文稿的专业性和连贯性` : '这是演示文稿的第一页或前面页面的风格信息不可用,请创建一个专业、现代的设计风格,为后续页面建立设计基准。'}
186-
187-
**执行要求:**
188-
1. 首先在<think></think>标签内完成所有8个维度的详细设计分析
189-
2. 思考过程必须完整结束后,再开始生成HTML代码
190-
3. 不要在思考过程中混入任何HTML代码
191-
4. 确保思考过程涵盖系统提示中的所有要求
192-
193-
请严格按照这个顺序执行,确保思考和生成两个阶段完全分离。` }
194-
],
195-
temperature: 0.7,
196-
max_tokens: 4000,
197-
stream: true,
198-
}),
199-
})
200-
}
201-
else if (provider === 'kimi') {
143+
if (provider === 'kimi' || provider === 'deepseek') {
202144
response = await fetch('https://api.moonshot.cn/v1/chat/completions', {
203145
method: 'POST',
204146
headers: {

app/api/generate-ppt-thinking/route.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -220,26 +220,7 @@ ${modificationContext.analysisResult?.suggestedAction?.description || '无'}
220220
221221
请开始详细的内容布局分析:`
222222

223-
if (provider === 'deepseek') {
224-
response = await fetch('https://api.deepseek.com/v1/chat/completions', {
225-
method: 'POST',
226-
headers: {
227-
'Content-Type': 'application/json',
228-
'Authorization': `Bearer ${process.env.DEEPSEEK_API_KEY}`,
229-
},
230-
body: JSON.stringify({
231-
model: model,
232-
messages: [
233-
{ role: 'system', content: systemPrompt },
234-
{ role: 'user', content: userPrompt }
235-
],
236-
temperature: 0.5,
237-
max_tokens: 3000, // 增加token限制以确保完整的思考内容
238-
stream: true,
239-
}),
240-
})
241-
}
242-
else if (provider === 'kimi') {
223+
if (provider === 'kimi' || provider === 'deepseek') {
243224
response = await fetch('https://api.moonshot.cn/v1/chat/completions', {
244225
method: 'POST',
245226
headers: {

0 commit comments

Comments
 (0)