Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 0cb9dd8

Browse files
committed
Enhance multimodal detection capabilities and update configurations
- Introduced a new multimodal detection feature, allowing the system to analyze both text and image content for safety. - Added support for image input via base64 encoding and URLs, enhancing the flexibility of the detection API. - Updated the backend to include new models and routes for handling image uploads and processing. - Enhanced the API to support mixed content types in detection requests, ensuring consistent risk assessment across modalities. - Improved the README files with detailed descriptions of the multimodal detection functionality and usage examples. - Incremented version numbers in both backend and frontend to 2.3.0 to signify the introduction of these features.
1 parent 6eb56f9 commit 0cb9dd8

27 files changed

+1845
-118
lines changed

CHANGELOG.md

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,99 @@ All notable changes to Xiangxin AI Guardrails platform are documented in this fi
1010
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1111
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1212

13+
## [2.3.0] - 2025-09-30
14+
15+
### 🚀 重大更新 Major Updates
16+
- 🖼️ **多模态检测功能**
17+
- 新增图片模态安全检测能力
18+
- 支持图片内容的合规性和安全性检测
19+
- 与文本检测保持一致的风险类型和检测标准
20+
- 完整支持API调用模式和安全网关模式
21+
22+
### 新增 Added
23+
- 🖼️ **图片检测功能**
24+
- 支持base64编码和URL两种图片输入方式
25+
- 调用多模态检测模型 `Xiangxin-Guardrails-VL`
26+
- 图片文件存储在用户专属目录(/mnt/data/xiangxin-guardrails-data/media/{user_uuid}/)
27+
- 支持在线测试界面上传图片进行检测
28+
- 新增图片上传组件和预览功能
29+
30+
- 🔌 **API接口增强**
31+
- 检测API支持混合消息(文本+图片)
32+
- messages中的content支持数组格式:`[{"type": "text"}, {"type": "image_url"}]`
33+
- 图片URL支持 `data:image/jpeg;base64,...``file://...` 两种格式
34+
- 安全网关代理服务完整支持多模态请求透传
35+
36+
- 📁 **新增文件**
37+
- `backend/routers/media.py` - 媒体文件管理路由
38+
- `backend/utils/image_utils.py` - 图片处理工具
39+
- `backend/utils/url_signature.py` - URL签名验证工具
40+
- `backend/scripts/migrate_add_image_fields.py` - 数据库迁移脚本
41+
- `frontend/src/components/ImageUpload/` - 图片上传组件
42+
43+
### 变更 Changed
44+
- 🔄 **检测服务增强**
45+
- 检测模型调用逻辑支持多模态内容
46+
- 检测结果数据库表新增图片相关字段
47+
- 在线测试页面支持图片上传和预览
48+
49+
- 🌐 **API响应格式**
50+
- 保持与文本检测一致的响应格式
51+
- 多标签风险支持:可返回多个unsafe标签(如:unsafe\nS1,S2)
52+
- 敏感度分数和等级适用于图片检测
53+
54+
### 技术特性 Technical Features
55+
- **图片检测模型**:基于视觉-语言模型的多模态安全检测
56+
- **存储管理**:用户级别的媒体文件隔离存储
57+
- **URL安全**:支持签名URL防止未授权访问
58+
- **格式兼容**:兼容OpenAI Vision API消息格式
59+
60+
### 使用示例 Usage Examples
61+
62+
#### Python API调用示例
63+
```python
64+
import base64
65+
from xiangxinai import XiangxinAI
66+
67+
client = XiangxinAI("your-api-key")
68+
69+
# 图片base64编码
70+
with open("image.jpg", "rb") as f:
71+
image_base64 = base64.b64encode(f.read()).decode("utf-8")
72+
73+
# 发送图片检测请求
74+
response = client.check_messages([
75+
{
76+
"role": "user",
77+
"content": [
78+
{"type": "text", "text": "这个图片安全吗?"},
79+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_base64}"}}
80+
]
81+
}
82+
])
83+
84+
print(f"检测结果: {response.overall_risk_level}")
85+
print(f"风险类别: {response.all_categories}")
86+
```
87+
88+
#### cURL调用示例
89+
```bash
90+
curl -X POST "http://localhost:5001/v1/guardrails" \
91+
-H "Authorization: Bearer your-api-key" \
92+
-H "Content-Type: application/json" \
93+
-d '{
94+
"model": "Xiangxin-Guardrails-VL",
95+
"messages": [{
96+
"role": "user",
97+
"content": [
98+
{"type": "text", "text": "这个图片安全吗?"},
99+
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}}
100+
]
101+
}],
102+
"logprobs": true
103+
}'
104+
```
105+
13106
## [2.2.0] - 2025-01-15
14107

