Skip to content

Commit

Permalink
feat: ALL_DIALOG_RECORD_ENABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
deanxv committed Jun 26, 2024
1 parent 43e3faf commit 03316ac
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Render 可以直接部署 docker 镜像,不需要 fork 仓库:[Render](https:/
| 变量参数 | 变量描述 | 是否必填 |
|:------------------:|:---------------------------------------------------:|:----:|
| AUDIT_CHANNEL_TYPE | 审核渠道类型[openai:openai、ali:阿里、baidu:百度、qiniu:七牛] | Y |
| ALL_DIALOG_RECORD_ENABLE | 全量上下文审核开关[0:关闭、1:打开](默认:0) | N |
| BASE_URL | 审核通过后的转发接口请求地址域名或IP:端口(例如: https://api.openai.com| Y |
| API_KEY | 鉴权密钥,与转发接口的API-Key保持一致,多个以`,`分隔 | Y |
| ENABLE | 审核启用开关[0:关闭、1:打开](默认:1) | N |
Expand Down
1 change: 1 addition & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var QiNiuAuditContentLength = env.Int("QINIU_AUDIT_CONTENT_LENGTH", 4000)
var OpenaiModerationBaseUrl = os.Getenv("OPENAI_MODERATION_BASE_URL")
var OpenaiModerationApiKey = os.Getenv("OPENAI_MODERATION_API_KEY")
var OpenaiModerationLabel = os.Getenv("OPENAI_MODERATION_LABEL")
var AllDialogRecordEnable = env.Int("ALL_DIALOG_RECORD_ENABLE", 0)
var OpenaiModerationAuditContentLength = env.Int("OPENAI_MODERATION_AUDIT_CONTENT_LENGTH", 4000)

var DebugEnabled = strings.ToLower(os.Getenv("DEBUG")) == "true"
Expand Down
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package common
import "time"

var StartTime = time.Now().Unix() // unit: second
var Version = "v1.0.1" // this hard coding will be replaced automatically when building, no need to manually change
var Version = "v1.0.2" // this hard coding will be replaced automatically when building, no need to manually change
Binary file modified docs/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions model/openai.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package model

import "gpt-content-audit/common/config"

type OpenAIChatCompletionRequest struct {
Model string `json:"model"`
Stream bool `json:"stream"`
Expand Down Expand Up @@ -95,12 +97,27 @@ type GetUserContent interface {

func (r OpenAIChatCompletionRequest) GetUserContent() []string {
var userContent []string
for _, msg := range r.Messages {
switch contentObj := msg.Content.(type) {
case string:
userContent = append(userContent, contentObj)
if config.AllDialogRecordEnable == 1 {
for _, msg := range r.Messages {
if msg.Role == "user" {
switch contentObj := msg.Content.(type) {
case string:
userContent = append(userContent, contentObj)
}
}
}
} else {
for i := len(r.Messages) - 1; i >= 0; i-- {
if r.Messages[i].Role == "user" {
switch contentObj := r.Messages[i].Content.(type) {
case string:
userContent = append(userContent, contentObj)
}
break
}
}
}

return userContent
}

Expand Down

0 comments on commit 03316ac

Please sign in to comment.