Skip to main content

基于大语言模型(LLM)的内容审核工具,支持文本与图像,自定义审核项配置,调用模型获得结构化判定结果,使用 OpenAI 兼容接口

Project description

ai-content-audit

基于大语言模型(LLM)的内容审核工具包:支持文本和图像审核,定义审核项、加载内容、调用模型获得结构化判定结果。

安装

  • 使用 Python 3.12+
  • 克隆本仓库:
git clone https://github.com/Apauto-to-all/ai-content-audit.git
cd ai-content-audit
  • 安装依赖包:
pip install openai pydantic filetype python-dotenv

或使用 uv:

uv sync

快速上手

文本审核

from openai import OpenAI
from ai_content_audit import AuditManager, loader

client = OpenAI(base_url="https://", api_key="your_key")
manager = AuditManager(client=client, model="qwen-plus")

# 定义审核项
item = loader.options_item.create(
    name="是否包含敏感信息",
    instruction="检查文本中是否出现用户定义的敏感信息。",
    options={"有":"检测到", "无":"未检测到", "不确定":"无法判断"},
)

# 准备文本
text = loader.audit_data.create(content="本文由xxx发布,联系电话:13800138000。")

# 审核
result = manager.audit_one(text, item)
print(f"审核项: {result.item_name}")
print(f"文本节选: {result.text_excerpt}...")
print(f"决策: {result.decision.choice}")
print(f"理由: {result.decision.reason}")

图像审核

# 使用视觉模型审核图片
manager = AuditManager(client=client, model="qwen-vl-plus")

# 加载图片
image = loader.audit_data.from_file("path/to/image.jpg")

# 审核
result = manager.audit_one(image, item)
print(f"决策: {result.decision.choice}")
print(f"理由: {result.decision.reason}")

功能特性

  • 文本审核:支持纯文本内容审核
  • 图像审核:支持 JPEG、PNG、WebP 等格式,使用视觉模型
  • 批量审核:同时审核多个内容和多个审核项
  • 灵活加载:从文件、目录或内存加载内容
  • 结构化输出:基于 Pydantic 的审核结果模型

示例

查看 example/ 目录中的完整示例:

  • example.py:基础文本审核示例
  • image_examples.py:图像审核示例
  • batch_examples.py:批量审核示例
  • file_examples.py:文件加载示例

运行示例:

python example/example.py
python example/image_examples.py

许可证

Apache-2.0,见 LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_content_audit-0.2.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_content_audit-0.2.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file ai_content_audit-0.2.0.tar.gz.

File metadata

  • Download URL: ai_content_audit-0.2.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for ai_content_audit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 01aaf5868dafd1e997293f2399f2a1b1ba88ae1a1b62f5d2267abe4ce4ef8832
MD5 b7ec281d48157cb53051a47be672c408
BLAKE2b-256 e854787f7a494510d068d4eaac2ba36bc5670268b78343bb1c049c99b3eec301

See more details on using hashes here.

File details

Details for the file ai_content_audit-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_content_audit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93be32f388811c8cf1d118febbdc9abfbf0f7055caac051013aa3145f22f3eac
MD5 e2a64523e972f89e27d2cc9c865c43d3
BLAKE2b-256 9a12a928f504ec8fc60e5d26dcbfaf08b31ecf08b409f95f694c0417b73f1069

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page