15108
### 🚀 重大更新 Major Updates
@@ -49,7 +142,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
49142
```
50143

51144
## [2.1.0] - 2025-09-29
52-
增加敏感度阈值配置功能,应对特殊场景和全自动流水线
145+
增加敏感度阈值配置功能,可自定义检测的敏感度阈值,可用于应对特殊场景或全自动流水线场景
53146

54147
## [2.0.0] - 2025-01-01
55148

README.md

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ English | [中文](./README_ZH.md)
2525

2626
- 🪄 **Two Usage Modes** - Detection API + Security Gateway
2727
- 🛡️ **Dual Protection** - Prompt attack detection + Content compliance detection
28+
- 🖼️ **Multimodal Detection** - Support for text and image content safety detection 🆕
2829
- 🧠 **Context Awareness** - Intelligent safety detection based on conversation context
2930
- 📋 **Compliance Standards** - Compliant with "GB/T45654—2025 Basic Security Requirements for Generative AI Services"
3031
- 🔧 **Flexible Configuration** - Blacklist/whitelist, response templates, rate limiting and other personalized configurations
@@ -34,11 +35,11 @@ English | [中文](./README_ZH.md)
3435
- 📊 **Visual Management** - Intuitive web management interface and real-time monitoring
3536
-**High Performance** - Asynchronous processing, supporting high-concurrency access
3637
- 🔌 **Easy Integration** - Compatible with OpenAI API format, one-line code integration
37-
- 🎯 **Configurable Sensitivity** - Three-tier sensitivity threshold configuration for automated pipeline scenarios 🆕
38+
- 🎯 **Configurable Sensitivity** - Three-tier sensitivity threshold configuration for automated pipeline scenarios
3839

3940
## 🚀 Dual Mode Support
4041

41-
Xiangxin AI Guardrails 2.1 supports two usage modes to meet different scenario requirements:
42+
Xiangxin AI Guardrails 2.3 supports two usage modes to meet different scenario requirements:
4243

4344
### 🔍 API Call Mode
4445
Developers **actively call** detection APIs for safety checks
@@ -394,7 +395,74 @@ User Request → Security Gateway(5002) → Input Safety Detection
394395
- **Smart Recognition**: Automatic detection of reasoning_content, thinking and other reasoning fields
395396
- **Transparent Proxy**: Full OpenAI API compatibility, supports all reasoning models
396397

397-
## 🧠 Knowledge Base Responses Feature 🆕
398+
## 🖼️ Multimodal Detection Feature 🆕
399+
400+
Xiangxin AI Guardrails v2.3.0 introduces **image modality detection**, expanding safety protection from text-only to multimodal content.
401+
402+
### 📸 Key Features
403+
404+
- **Image Content Detection**: AI-powered safety analysis of image content
405+
- **Unified Risk Standards**: Same risk categories (S1-S12) apply to both text and images
406+
- **Multiple Input Formats**: Support for base64-encoded images and image URLs
407+
- **Seamless Integration**: Compatible with both API Call Mode and Security Gateway Mode
408+
- **OpenAI Vision Compatible**: Supports OpenAI Vision API message format
409+
410+
### 🔄 Usage Examples
411+
412+
#### Python API - Image Detection
413+
```python
414+
import base64
415+
from xiangxinai import XiangxinAI
416+
417+
client = XiangxinAI("your-api-key")
418+
419+
# Encode image to base64
420+
with open("image.jpg", "rb") as f:
421+
image_base64 = base64.b64encode(f.read()).decode("utf-8")
422+
423+
# Check image safety
424+
response = client.check_messages([
425+
{
426+
"role": "user",
427+
"content": [
428+
{"type": "text", "text": "Is this image safe?"},
429+
{
430+
"type": "image_url",
431+
"image_url": {"url": f"data:image/jpeg;base64,{image_base64}"}
432+
}
433+
]
434+
}
435+
])
436+
437+
print(f"Risk Level: {response.overall_risk_level}")
438+
print(f"Risk Categories: {response.all_categories}")
439+
```
440+
441+
#### HTTP API - Image Detection
442+
```bash
443+
curl -X POST "http://localhost:5001/v1/guardrails" \
444+
-H "Authorization: Bearer your-api-key" \
445+
-H "Content-Type: application/json" \
446+
-d '{
447+
"model": "Xiangxin-Guardrails-VL",
448+
"messages": [{
449+
"role": "user",
450+
"content": [
451+
{"type": "text", "text": "Is this image safe?"},
452+
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}}
453+
]
454+
}]
455+
}'
456+
```
457+
458+
### 🎯 Use Cases
459+
460+
- **Social Media**: Automatically screen user-uploaded images for unsafe content
461+
- **E-commerce**: Ensure product images comply with platform policies
462+
- **Education**: Protect minors from inappropriate image content
463+
- **Content Platforms**: Moderate AI-generated images before publication
464+
465+
## 🧠 Knowledge Base Responses Feature
398466

399467
Xiangxin AI Guardrails v2.2.0 introduces powerful knowledge base response functionality with vector similarity-based intelligent Q&A matching.
400468

@@ -1047,13 +1115,15 @@ We provide professional AI safety solutions:
10471115
Xiangxin AI Guardrails will continue to evolve in two directions: **Detection Capabilities** and **Platform Features**, ensuring that large model applications run under safe and compliant conditions.
10481116

10491117
### 🔍 Detection Capabilities
1118+
-**Image Modality Detection** (v2.3.0): AI-powered image content safety analysis
1119+
- **Audio & Video Detection**: Support for audio and video content safety analysis (Coming Soon)
10501120
- **Multimodal Subtle Violation Content Recognition**: Support multimodal inputs including text, images, audio, and video, identifying and intercepting subtle violations or illegal information.
10511121
- **Role-based Privilege Escalation Detection**: Combined with context and user identity, identify and intercept privilege escalation questions or sensitive information requests.
10521122
- **Personal Information & Sensitive Data Detection**: Automatically identify and intercept content involving personal information, business secrets, and other sensitive content to prevent data leaks.
10531123
- **Out-of-business-scope Content Detection**: Identify and intervene in questions/outputs that exceed business scenarios or compliance boundaries.
10541124

10551125
### 🛡️ Platform Features
1056-
- **Multimodal Content Recognition Support**: Provide security recognition matching actual application modalities (text, images, audio, video, files).
1126+
- **Multimodal Content Recognition Support** (v2.3.0): Text and image safety detection available
10571127
- **Sensitive Information Interception & Desensitization**: When sensitive content is detected, it can be directly intercepted or automatically desensitized based on rules before output.
10581128
- **Desensitization Rule Configuration**: Support user-defined desensitization strategies, flexibly adapting to compliance requirements in different scenarios.
10591129
- **Out-of-business-scope Control**: Block or substitute answers for privilege escalation or inappropriate questions, ensuring compliant output.

README_ZH.md

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525

2626
- 🪄 **两种使用模式** - 检测API + 安全网关
2727
- 🛡️ **双重防护** - 提示词攻击检测 + 内容合规检测
28+
- 🖼️ **多模态检测** - 支持文本和图片内容安全检测 🆕
2829
- 🧠 **上下文感知** - 基于对话上下文的智能安全检测
2930
- 📋 **合规标准** - 符合《GB/T45654—2025 生成式人工智能服务安全基本要求》
3031
- 🔧 **灵活配置** - 黑白名单、代答库、限速等个性化配置
31-
- 🧠 **代答知识库** - 基于向量相似度的智能问答匹配,支持自定义问答对知识库 🆕
32-
- 🎯 **敏感度阈值配置** - 三档敏感度阈值配置,适应自动化流水线等不同使用场景 🆕
32+
- 🧠 **代答知识库** - 基于向量相似度的智能问答匹配,支持自定义问答对知识库
33+
- 🎯 **敏感度阈值配置** - 三档敏感度阈值配置,适应自动化流水线等不同使用场景
3334
- 🏢 **私有化部署** - 支持完全本地化部署,数据安全可控
3435
- 🔌 **客户系统集成** - 支持与客户现有用户系统深度集成,API级别的配置管理
3536
- 📊 **可视化管理** - 直观的Web管理界面和实时监控
@@ -38,7 +39,7 @@
3839

3940
## 🚀 双模式支持
4041

41-
象信AI安全护栏2.1支持两种使用模式,满足不同场景需求:
42+
象信AI安全护栏2.3支持两种使用模式,满足不同场景需求:
4243

4344
### 🔍 API调用模式
4445
开发者**主动调用**检测API进行安全检测
@@ -392,7 +393,74 @@ response = client.chat.completions.create(model="local-reasoning-llm", messages=
392393
[通过检测] → 返回给用户
393394
```
394395

