DeepSeek + AI PPT 实现本地部署 | 客服服务营销数智化洞察_晓观点
       

DeepSeek + AI PPT 实现本地部署

接上文deepseek服务器繁忙,API无法充值deepseek服务器繁忙,API无法充值,如何使用其他渠道玩转deepseek,本文主要讲解deepseek 和 ai ppt如何配合,输出高质量的ppt稿件。

主要使用技术:

  1. ollama,用于本地部署deepseek
  2. PPTist,用于ppt创建编辑预览
  3. python,用于提供ppt生成的服务端

一. 本地部署deepseek

步骤如下

1.安装ollama

  下载地址:https://ollama.com/download

  根据自己的系统选择安装包下载

DeepSeek + AI PPT 实现本地部署

2.部署模型

  • https://ollama.com/library/deepseek-v3
  • https://ollama.com/library/deepseek-r1

  deepseek-v3需要404G的磁盘空间,我这里就直接部署r1 7b的模型测试一下

DeepSeek + AI PPT 实现本地部署
DeepSeek + AI PPT 实现本地部署

二. PPT工具部署

找到一个空目录:

git clone https://github.com/pipipi-pikachu/PPTist.git

cd PPTist

npm install

npm run dev

浏览器打开:http://127.0.0.1:5173/

DeepSeek + AI PPT 实现本地部署

这里已经就可以使用ppt了,并且也可以使用官方的AI来生成ppt内容。

三. PPT内容生成服务端

这里我们使用python来完成ppt内容生成的API,替换第一节中的官方提供的API,这样就实现完全本地化来,在断网的网络环境中也能正常使用AI来完成ppt的生成了。

pip install FastAPI openai uvicorn

服务端代码,这个代码也可以自行修改,接入其他模型

from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import StreamingResponse
from openai import AsyncOpenAI
from typing import Dict, Any
import json
import os

app = FastAPI()

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 初始化OpenAI客户端
client = AsyncOpenAI(
    api_key="xx",
    base_url="http://127.0.0.1:11434/v1",
)

# 大纲生成提示词
OUTLINE_PROMPTS = {
    'zh': """请为以下主题生成一个详细的PPT大纲,要求:
1. 标题:简洁明确,突出主题
2. 目录:包含5个主要章节,每个章节标题需要体现层次性和逻辑性
3. 具体内容:
   - 每个章节包含3-4个关键要点
   - 要点之间需要有逻辑递进关系
   - 确保覆盖主题的各个重要方面
   - 适当融入数据支持、案例分析或实践应用
4. 整体结构:
   - 开篇:背景介绍和主题概述
   - 中间:核心内容展开
   - 结尾:总结和展望
请按照以上要求,生成一个专业、系统的PPT大纲:""",
    'en': """Please generate a detailed PPT outline for the following topic with these requirements:
1. Title: Concise and clear, highlighting the main theme
2. Table of Contents: Include 5 main chapters, each chapter title should reflect hierarchy and logic
3. Detailed Content:
   - Each chapter should contain 3-4 key points
   - Points should have a logical progression
   - Ensure coverage of all important aspects of the topic
   - Incorporate data support, case analysis, or practical applications where appropriate
4. Overall Structure:
   - Opening: Background and topic overview
   - Middle: Core content development
   - Ending: Summary and future outlook
Please generate a professional and systematic PPT outline following these requirements:"""
}

