Files
backend/internal/config/external.go
lafay 38d628c696
Some checks failed
Build Backend / build (push) Failing after 45s
Build Backend / build-docker (push) Has been skipped
feat(moderation): add Tencent TMS as fallback for AI content moderation
Add Tencent Cloud Text Moderation System (TMS) as a fallback moderation
service when OpenAI is unavailable or returns an error. The service
now checks OpenAI first, and falls back to Tencent TMS if it fails,
providing better reliability for content moderation.

Features:
- New Tencent TMS configuration in config.yaml with environment variable overrides
- New tencent package in internal/pkg/tencent/ with TMS client implementation
- PostAIService now uses dual moderation with OpenAI primary and Tencent fallback
- Strict mode configuration passed to PostAIService for consistent behavior

BREAKING CHANGE: NewPostAIService now requires tencentClient and strictMode
parameters - update wire configuration accordingly.
2026-04-21 22:31:30 +08:00

37 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package config
// HotRankConfig 热门榜定时重算(仅 Redis ZSET + 分层缓存中的 Top ID 列表,不写库)
type HotRankConfig struct {
Enabled bool `mapstructure:"enabled"`
RefreshIntervalSeconds int `mapstructure:"refresh_interval_seconds"`
// TopN 写入缓存的热门条数ZSET 与 top_ids 列表长度上限)
TopN int `mapstructure:"top_n"`
// RecentWindowHours 候选池:该时间窗内新发的帖子 ID 会参与本轮重算
RecentWindowHours int `mapstructure:"recent_window_hours"`
// RecentFetchLimit 时间窗内最多拉取的帖子 ID 数(按 created_at 倒序)
RecentFetchLimit int `mapstructure:"recent_fetch_limit"`
// CandidateCap 候选 ID 合并后的上限(上届 Top + 新帖去重后截断)
CandidateCap int `mapstructure:"candidate_cap"`
}
// OpenAIConfig OpenAI 配置
type OpenAIConfig struct {
Enabled bool `mapstructure:"enabled"`
BaseURL string `mapstructure:"base_url"`
APIKey string `mapstructure:"api_key"`
ModerationModel string `mapstructure:"moderation_model"`
ModerationMaxImagesPerRequest int `mapstructure:"moderation_max_images_per_request"`
RequestTimeout int `mapstructure:"request_timeout"`
StrictModeration bool `mapstructure:"strict_moderation"`
}
// TencentTMSConfig 腾讯云文本内容安全配置(作为 OpenAI 审核的备用)
type TencentTMSConfig struct {
Enabled bool `mapstructure:"enabled"`
SecretID string `mapstructure:"secret_id"`
SecretKey string `mapstructure:"secret_key"`
Region string `mapstructure:"region"`
BizType string `mapstructure:"biz_type"`
Timeout int `mapstructure:"timeout"`
}