395-
## 🧠 代答知识库功能 🆕
396+
## 🖼️ 多模态检测功能 🆕
397+
398+
象信AI安全护栏v2.3.0新增**图片模态检测**功能,将安全防护从纯文本扩展到多模态内容。
399+
400+
### 📸 核心功能
401+
402+
- **图片内容检测**:AI智能分析图片内容的安全性
403+
- **统一风险标准**:图片和文本使用相同的风险类型(S1-S12)
404+
- **多种输入格式**:支持base64编码图片和图片URL
405+
- **无缝集成**:兼容API调用模式和安全网关模式
406+
- **OpenAI Vision兼容**:支持OpenAI Vision API消息格式
407+
408+
### 🔄 使用示例
409+
410+
#### Python API - 图片检测
411+
```python
412+
import base64
413+
from xiangxinai import XiangxinAI
414+
415+
client = XiangxinAI("your-api-key")
416+
417+
# 图片base64编码
418+
with open("image.jpg", "rb") as f:
419+
image_base64 = base64.b64encode(f.read()).decode("utf-8")
420+
421+
# 检测图片安全性
422+
response = client.check_messages([
423+
{
424+
"role": "user",
425+
"content": [
426+
{"type": "text", "text": "这个图片安全吗?"},
427+
{
428+
"type": "image_url",
429+
"image_url": {"url": f"data:image/jpeg;base64,{image_base64}"}
430+
}
431+
]
432+
}
433+
])
434+
435+
print(f"风险等级: {response.overall_risk_level}")
436+
print(f"风险类别: {response.all_categories}")
437+
```
438+
439+
#### HTTP API - 图片检测
440+
```bash
441+
curl -X POST "http://localhost:5001/v1/guardrails" \
442+
-H "Authorization: Bearer your-api-key" \
443+
-H "Content-Type: application/json" \
444+
-d '{
445+
"model": "Xiangxin-Guardrails-VL",
446+
"messages": [{
447+
"role": "user",
448+
"content": [
449+
{"type": "text", "text": "这个图片安全吗?"},
450+
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}}
451+
]
452+
}]
453+
}'
454+
```
455+
456+
### 🎯 应用场景
457+
458+
- **社交媒体**:自动筛查用户上传的图片内容
459+
- **电商平台**:确保商品图片符合平台规范
460+
- **教育平台**:保护未成年人免受不良图片影响
461+
- **内容平台**:审核AI生成的图片内容
462+
463+
## 🧠 代答知识库功能
396464