# PPT内容生成提示词
CONTENT_PROMPTS = {
    "zh": """请根据以下大纲生成一个完整的PPT内容,以JSON格式返回。要求:
1. 每个要点的具体内容应在50-100字之间,确保内容详实专业
2. 格式必须严格按照以下示例:
{
    "data": [
        {
            "type": "cover",  # 封面页
            "data": {
                "title": "标题",
                "text": "副标题或说明文字(20-30字的主题介绍)"
            }
        },
        {
            "type": "contents",  # 目录页
            "data": {
                "items": ["第一章节", "第二章节", "第三章节", "第四章节", "第五章节"]
            }
        },
        {
            "type": "transition",  # 过渡页
            "data": {
                "title": "章节标题",
                "text": "章节说明文字(30-50字的章节概述)"
            }
        },
        {
            "type": "content",  # 内容页
            "data": {
                "title": "页面标题",
                "items": [
                    {
                        "title": "要点标题",
                        "text": "要点具体内容(50-100字的详细说明,包含核心观点、数据支持或实际案例)"
                    }
                ]
            }
        },
        {
            "type": "end"  # 结束页
        }
    ]
}
请确保返回的JSON格式完全符合上述规范,不要添加任何额外的格式或说明。""",
    "en": """Please generate complete PPT content based on the following outline in JSON format. Requirements:
1. Each point's content should be between 50-100 words, ensuring detailed and professional content
2. The format must strictly follow this example:
{
    "data": [
        {
            "type": "cover",  # Cover page
            "data": {
                "title": "Title",
                "text": "Subtitle or description (20-30 words topic introduction)"
            }
        },
        {
            "type": "contents",  # Table of contents
            "data": {
                "items": ["Content item 1", "Content item 2", "Content item 3"]
            }
        },
        {
            "type": "transition",  # Transition page
            "data": {
                "title": "Section title",
                "text": "Section description (30-50 words section overview)"
            }
        },
        {
            "type": "content",  # Content page
            "data": {
                "title": "Page title",
                "items": [
                    {
                        "title": "Point title",
                        "text": "Point content (50-100 words detailed explanation, including core viewpoints, data support or case studies)"
                    }
                ]
            }
        },
        {
            "type": "end"  # End page
        }
    ]
}
Please ensure the returned JSON format strictly follows the above specification without any additional formatting or descriptions."""
}

async def generate_outline_stream(content: str, language: str):
    messages = [
        {"role": "system", "content": OUTLINE_PROMPTS[language]},
        {"role": "user", "content": content}
    ]
    
    stream = await client.chat.completions.create(
        model="deepseek-r1:latest",
        messages=messages,
        stream=True
    )

    async for chunk in stream:
        if chunk.choices and chunk.choices[0].delta.content:
            yield chunk.choices[0].delta.content

@app.post("/tools/aippt_outline")
async def aippt_outline(request: Request):
    data = await request.json()
    content = data.get('content')
    language = data.get('language', 'zh')
    
    if not content:
        return {"error": "Content is required"}
    
    return StreamingResponse(
        generate_outline_stream(content, language),
        media_type='text/event-stream'
    )

@app.post("/tools/aippt")
async def aippt(request: Request):
    data = await request.json()
    content = data.get('content')
    language = data.get('language', 'zh')
    
    if not content:
        return {"error": "Content is required"}

    contents = content.split('</think>')
    if len(contents) > 1:
        content = contents[1].strip()
    
    messages = [
        {"role": "system", "content": CONTENT_PROMPTS[language]},
        {"role": "user", "content": content}
    ]
    
    response = await client.chat.completions.create(
        model="deepseek-r1:latest",
        messages=messages,
        temperature=0.7,
        max_tokens=2000,
        timeout=120
    )
    content = response.choices[0].message.content
    return {
    "state": 1,
    "data": [
        {
            "role": "assistant",
            "content": content
        }
    ]
}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

启动后端服务

python3 app.py

INFO:     Started server process [49964]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

修改配置PPTist 中的 vite.config.ts 文件

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  base: '',
  plugins: [
    vue(),
  ],
  server: {
    host: '127.0.0.1',
    port: 5173,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:8000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      }
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
          @import '@/assets/styles/variable.scss';
          @import '@/assets/styles/mixin.scss';
        `
      },
    },
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

重新启动前端服务即可。

接下来看看效果吧

免费试用 更多热门智能应用                        
(3)
研发专家-白起研发专家-白起
上一篇 2025年2月8日
下一篇 2025年2月17日

相关推荐