Documentation ¶
Index ¶
- Constants
- Variables
- func ContainsContentType(contentType string) bool
- func ContentExtractFromJSONDATA(data string, datatype DATATYPE) (string, bool)
- func FileExists(path string) bool
- func RequestBodyExtract(data string) (string, bool)
- func ResponseBodyExtract(data string) (string, bool)
- type Config
- type DATATYPE
- type LLMGuardOutputRequest
- type LLMGuardPromptRequest
- type LLMGuardRequest
- type LLMGuardResponse
- type LLMPath
- type LlmGuard
- type Scanner
- type ScannersResult
Constants ¶
View Source
const ( REQAPIPATH = "/scan/prompt" RESAPIPATH = "/scan/output" )
Variables ¶
View Source
var ( CONFIGPATH = "llmcontentpath.json" //配置各大模型API框架支持的content-type ContentTypes = []string{ "application/json", "application/x-ndjson", "application/x-www-form-urlencoded", } MaxIdleConns = 10000 MaxIdleConnsPerHost = 10000 LlmGuardClient *LlmGuard )
配置相关变量
View Source
var RequestPaths []string
记录全部LLM框架接口的问题和答案的json路径
View Source
var ResponsePaths []string
View Source
var Scanner_List = []Scanner{ Anonymize, BanCode, BanCompetitors, BanSubstrings, BanTopics, Code, Gibberish, InvisibleText, Language, PromptInjection, Regex, Secrets, Sentiment, TokenLimit, Toxicity, Bias, Deanonymize, FactualConsistency, JSON, LanguageSame, MaliciousURLs, NoRefusal, ReadingTime, Relevance, Sensitive, }
Functions ¶
func ContainsContentType ¶
func ContentExtractFromJSONDATA ¶
从给定的字符串中提取请求或者应答数据,如果提取不到,返回""和false, 如果提取到内容返回对应的内容和true
func FileExists ¶
func RequestBodyExtract ¶
func ResponseBodyExtract ¶
输入json结构体字符串,然后从中提取符合支持的大模型回答json结构体里的答案
Types ¶
type LLMGuardOutputRequest ¶
type LLMGuardOutputRequest struct { Prompt string `json:"prompt"` Output string `json:"output"` Scanners_Suppress []Scanner `json:"scanners_suppress"` }
func (*LLMGuardOutputRequest) AddScannerSuppress ¶
func (lor *LLMGuardOutputRequest) AddScannerSuppress(scanner Scanner)
func (*LLMGuardOutputRequest) RemoveFromScannerList ¶
func (lor *LLMGuardOutputRequest) RemoveFromScannerList(scanner Scanner)
func (*LLMGuardOutputRequest) RemoveScanner ¶ added in v3.0.2
func (lor *LLMGuardOutputRequest) RemoveScanner(scanner Scanner)
type LLMGuardPromptRequest ¶
type LLMGuardPromptRequest struct { Prompt string `json:"prompt"` Scanners_Suppress []Scanner `json:"scanners_suppress"` }
func (*LLMGuardPromptRequest) AddScannerSuppress ¶
func (lpr *LLMGuardPromptRequest) AddScannerSuppress(scanner Scanner)
func (*LLMGuardPromptRequest) RemoveFromScannerList ¶
func (lpr *LLMGuardPromptRequest) RemoveFromScannerList(scanner Scanner)
func (*LLMGuardPromptRequest) RemoveScanner ¶
func (lpr *LLMGuardPromptRequest) RemoveScanner(scanner Scanner)
type LLMGuardRequest ¶
type LLMGuardResponse ¶
type LLMGuardResponse struct { IsValid bool `json:"is_valid"` Scanners ScannersResult `json:"scanners"` SanitizedPrompt string `json:"sanitized_prompt,omitempty"` }
func LLMguardScanWithTransport ¶
func LLMguardScanWithTransport(url string, data LLMGuardRequest) (*LLMGuardResponse, error)
func (*LLMGuardResponse) Valid ¶
func (l *LLMGuardResponse) Valid() bool
type Scanner ¶
type Scanner string
var ( Anonymize Scanner = "Anonymize" BanCode Scanner = "Bancode" BanCompetitors Scanner = "BanCompetitors" BanSubstrings Scanner = "BanSubstrings" BanTopics Scanner = "BanTopics" Code Scanner = "Code" Gibberish Scanner = "Gibberish" InvisibleText Scanner = "InvisibleText" Language Scanner = "Language" PromptInjection Scanner = "PromptInjection" Regex Scanner = "Regex" Secrets Scanner = "Secrets" Sentiment Scanner = "Sentiment" TokenLimit Scanner = "TokenLimit" Toxicity Scanner = "Toxicity" Bias Scanner = "Bias" Deanonymize Scanner = "Deanonymize" FactualConsistency Scanner = "FactualConsistency" JSON Scanner = "JSON" LanguageSame Scanner = "LanguageSame" MaliciousURLs Scanner = "MaliciousURLs" NoRefusal Scanner = "NoRefusal" ReadingTime Scanner = "ReadingTime" Relevance Scanner = "Relevance" Sensitive Scanner = "Sensitive" )
func RemoveFromScannerList ¶
type ScannersResult ¶
type ScannersResult struct { Anonymize float32 `json:"Anonymize,omitempty"` BanCode float32 `json:"BanCode,omitempty"` BanCompetitors float32 `json:"BanCompetitors,omitempty"` BanSubstrings float32 `json:"BanSubstrings,omitempty"` BanTopics float32 `json:"BanTopics,omitempty"` Code float32 `json:"Code,omitempty"` Gibberish float32 `json:"Gibberish,omitempty"` InvisibleText float32 `json:"InvisibleText,omitempty"` Language float32 `json:"Language,omitempty"` PromptInjection float32 `json:"PromptInjection,omitempty"` Regex float32 `json:"Regex,omitempty"` Secrets float32 `json:"Secrets,omitempty"` Sentiment float32 `json:"Sentiment,omitempty"` TokenLimit float32 `json:"TokenLimit,omitempty"` Toxicity float32 `json:"Toxicity,omitempty"` Bias float32 `json:"Bias,omitempty"` Deanonymize float32 `json:"Deanonymize,omitempty"` FactualConsistency float32 `json:"FactualConsistency,omitempty"` JSON float32 `json:"JSON,omitempty"` LanguageSame float32 `json:"LanguageSame,omitempty"` MaliciousURLs float32 `json:"MaliciousURLs,omitempty"` NoRefusal float32 `json:"NoRefusal,omitempty"` ReadingTime float32 `json:"ReadingTime,omitempty"` Relevance float32 `json:"Relevance,omitempty"` Sensitive float32 `json:"Sensitive,omitempty"` }
func DetectAnswer ¶ added in v3.0.2
func DetectAnswer(req string, ans string) (bool, ScannersResult)
TODO 对外提供大模型检测接口,检测回答的内容
func DetectQuestion ¶
func DetectQuestion(reqBody string) (bool, ScannersResult)
对外提供大模型检测调用接口,用于请求体检测
Click to show internal directories.
Click to hide internal directories.