Documentation
¶
Index ¶
- Variables
- func StandardizeCategories(providerName string, categories map[string]interface{}) map[string]bool
- type AIFilter
- type AIFilterResult
- type AIProvider
- type AzureProvider
- func (p *AzureProvider) AnalyzeAudio(ctx context.Context, audioURL string) (*AIFilterResult, error)
- func (p *AzureProvider) AnalyzeImage(ctx context.Context, imageURL string) (*AIFilterResult, error)
- func (p *AzureProvider) AnalyzeText(ctx context.Context, text string) (*AIFilterResult, error)
- func (p *AzureProvider) AnalyzeVideo(ctx context.Context, videoURL string) (*AIFilterResult, error)
- type BaseProvider
- type BatchGetItem
- type BatchGetResult
- type BatchResult
- type BatchSetItem
- type CacheEntry
- type CacheKey
- type CacheManager
- func (cm *CacheManager) BatchGet(items []BatchGetItem) map[string]BatchGetResult
- func (cm *CacheManager) BatchSet(items []BatchSetItem) []error
- func (cm *CacheManager) Clear()
- func (cm *CacheManager) Get(contentType model.ContentType, content string) (interface{}, bool)
- func (cm *CacheManager) GetStats() CacheStats
- func (cm *CacheManager) Set(contentType model.ContentType, content string, value interface{}, size int64)
- func (cm *CacheManager) SetEvictionCallback(callback func(string, CacheEntry))
- func (cm *CacheManager) SetThreshold(name string, value float64)
- func (cm *CacheManager) SetThresholdCallback(callback func(CacheStats))
- type CacheMonitor
- type CacheStats
- type CategoryMapping
- type ContentFilter
- type ContentFilterService
- type FilterLevel
- type FilterResult
- type GoogleProvider
- func (p *GoogleProvider) AnalyzeAudio(ctx context.Context, audioURL string) (*AIFilterResult, error)
- func (p *GoogleProvider) AnalyzeImage(ctx context.Context, imageURL string) (*AIFilterResult, error)
- func (p *GoogleProvider) AnalyzeText(ctx context.Context, text string) (*AIFilterResult, error)
- func (p *GoogleProvider) AnalyzeVideo(ctx context.Context, videoURL string) (*AIFilterResult, error)
- type MonitorConfig
- type OpenAIProvider
- func (p *OpenAIProvider) AnalyzeAudio(ctx context.Context, audioURL string) (*AIFilterResult, error)
- func (p *OpenAIProvider) AnalyzeImage(ctx context.Context, imageURL string) (*AIFilterResult, error)
- func (p *OpenAIProvider) AnalyzeText(ctx context.Context, text string) (*AIFilterResult, error)
- func (p *OpenAIProvider) AnalyzeVideo(ctx context.Context, videoURL string) (*AIFilterResult, error)
- type ProviderConfig
- type ProviderType
- type TencentProvider
- func (p *TencentProvider) AnalyzeAudio(ctx context.Context, audioURL string) (*AIFilterResult, error)
- func (p *TencentProvider) AnalyzeImage(ctx context.Context, imageURL string) (*AIFilterResult, error)
- func (p *TencentProvider) AnalyzeText(ctx context.Context, text string) (*AIFilterResult, error)
- func (p *TencentProvider) AnalyzeVideo(ctx context.Context, videoURL string) (*AIFilterResult, error)
- type TypeStats
Constants ¶
This section is empty.
Variables ¶
var DefaultThresholds = map[string]float64{
"hit_rate_min": 0.7,
"memory_usage_max": 100e6,
"avg_access_time_max": 100,
"expired_ratio_max": 0.2,
}
DefaultThresholds 默认阈值配置
Functions ¶
Types ¶
type AIFilter ¶
type AIFilter struct {
// contains filtered or unexported fields
}
AIFilter AI内容过滤器
func (*AIFilter) Analyze ¶
func (f *AIFilter) Analyze(ctx context.Context, content string, contentType model.ContentType) (*AIFilterResult, error)
Analyze 分析内容
type AIFilterResult ¶
type AIFilterResult struct {
Score float64 `json:"score"`
Categories map[string]bool `json:"categories"`
Suggestions []string `json:"suggestions"`
}
AIFilterResult AI过滤结果
type AIProvider ¶
type AIProvider interface {
// AnalyzeText 分析文本内容
AnalyzeText(ctx context.Context, text string) (*AIFilterResult, error)
// AnalyzeImage 分析图片内容
AnalyzeImage(ctx context.Context, imageURL string) (*AIFilterResult, error)
// AnalyzeAudio 分析音频内容
AnalyzeAudio(ctx context.Context, audioURL string) (*AIFilterResult, error)
// AnalyzeVideo 分析视频内容
AnalyzeVideo(ctx context.Context, videoURL string) (*AIFilterResult, error)
// Name 获取提供商名称
Name() string
}
AIProvider 定义AI服务提供商接口
func NewAIProvider ¶
func NewAIProvider(config ProviderConfig) (AIProvider, error)
NewAIProvider 创建AI服务提供商实例
type AzureProvider ¶
type AzureProvider struct {
BaseProvider
// contains filtered or unexported fields
}
AzureProvider Azure Content Moderator服务提供商
func NewAzureProvider ¶
func NewAzureProvider(config ProviderConfig) (*AzureProvider, error)
NewAzureProvider 创建Azure Content Moderator服务提供商实例
func (*AzureProvider) AnalyzeAudio ¶
func (p *AzureProvider) AnalyzeAudio(ctx context.Context, audioURL string) (*AIFilterResult, error)
AnalyzeAudio 实现音频分析
func (*AzureProvider) AnalyzeImage ¶
func (p *AzureProvider) AnalyzeImage(ctx context.Context, imageURL string) (*AIFilterResult, error)
AnalyzeImage 实现图片分析
func (*AzureProvider) AnalyzeText ¶
func (p *AzureProvider) AnalyzeText(ctx context.Context, text string) (*AIFilterResult, error)
AnalyzeText 实现文本分析
func (*AzureProvider) AnalyzeVideo ¶
func (p *AzureProvider) AnalyzeVideo(ctx context.Context, videoURL string) (*AIFilterResult, error)
AnalyzeVideo 实现视频分析
type BaseProvider ¶
type BaseProvider struct {
// contains filtered or unexported fields
}
BaseProvider 基础AI服务提供商实现
func (*BaseProvider) Name ¶
func (p *BaseProvider) Name() string
type BatchGetItem ¶
type BatchGetItem struct {
ContentType model.ContentType
Content string
}
BatchGetItem 批量获取的条目
type BatchGetResult ¶
BatchGetResult 批量获取的结果
type BatchResult ¶
BatchResult 批量操作的结果
type BatchSetItem ¶
type BatchSetItem struct {
ContentType model.ContentType
Content string
Value interface{}
Size int64
}
BatchSetItem 批量设置的条目
type CacheEntry ¶
type CacheEntry struct {
Value interface{}
Size int64
Expiry time.Time
LastAccess time.Time
AccessCount int
}
CacheEntry 缓存条目
type CacheManager ¶
type CacheManager struct {
// contains filtered or unexported fields
}
CacheManager 缓存管理器
func NewCacheManager ¶
func NewCacheManager(maxEntries int, ttl time.Duration) *CacheManager
NewCacheManager 创建缓存管理器
func (*CacheManager) BatchGet ¶
func (cm *CacheManager) BatchGet(items []BatchGetItem) map[string]BatchGetResult
BatchGet 批量获取缓存条目
func (*CacheManager) BatchSet ¶
func (cm *CacheManager) BatchSet(items []BatchSetItem) []error
BatchSet 批量设置缓存条目
func (*CacheManager) Get ¶
func (cm *CacheManager) Get(contentType model.ContentType, content string) (interface{}, bool)
Get 获取缓存条目
func (*CacheManager) Set ¶
func (cm *CacheManager) Set(contentType model.ContentType, content string, value interface{}, size int64)
Set 设置缓存条目
func (*CacheManager) SetEvictionCallback ¶
func (cm *CacheManager) SetEvictionCallback(callback func(string, CacheEntry))
SetEvictionCallback 设置条目淘汰回调
func (*CacheManager) SetThreshold ¶
func (cm *CacheManager) SetThreshold(name string, value float64)
SetThreshold 设置监控阈值
func (*CacheManager) SetThresholdCallback ¶
func (cm *CacheManager) SetThresholdCallback(callback func(CacheStats))
SetThresholdCallback 设置阈值告警回调
type CacheMonitor ¶
type CacheMonitor struct {
// contains filtered or unexported fields
}
CacheMonitor 缓存监控服务
func NewCacheMonitor ¶
func NewCacheMonitor(cache *CacheManager, config MonitorConfig) (*CacheMonitor, error)
NewCacheMonitor 创建缓存监控服务
type CacheStats ¶
type CacheStats struct {
// 当前缓存大小
Size int
// 内存使用量(字节)
MemoryUsage int64
// 命中率
HitRate float64
// 平均访问时间(毫秒)
AvgAccessTime float64
// 过期条目数量
ExpiredEntries int
// 命中次数
Hits int
// 未命中次数
Misses int
// 按内容类型统计
TypeStats map[model.ContentType]TypeStats
}
CacheStats 缓存统计信息
type CategoryMapping ¶
CategoryMapping 定义不同提供商的类别映射
type ContentFilter ¶
type ContentFilter interface {
Filter(ctx context.Context, content string, contentType model.ContentType) (bool, string, error)
}
ContentFilter 内容过滤器接口
type ContentFilterService ¶
type ContentFilterService struct {
// contains filtered or unexported fields
}
ContentFilterService 内容过滤服务
func NewContentFilterService ¶
func NewContentFilterService(level FilterLevel) *ContentFilterService
NewContentFilterService 创建新的内容过滤服务
func (*ContentFilterService) AddRegexPattern ¶
func (s *ContentFilterService) AddRegexPattern(pattern string) error
AddRegexPattern 添加正则表达式模式
func (*ContentFilterService) Filter ¶
func (s *ContentFilterService) Filter(ctx context.Context, content string, contentType model.ContentType) (*FilterResult, error)
Filter 过滤内容
func (*ContentFilterService) LoadSensitiveWords ¶
func (s *ContentFilterService) LoadSensitiveWords(words []string)
LoadSensitiveWords 加载敏感词列表
type FilterLevel ¶
type FilterLevel int
FilterLevel 定义过滤级别
const ( LevelLow FilterLevel = 1 // 低级别过滤 LevelMedium FilterLevel = 2 // 中级别过滤 LevelHigh FilterLevel = 3 // 高级别过滤 )
type FilterResult ¶
type FilterResult struct {
IsClean bool `json:"is_clean"`
Score float64 `json:"score"`
Categories map[string]bool `json:"categories"`
Suggestions []string `json:"suggestions"`
Reason string `json:"reason"`
}
FilterResult 过滤结果
type GoogleProvider ¶
type GoogleProvider struct {
BaseProvider
// contains filtered or unexported fields
}
GoogleProvider Google Cloud Content Safety API服务提供商
func NewGoogleProvider ¶
func NewGoogleProvider(config ProviderConfig) (*GoogleProvider, error)
NewGoogleProvider 创建Google Cloud Content Safety API服务提供商实例
func (*GoogleProvider) AnalyzeAudio ¶
func (p *GoogleProvider) AnalyzeAudio(ctx context.Context, audioURL string) (*AIFilterResult, error)
AnalyzeAudio 实现音频分析
func (*GoogleProvider) AnalyzeImage ¶
func (p *GoogleProvider) AnalyzeImage(ctx context.Context, imageURL string) (*AIFilterResult, error)
AnalyzeImage 实现图片分析
func (*GoogleProvider) AnalyzeText ¶
func (p *GoogleProvider) AnalyzeText(ctx context.Context, text string) (*AIFilterResult, error)
AnalyzeText 实现文本分析
func (*GoogleProvider) AnalyzeVideo ¶
func (p *GoogleProvider) AnalyzeVideo(ctx context.Context, videoURL string) (*AIFilterResult, error)
AnalyzeVideo 实现视频分析
type MonitorConfig ¶
type MonitorConfig struct {
// 监控间隔
Interval time.Duration
// 日志文件路径
LogPath string
// 阈值告警配置
Thresholds map[string]float64
// 告警回调
AlertCallback func(alert string)
}
MonitorConfig 监控配置
type OpenAIProvider ¶
type OpenAIProvider struct {
BaseProvider
}
OpenAIProvider OpenAI服务提供商实现
func NewOpenAIProvider ¶
func NewOpenAIProvider(config ProviderConfig) (*OpenAIProvider, error)
NewOpenAIProvider 创建OpenAI服务提供商实例
func (*OpenAIProvider) AnalyzeAudio ¶
func (p *OpenAIProvider) AnalyzeAudio(ctx context.Context, audioURL string) (*AIFilterResult, error)
func (*OpenAIProvider) AnalyzeImage ¶
func (p *OpenAIProvider) AnalyzeImage(ctx context.Context, imageURL string) (*AIFilterResult, error)
func (*OpenAIProvider) AnalyzeText ¶
func (p *OpenAIProvider) AnalyzeText(ctx context.Context, text string) (*AIFilterResult, error)
func (*OpenAIProvider) AnalyzeVideo ¶
func (p *OpenAIProvider) AnalyzeVideo(ctx context.Context, videoURL string) (*AIFilterResult, error)
type ProviderConfig ¶
type ProviderConfig struct {
Type ProviderType `json:"type"`
APIKey string `json:"api_key"`
APISecret string `json:"api_secret,omitempty"`
Region string `json:"region,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
}
ProviderConfig AI服务提供商配置
type ProviderType ¶
type ProviderType string
ProviderType 定义AI服务提供商类型
const ( ProviderOpenAI ProviderType = "openai" ProviderAzure ProviderType = "azure" ProviderGoogle ProviderType = "google" ProviderTencent ProviderType = "tencent" )
type TencentProvider ¶
type TencentProvider struct {
BaseProvider
// contains filtered or unexported fields
}
TencentProvider 腾讯云内容安全服务提供商
func NewTencentProvider ¶
func NewTencentProvider(config ProviderConfig) (*TencentProvider, error)
NewTencentProvider 创建腾讯云内容安全服务提供商实例
func (*TencentProvider) AnalyzeAudio ¶
func (p *TencentProvider) AnalyzeAudio(ctx context.Context, audioURL string) (*AIFilterResult, error)
AnalyzeAudio 实现音频分析
func (*TencentProvider) AnalyzeImage ¶
func (p *TencentProvider) AnalyzeImage(ctx context.Context, imageURL string) (*AIFilterResult, error)
AnalyzeImage 实现图片分析
func (*TencentProvider) AnalyzeText ¶
func (p *TencentProvider) AnalyzeText(ctx context.Context, text string) (*AIFilterResult, error)
AnalyzeText 实现文本分析
func (*TencentProvider) AnalyzeVideo ¶
func (p *TencentProvider) AnalyzeVideo(ctx context.Context, videoURL string) (*AIFilterResult, error)
AnalyzeVideo 实现视频分析