[feat] ai-security-guard support checking prompt and image in request body (#3206)

This commit is contained in:
rinfx
2025-12-22 09:36:49 +08:00
committed by GitHub
parent f4905cbba7
commit e1e8e55c83
6 changed files with 494 additions and 18 deletions

View File

@@ -17,13 +17,13 @@ import (
"github.com/tidwall/gjson"
)
type ImageItemForOpenAI struct {
type ImageItem struct {
Content string
Type string // URL or BASE64
}
func parseContent(json gjson.Result) (text string, images []ImageItemForOpenAI) {
images = []ImageItemForOpenAI{}
func parseContent(json gjson.Result) (text string, images []ImageItem) {
images = []ImageItem{}
if json.IsArray() {
for _, item := range json.Array() {
switch item.Get("type").String() {
@@ -32,12 +32,12 @@ func parseContent(json gjson.Result) (text string, images []ImageItemForOpenAI)
case "image_url":
imgContent := item.Get("image_url.url").String()
if strings.HasPrefix(imgContent, "data:image") {
images = append(images, ImageItemForOpenAI{
images = append(images, ImageItem{
Content: imgContent,
Type: "BASE64",
})
} else {
images = append(images, ImageItemForOpenAI{
images = append(images, ImageItem{
Content: imgContent,
Type: "URL",
})