397465
象信AI安全护栏v2.2.0新增了强大的代答知识库功能,基于向量相似度搜索提供智能问答匹配。
398466

@@ -1272,16 +1340,18 @@ git push origin feature/amazing-feature
12721340
象信 AI 安全护栏将持续演进,在 **检测能力****平台功能** 两个方向不断增强,确保大模型应用在安全、合规的前提下运行。
12731341

12741342
### 🔍 检测能力
1275-
- **多模态隐晦违规内容识别**:支持文本、图像、音频、视频等多模态输入,识别并拦截隐蔽的违规或违法信息。
1276-
- **基于用户角色的越权检测**:结合上下文与用户身份,识别并拦截越权提问或敏感信息请求。
1277-
- **个人信息与敏感数据检测**:自动识别、拦截涉及个人信息、商业秘密等敏感内容,防止数据泄露。
1278-
- **超业务范围内容检测**:对超出业务场景或合规边界的提问/输出进行识别和干预。
1343+
-**图片模态检测** (v2.3.0):AI智能分析图片内容的安全性
1344+
- **音频视频检测**:支持音频和视频内容安全分析(即将推出)
1345+
- **多模态隐晦违规内容识别**:支持文本、图像、音频、视频等多模态输入,识别并拦截隐蔽的违规或违法信息。
1346+
- **基于用户角色的越权检测**:结合上下文与用户身份,识别并拦截越权提问或敏感信息请求。
1347+
- **个人信息与敏感数据检测**:自动识别、拦截涉及个人信息、商业秘密等敏感内容,防止数据泄露。
1348+
- **超业务范围内容检测**:对超出业务场景或合规边界的提问/输出进行识别和干预。
12791349

