文本摘要服务

基于FastAPI和FastMCP的文本摘要服务,用于快速生成给定文本的摘要。

  • by highfeature
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 highfeature/hf-mcp-summarize

使用说明

📚 流式HTTP FastAPI/FastMCP摘要生成器代理版本0.5(请参阅发行说明.md)

基于原件:https://github.com/open-webui/openapi-servers/tree/main/servers/summarizer-tool(FastMCP stdio)特别感谢他们。

我为什么要创建这个应用程序?

我正在为我的实验室寻找一个骨架模型,它可以包含全套:

  • 我在其他应用程序中使用的FastAPI函数
  • FastMCP为我的所有工具、提示、资源等提供服务
  • 一切记录在案,易于维护
  • 所有这些都在一个Docker容器中,我可以在需要时弹出 (减少descktop/server上使用的内存、端口等的数量)

此FastAPI/FastMCP服务器用于汇总给定的文本块。

假设您正在使用默认端口在相邻容器中运行一个ollama实例。

运行方式:

(hf-mcp-summarize) $ uvicorn main:app --reload --port=19140

将其添加到您的AI中:

千

添加您的mcp_settings.json

{
    "mcpServers": {
        ...
        "hf-mcp-summarize": {
            "disabled": false,
            "type": "streamable-http",
            "url": "http://0.0.0.0:19140/mcp-server/mcp/",
            "note": "For Streamable HTTP connections, add this URL directly in your MCP Client",
            "alwaysAllow": []
        },
        ...
    }
}

开放代码

插件opencode.json

{
  ...
  "mcp": {
    ...
    "hf-mcp-summarize": {
      "type": "remote",
      "url": "http://0.0.0.0:19140/mcp-server/mcp/",
      "oauth": false,
      "headers": {
        "Authorization": "Bearer {env:MY_API_KEY}"
      },
      "enabled": true
    },
    ...
  }
  ...
}

📦 端点列表

FastAPI路由:GEThttp://0.0.0.0:19140/health-检查

将返回类似{“status”:“healthy”}的dict

FastAPI路由:GEThttp://0.0.0.0:19140/

将返回一个类似于{“service”:“Weather MCP service”,“version”:“1.0.0”,“status”:“running”}的字典

FastMCP路由:POST/mcp服务器/mcp/add

简单无用的工具很难将a+b相加,并通过在总和上加10来作弊。 📥 请求 { a: 7 b: 3 } 📤 答复:

{
    "status": "success",
    "result": "20"
}

FastMCP路由:POST/mcp服务器/mcp/摘要/text

总结给定的文本块 📥 请求 主体:

{
    'text':'Your blob of text here. It can be unlimited, but is recommended to be within the context window of the LLM you are asking for a summary from.'
}

📤 答复:

{
    "status": "success",
    "summary": "A summary of your text."
}

🧩 环境变量

名称 描述 默认值
MODEL_NAME 您尝试引用的模型的名称。应与您的ollama实例中的模型匹配。 骆驼3
MODEL_URL 您尝试访问的模型的URL路径 http://host.docker.internal:11434

本地启动和调试

本地发布

# change with the LLM you want to use for summarize
export MODEL_NAME="hf-tool-llama3.2-3b-32k"
# change the URL of Ollama server
export MODEL_URL="http://0.0.0.0:11434/"
# change the 0.0.0.0:18990 not working for now when full docker to
# the IP address of sentry-nginx-1 and it's port.
# - SENTRY_URL="http://a87a15429de8e0c6e17217403ece2c13@0.0.0.0:18990/2"
export SENTRY_URL="http://a87a15429de8e0c6e17217403ece2c13@172.31.0.69:80/2"
source .venv/bin/activate
uv run uvicorn src.main:app --reload --port=19140 --log-level debug

或者使用Docker

docker compose -p hf-mcp-summarize up --build -d

在Codium中调试(Vscode完全开源,没有任何跟踪器)

添加此

        {
            "name": "Python Debugger: FastAPI",
            "type": "debugpy",
            "request": "launch",
            "module": "uvicorn",
            "args": [
                "main:app",
                "--reload",
                "--port",
                "19000"
            ],
            "env": {
                "MODEL": "hf-tool-llama3.2-3b-32k",
                "MODEL_URL": "http://0.0.0.0:11434/"
            },
            "jinja": true
        },

然后运行MCP检查器(如果您每天都在使用它,请创建一个别名;-)

npx -y @modelcontextprotocol/inspector
Starting MCP inspector...
⚙ Proxy server listening on 127.0.0.1:6277
🔑 Session token: 60095e43428a6e088eb77fee19951f148b5a839f0bc49fb519ed16d0a3f642ea
Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth

🔗 Open inspector with token pre-filled:
   http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=60095e43428a6e088eb77fee19951f148b5a839f0bc49fb519ed16d0a3f642ea
   (Auto-open is disabled when authentication is enabled)

🔍 MCP Inspector is up and running at http://127.0.0.1:6274 🚀
http://127.0.0.1:19140/mcp-server/mcp/