text

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Aliyun service type for text moderation
	AliyunServiceChatDetection = "chat_detection"
	// Aliyun high-risk labels that result in block
	AliyunHighRiskLabelTerrorism  = "terrorism"
	AliyunHighRiskLabelPorn       = "porn"
	AliyunHighRiskLabelContraband = "contraband"
)
View Source
const (
	// QCloud suggestion values (from API response)
	QCloudSuggestionPass   = "Pass"
	QCloudSuggestionReview = "Review"
	QCloudSuggestionBlock  = "Block"
	// QCloud score conversion (percentage to 0-1 range)
	QCloudScoreDivisor = 100.0
	// QCloud keywords format string
	QCloudKeywordsFormat = "Keywords: %v"
)
View Source
const (
	// TextCensorEndpoint is the text moderation API endpoint
	TextCensorEndpoint = "/v3/text/censor"
	// TextCensorHost is the text moderation API host
	TextCensorHost   = "ai.qiniuapi.com"
	TextCensorScenes = "antispam"
)
View Source
const (
	// Provider kinds
	KindAliyun = "aliyun"
	KindQCloud = "qcloud"
	KindQiNiu  = "qiniu"

	// Suggestion values
	SuggestionPass   = "pass"
	SuggestionReview = "review"
	SuggestionBlock  = "block"

	// Label values
	LabelNormal      = "normal"
	LabelSpam        = "spam"
	LabelAd          = "ad"
	LabelPolitics    = "politics"
	LabelTerrorism   = "terrorism"
	LabelAbuse       = "abuse"
	LabelPorn        = "porn"
	LabelFlood       = "flood"
	LabelContraband  = "contraband"
	LabelMeaningless = "meaningless"

	// Chinese messages for labels
	MsgNormal       = "正常文本"
	MsgSpam         = "含垃圾信息"
	MsgAd           = "广告"
	MsgPolitics     = "涉政"
	MsgTerrorism    = "暴恐"
	MsgAbuse        = "辱骂"
	MsgPorn         = "色情"
	MsgFlood        = "灌水"
	MsgContraband   = "违禁"
	MsgMeaningless  = "无意义"
	MsgUnknownLabel = "未知标签: %s"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AliyunTextCensor

type AliyunTextCensor struct {
	AccessKeyID     string
	AccessKeySecret string
	Endpoint        string
	Client          *green.Client
}

AliyunTextCensor is the client for Alibaba Cloud text content moderation

func NewAliyunTextCensor

func NewAliyunTextCensor() (*AliyunTextCensor, error)

NewAliyunTextCensor creates a new Alibaba Cloud text moderation client

func (*AliyunTextCensor) CensorText

func (c *AliyunTextCensor) CensorText(text string) (*CensorResult, error)

CensorText performs text content moderation Returns: CensorResult with suggestion, label, and score

type CensorResult

type CensorResult struct {
	Suggestion string  `json:"suggestion"`        // pass, review, or block
	Label      string  `json:"label"`             // Moderation label: normal, spam, ad, politics, terrorism, abuse, porn, flood, contraband, etc.
	Score      float64 `json:"score"`             // Confidence score (0.0 to 1.0)
	Details    string  `json:"details,omitempty"` // Additional details or description
	Msg        string  `json:"msg"`               // Human-readable message based on label
}

CensorResult represents the detailed text moderation result

type QCloudTextCensor

type QCloudTextCensor struct {
	SecretID  string
	SecretKey string
	Region    string
	Client    *tms.Client
}

QCloudTextCensor is the client for Tencent Cloud text content moderation

func NewQCloudTextCensor

func NewQCloudTextCensor() (*QCloudTextCensor, error)

NewQCloudTextCensor creates a new Tencent Cloud text moderation client

func (*QCloudTextCensor) CensorText

func (c *QCloudTextCensor) CensorText(text string) (*CensorResult, error)

CensorText performs text content moderation Returns: CensorResult with suggestion, label, and score

type QiniuTextCensor

type QiniuTextCensor struct {
	AccessKey string
	SecretKey string
	Host      string
	Client    *http.Client
}

QiniuTextCensor is the client for text content moderation

func NewQiniuTextCensor

func NewQiniuTextCensor() (*QiniuTextCensor, error)

NewQiniuTextCensor creates a new text moderation client

func NewQiniuTextCensorWithCredentials

func NewQiniuTextCensorWithCredentials(accessKey, secretKey string) *QiniuTextCensor

NewQiniuTextCensorWithCredentials creates a new text moderation client with provided credentials

func (*QiniuTextCensor) Censor

Censor performs text content moderation

func (*QiniuTextCensor) CensorText

func (c *QiniuTextCensor) CensorText(text string) (*CensorResult, error)

CensorText is a convenience method to moderate text content text: text content to be moderated

type ServiceParameters

type ServiceParameters struct {
	Content string `json:"content"`
}

ServiceParameters represents the service parameters for text moderation

type TextCensor

type TextCensor interface {
	CensorText(text string) (*CensorResult, error)
}

func GetTextCensor

func GetTextCensor(kind string) (TextCensor, error)

type TextCensorData

type TextCensorData struct {
	Text string `json:"text"` // Text content
}

TextCensorData represents the text data to be moderated

type TextCensorParams

type TextCensorParams struct {
	Scenes []string `json:"scenes"` // Moderation type, required field, options: antispam
}

TextCensorParams represents moderation parameters

type TextCensorRequest

type TextCensorRequest struct {
	Data   TextCensorData   `json:"data"`
	Params TextCensorParams `json:"params"`
}

TextCensorRequest represents the request parameters for text moderation

type TextCensorResponse

type TextCensorResponse struct {
	Code    int               `json:"code"`    // Processing status: 200 means success
	Message string            `json:"message"` // Status description corresponding to code
	Result  *TextCensorResult `json:"result"`  // Moderation result
}

TextCensorResponse represents the text moderation response

type TextCensorResult

type TextCensorResult struct {
	Suggestion string                     `json:"suggestion"` // pass (approved), review (needs manual review), block (violation)
	Scenes     map[string]TextSceneResult `json:"scenes"`     // Moderation results for each scene
}

TextCensorResult represents the text moderation result

type TextSceneDetail

type TextSceneDetail struct {
	Label       string  `json:"label"`       // Moderation label: normal, spam, ad, politics, terrorism, abuse, porn, flood, contraband, meaningless
	Score       float64 `json:"score"`       // Confidence score
	Description string  `json:"description"` // Description of violation content
}

TextSceneDetail represents detailed moderation information for a scene

type TextSceneResult

type TextSceneResult struct {
	Suggestion string            `json:"suggestion"` // Overall suggestion for this scene: pass/review/block
	Details    []TextSceneDetail `json:"details"`    // Detailed information array
}

TextSceneResult represents the moderation result for a scene

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL