Back to MCP directory
publicPublicdnsLocal runtime

langextract-web

基于Google LangExtract库的Web界面、API和MCP服务,支持使用LLM从文本中提取结构化信息,提供可视化界面和多种模型集成。

article

README

🚀 LangExtract Web

🔍 使用大语言模型从文本中提取结构化信息 — 这是一个为 Google 的 LangExtract 库打造的 Web 界面 + API + MCP 包装器,能有效助力文本信息提取工作。

UI Screenshot

🚀 快速开始

Docker(推荐)

docker run -d -p 8600:8600 \
  -e LANGEXTRACT_API_KEY=your-gemini-api-key \
  neosun/langextract:latest

打开 http://localhost:8600

Docker Compose

services:
  langextract:
    image: neosun/langextract:latest
    ports:
      - "8600:8600"
    environment:
      - LANGEXTRACT_API_KEY=${LANGEXTRACT_API_KEY}
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - OLLAMA_HOST=http://host.docker.internal:11434
    volumes:
      - /tmp/langextract:/tmp/langextract
    extra_hosts:
      - "host.docker.internal:host-gateway"
docker compose up -d

✨ 主要特性

  • 🎯 精准溯源 — 每个提取结果都能精确映射回文本中的具体位置。
  • 📚 少样本学习 — 只需少量示例即可定义提取任务,无需微调。
  • 📄 长文档优化 — 通过分块和多轮提取,实现高召回率。
  • 🌐 Web 界面 — 拥有现代、响应式的界面,支持暗模式和国际化。
  • 🔌 REST API — 在 /docs 处提供完整的 Swagger 文档。
  • 🤖 MCP 支持 — 支持模型上下文协议,便于与 AI 助手集成。
  • 🔧 LiteLLM 兼容 — 可使用任何大语言模型提供商(如 Gemini、OpenAI、Claude、Ollama 等)。
  • 📁 文件上传 — 支持拖放文件或从 URL 获取内容。

📦 安装指南

从源代码安装

git clone https://github.com/neosun100/langextract-web.git
cd langextract-web

# 安装依赖
pip install -e .
pip install flask flask-cors flasgger gunicorn

# 运行
python app.py

环境变量

| 变量 | 描述 | 是否必需 | |----------|-------------|----------| | LANGEXTRACT_API_KEY | Gemini API 密钥 | 是(使用 Gemini 时) | | OPENAI_API_KEY | OpenAI API 密钥 | 使用 OpenAI 模型时需要 | | OLLAMA_HOST | Ollama 服务器 URL | 使用本地模型时需要 | | PORT | 服务器端口(默认:8600) | 否 |

💻 使用示例

Web 界面

  1. 打开 http://localhost:8600
  2. 输入文本或拖放文件/粘贴 URL
  3. 定义提取提示和少样本示例
  4. 选择模型并配置参数
  5. 点击“提取”并查看可视化结果

REST API

# 健康检查
curl http://localhost:8600/health

# 提取
curl -X POST http://localhost:8600/api/extract \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Lady Juliet gazed at the stars, her heart aching for Romeo.",
    "prompt": "Extract characters and emotions",
    "examples": [{
      "text": "ROMEO spoke softly",
      "extractions": [{"extraction_class": "character", "extraction_text": "ROMEO"}]
    }],
    "model_id": "gemini-2.5-flash"
  }'

完整的 API 文档:http://localhost:8600/docs

MCP 集成

{
  "mcpServers": {
    "langextract": {
      "command": "docker",
      "args": ["exec", "-i", "langextract", "python", "mcp_server.py"]
    }
  }
}

🔧 技术细节

提取参数

| 参数 | 默认值 | 描述 | |-----------|---------|-------------| | max_char_buffer | 1000 | 每次推理块的字符数 | | extraction_passes | 1 | 提取轮数(数值越高,召回率越高) | | max_workers | 10 | 并行工作线程数,用于提高速度 | | batch_length | 10 | 每批处理的块数 | | temperature | 0 | 采样温度(0 表示确定性) | | context_window_chars | - | 跨块上下文,用于指代消解 |

支持的模型

| 提供商 | 模型 | |----------|--------| | Google | gemini-2.5-flash ⭐, gemini-2.5-pro | | OpenAI | gpt-4o, gpt-4o-mini | | Anthropic | claude-3-5-sonnet-20241022 | | Ollama | gemma2:2b, llama3.2:3b 等 | | LiteLLM | 任何 提供商/模型 格式 |

🏗️ 技术栈

  • 后端:Flask、Gunicorn
  • 核心:Google 的 LangExtract
  • 大语言模型:Google Gemini、OpenAI、Anthropic、Ollama
  • 容器:Docker

📝 更新日志

v1.2.0

  • ✨ 支持文件拖放上传
  • ✨ 支持从 URL 获取内容
  • ✨ 支持自定义模型(LiteLLM)
  • ✨ 在界面中完全暴露参数
  • ✨ 添加项目介绍部分

v1.0.0

  • 🎉 初始版本,包含 Web 界面 + API + MCP

🤝 贡献

欢迎贡献代码!请阅读 贡献指南

📄 许可证

采用 Apache 2.0 许可证 - 详情见 LICENSE

本项目基于 Google 的 LangExtract 开发。


⭐ 星标历史

Star History Chart

📱 关注我们

WeChat

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client