社交语气翻译器

一个基于FastAPI和MCP服务器的工具,用于分析消息语气并将其重写为五种不同的风格(专业、友好、说服、简洁、同理心),并提供平台特定建议。

  • by UdayBattula
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 udaybattula/social-vibe-translator

使用说明

社交氛围翻译器

初学者友好的FastAPI+MCP服务器,分析语气并将消息重写为五种“氛围”:专业、友好、有说服力、简洁、同情。它还提供了特定于平台的提示。

特性

  • MCP工具 rewrite_vibes JSON I/O
  • FastAPI端点 /rewrite_vibes
  • OpenAI支持的一代产品,具有离线回退功能
  • Chroma用于平台/用户接地的检索增强生成(RAG)
  • 结构化JSON输出(OpenAI JSON模式)
  • 以法学硕士为评判标准,回归启发式
  • 请求/响应的Pydantic模型
  • 清晰的提示和简单的模板

需求

  • Python 3.10+
  • OpenAI API密钥(可选;如果丢失,则返回到确定性输出)

安装

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

环境

创建一个 .env 项目根目录中的文件:

OPENAI_API_KEY=your_openai_api_key_here
# Set to 1 to auto-start MCP stdio mode when running server module directly
MCP_STDIO=0

运行FastAPI服务器

uvicorn server:app --reload --app-dir .

服务器运行于 http://127.0.0.1:8000.

种子RAG指南(一次)

curl -X POST http://127.0.0.1:8000/seed_guidelines

HTTP使用示例

发布 http://127.0.0.1:8000/rewrite_vibes

curl -s -X POST http://127.0.0.1:8000/rewrite_vibes \
  -H 'Content-Type: application/json' \
  -d '{"message": "Can we move the meeting to tomorrow?", "platform": "Email"}' | jq .

MCP服务器使用情况

此项目公开了一个名为的MCP工具 rewrite_vibes 通过stdio。您可以通过以下方式运行stdio模式:

python -m server --stdio

如果 MCP_STDIO=1 已设置 .env,导入模块时,stdio服务器将自动启动。

在Puch AI中注册此MCP服务器:

  • 工具名称: rewrite_vibes
  • 命令: python -m server --stdio

请求/响应模式

  • 输入JSON: { "message": str, "platform": Optional[str] }
  • 输出JSON字段:
    • original_message:str
    • tone_analysis: { overall_tone: str, rationale: str }
    • vibes:每组5个项目 { vibe, rewritten_text, explanation, use_cases }
    • platform_tips: { platform: str, tips: str }

其他端点:

  • POST /rewrite_top → 排名前N的重写 target_tone
  • POST /seed_guidelines → 将种子平台/音调指南导入向量库
  • POST /feedback_accept → 商店接受个性化RAG的重写

请求/响应示例

请求:

{
  "message": "Need to push the deadline by two days. Can we adjust?",
  "platform": "LinkedIn"
}

示例响应:

{
  "original_message": "Need to push the deadline by two days. Can we adjust?",
  "tone_analysis": {
    "overall_tone": "Neutral",
    "rationale": "Heuristic analysis based on keywords and phrasing."
  },
  "vibes": [
    {
      "vibe": "Professional",
      "rewritten_text": "[Professional] Need to push the deadline by two days. Can we adjust?",
      "explanation": "Uses professional tone cues based on simple template guidance.",
      "use_cases": [
        "Use when you need a professional tone.",
        "Useful for quick edits when time is limited."
      ]
    },
    {
      "vibe": "Friendly",
      "rewritten_text": "[Friendly] Need to push the deadline by two days. Can we adjust?",
      "explanation": "Uses friendly tone cues based on simple template guidance.",
      "use_cases": [
        "Use when you need a friendly tone.",
        "Useful for quick edits when time is limited."
      ]
    },
    {
      "vibe": "Persuasive",
      "rewritten_text": "[Persuasive] Need to push the deadline by two days. Can we adjust?",
      "explanation": "Uses persuasive tone cues based on simple template guidance.",
      "use_cases": [
        "Use when you need a persuasive tone.",
        "Useful for quick edits when time is limited."
      ]
    },
    {
      "vibe": "Concise",
      "rewritten_text": "[Concise] Need to push the deadline by two days. Can we adjust?",
      "explanation": "Uses concise tone cues based on simple template guidance.",
      "use_cases": [
        "Use when you need a concise tone.",
        "Useful for quick edits when time is limited."
      ]
    },
    {
      "vibe": "Empathetic",
      "rewritten_text": "[Empathetic] Need to push the deadline by two days. Can we adjust?",
      "explanation": "Uses empathetic tone cues based on simple template guidance.",
      "use_cases": [
        "Use when you need an empathetic tone.",
        "Useful for quick edits when time is limited."
      ]
    }
  ],
  "platform_tips": {
    "platform": "linkedin",
    "tips": "Stay professional, avoid slang, include a clear ask, and keep paragraphs short."
  }
}

开发说明

  • 服务器在可用时使用异步OpenAI客户端;如果没有密钥,它就会回到本地启发式方法。
  • 保持请求简短,以尽量减少令牌使用。如果消息很长,则会被截断。