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.
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package tencent
|
|
|
|
type Config struct {
|
|
Enabled bool
|
|
SecretID string
|
|
SecretKey string
|
|
Region string
|
|
BizType string
|
|
Timeout int
|
|
}
|
|
|
|
type ModerationSuggestion string
|
|
|
|
const (
|
|
SuggestionPass ModerationSuggestion = "Pass"
|
|
SuggestionReview ModerationSuggestion = "Review"
|
|
SuggestionBlock ModerationSuggestion = "Block"
|
|
)
|
|
|
|
type ModerationResponse struct {
|
|
Suggestion ModerationSuggestion
|
|
Label string
|
|
RiskLevel string
|
|
Keywords []string
|
|
RequestID string
|
|
}
|
|
|
|
type textModerationRequest struct {
|
|
Content string `json:"Content"`
|
|
BizType string `json:"BizType,omitempty"`
|
|
}
|
|
|
|
type tencentAPIResponse struct {
|
|
Response struct {
|
|
Suggestion string `json:"Suggestion"`
|
|
Label string `json:"Label"`
|
|
RiskLevel string `json:"RiskLevel"`
|
|
Keywords []struct {
|
|
Word string `json:"Word"`
|
|
} `json:"Keywords,omitempty"`
|
|
RequestID string `json:"RequestId"`
|
|
Error *struct {
|
|
Code string `json:"Code"`
|
|
Message string `json:"Message"`
|
|
} `json:"Error,omitempty"`
|
|
} `json:"Response"`
|
|
}
|
|
|
|
func ConfigFromAppConfig(cfg *Config) Config {
|
|
return Config{
|
|
Enabled: cfg.Enabled,
|
|
SecretID: cfg.SecretID,
|
|
SecretKey: cfg.SecretKey,
|
|
Region: cfg.Region,
|
|
BizType: cfg.BizType,
|
|
Timeout: cfg.Timeout,
|
|
}
|
|
}
|