Skip to content

Commit

Permalink
feat: remove check in openai mode api
Browse files Browse the repository at this point in the history
  • Loading branch information
JingYiJun committed Apr 1, 2024
1 parent 8569faa commit 27d0cd0
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 108 deletions.
32 changes: 17 additions & 15 deletions apis/record/openai.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package record

import (
"slices"
"time"

"github.com/gofiber/fiber/v2"
"github.com/google/uuid"

"MOSS_backend/config"
. "MOSS_backend/models"
. "MOSS_backend/utils"
"MOSS_backend/utils/sensitive"
)

// OpenAIListModels
Expand Down Expand Up @@ -73,31 +70,36 @@ func OpenAICreateChatCompletion(c *fiber.Ctx) (err error) {
//}

// infer limiter
if !inferLimiter.Allow() {
return unknownError
}
//if !inferLimiter.Allow() {
// return unknownError
//}

consumerUsername := c.Get("X-Consumer-Username")
passSensitiveCheck := slices.Contains(config.Config.PassSensitiveCheckUsername, consumerUsername)
//consumerUsername := c.Get("X-Consumer-Username")
//passSensitiveCheck := slices.Contains(config.Config.PassSensitiveCheckUsername, consumerUsername)

if !passSensitiveCheck && sensitive.IsSensitive(prefix+"\n"+requestMessage, &User{}) {
return BadRequest(DefaultResponse).WithMessageType(Sensitive)
}
//if !passSensitiveCheck && sensitive.IsSensitive(prefix+"\n"+requestMessage, &User{}) {
// return BadRequest(DefaultResponse).WithMessageType(Sensitive)
//}

recordModels, _, err := request.Messages.BuildRecordModels()
if err != nil {
return err
}

record := Record{Request: requestMessage}
err = Infer(&record, prefix, recordModels, &User{PluginConfig: nil, ModelID: modelConfig.ID}, nil)
err = Infer(&record, prefix, recordModels, &User{
PluginConfig: nil,
ModelID: modelConfig.ID,
IsAdmin: true,
DisableSensitiveCheck: true,
}, nil)
if err != nil {
return err
}

if !passSensitiveCheck && sensitive.IsSensitive(record.Response, &User{}) {
return BadRequest(DefaultResponse).WithMessageType(Sensitive)
}
//if !passSensitiveCheck && sensitive.IsSensitive(record.Response, &User{}) {
// return BadRequest(DefaultResponse).WithMessageType(Sensitive)
//}

return c.JSON(&OpenAIChatCompletionResponse{
Id: "chatcmpl-" + uuid.Must(uuid.NewUUID()).String(),
Expand Down
61 changes: 31 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,50 @@ require (
github.com/eko/gocache/lib/v4 v4.1.5
github.com/eko/gocache/store/go_cache/v4 v4.2.1
github.com/eko/gocache/store/redis/v4 v4.2.1
github.com/go-playground/validator/v10 v10.17.0
github.com/gofiber/fiber/v2 v2.52.0
github.com/go-playground/validator/v10 v10.19.0
github.com/gofiber/fiber/v2 v2.52.4
github.com/gofiber/swagger v1.0.0
github.com/gofiber/websocket/v2 v2.2.1
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/uuid v1.6.0
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20231013030745-3066d243cd04
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20240322081424-40c7f53fc97c
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.18.0
github.com/redis/go-redis/v9 v9.4.0
github.com/prometheus/client_golang v1.19.0
github.com/redis/go-redis/v9 v9.5.1
github.com/robfig/cron/v3 v3.0.1
github.com/sashabaranov/go-openai v1.19.3
github.com/sashabaranov/go-openai v1.20.4
github.com/swaggo/swag v1.16.3
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.857
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.857
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.890
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.890
github.com/vmihailenco/msgpack/v5 v5.4.1
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.19.0
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.21.0
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
golang.org/x/time v0.5.0
gorm.io/driver/mysql v1.5.4
gorm.io/driver/mysql v1.5.6
gorm.io/driver/sqlite v1.5.5
gorm.io/gorm v1.25.7
gorm.io/gorm v1.25.9
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chromedp/cdproto v0.0.0-20240202021202-6d0b6a386732 // indirect
github.com/chromedp/cdproto v0.0.0-20240328024531-fe04f09ede24 // indirect
github.com/chromedp/sysutil v1.0.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fasthttp/websocket v1.5.7 // indirect
github.com/fasthttp/websocket v1.5.8 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/spec v0.20.14 // indirect
github.com/go-openapi/swag v0.22.9 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.3.2 // indirect
Expand All @@ -62,28 +63,28 @@ require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.51.1 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/fasthttp v1.52.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 27d0cd0

Please sign in to comment.