12801350
### 🛡️ 平台功能
1281-
- **多模态内容识别支持**:提供与实际应用模态匹配的安全识别(文本、图像、音频、视频、文件)。
1282-
- **敏感信息拦截与脱敏**:在检测到敏感内容时,可直接拦截或基于规则进行自动脱敏后输出。
1283-
- **脱敏规则配置**:支持用户自定义脱敏策略,灵活适配不同场景的合规需求。
1284-
- **超业务范围管控**:对越权或不当提问进行拒答或代答,确保输出合规。
1351+
- **多模态内容识别支持** (v2.3.0):文本和图片安全检测已上线
1352+
- **敏感信息拦截与脱敏**:在检测到敏感内容时,可直接拦截或基于规则进行自动脱敏后输出。
1353+
- **脱敏规则配置**:支持用户自定义脱敏策略,灵活适配不同场景的合规需求。
1354+
- **超业务范围管控**:对越权或不当提问进行拒答或代答,确保输出合规。
12851355
- **可配置的代答知识库**:支持可配置、可扩展、可持续更新的标准代答知识库,保障应答一致性和可控性。
12861356

12871357
本路线图会随着 **安全攻防形势****合规要求** 的变化持续更新,欢迎社区用户提出建议和贡献。

backend/.env.example

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,23 @@ GUARDRAILS_MODEL_API_URL=http://your-host-ip:your-port/v1
2020
GUARDRAILS_MODEL_API_KEY=your-guardrails-model-api-key
2121
GUARDRAILS_MODEL_NAME=Xiangxin-Guardrails-Text
2222

23+
# 多模态模型配置
24+
GUARDRAILS_VL_MODEL_API_URL=http://localhost:58003/v1
25+
GUARDRAILS_VL_MODEL_API_KEY=your-vl-model-api-key
26+
GUARDRAILS_VL_MODEL_NAME=Xiangxin-Guardrails-VL
27+
2328
# 检测最大上下文长度配置 (应该等于模型max-model-len - 1000)
2429
MAX_DETECTION_CONTEXT_LENGTH=7168
2530

31+
# 嵌入模型API配置
32+
# 用于知识库向量化的嵌入模型API
33+
EMBEDDING_API_BASE_URL=http://your-host-ip:your-port/v1
34+
EMBEDDING_API_KEY=your-embedding-api-key
35+
EMBEDDING_MODEL_NAME=Xiangxin-Embedding-1024
36+
EMBEDDING_MODEL_DIMENSION=1024
37+
EMBEDDING_SIMILARITY_THRESHOLD=0.7
38+
EMBEDDING_MAX_RESULTS=5
39+
2640
# API配置
2741
CORS_ORIGINS=*
2842

@@ -35,14 +49,6 @@ SUPPORT_EMAIL=wanglei@xiangxinai.cn
3549
# HuggingFace模型
3650
HUGGINGFACE_MODEL=xiangxinai/Xiangxin-Guardrails-Text
3751

38-
# 嵌入模型API配置
39-
# 用于知识库向量化的嵌入模型API
40-
EMBEDDING_API_BASE_URL=http://your-host-ip:your-port/v1
41-
EMBEDDING_API_KEY=your-embedding-api-key
42-
EMBEDDING_MODEL_NAME=Xiangxin-Embedding-1024
43-
EMBEDDING_MODEL_DIMENSION=1024
44-
EMBEDDING_SIMILARITY_THRESHOLD=0.7
45-
EMBEDDING_MAX_RESULTS=5
4652

4753
# JWT配置
4854
# 警告:请生成一个安全的随机密钥!可以使用: openssl rand -base64 64

0 commit comments

Comments
 (0)