Skip to content

Commit

Permalink
Merge pull request #46 from byebyebruce/main
Browse files Browse the repository at this point in the history
增加http basic auth & doc
  • Loading branch information
869413421 authored Mar 6, 2023
2 parents c0ca7a4 + 0262ef3 commit 0d010c6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ $ docker run -itd --name chatgpt-web --restart=always \
-e FREQ=0.0 \
-e PRES=0.6 \
-e PROXY=http://host.docker.internal:10809 \
-e AUTH_USER= \
-e AUTH_PASSWORD= \
-p 8080:8080 \
qingshui869413421/chatgpt-web:latest
```
Expand Down Expand Up @@ -125,7 +127,9 @@ $ docker run -itd --name chatgpt-web -v `pwd`/config.json:/app/config.json -p 80
"temperature": 0.9,
"top_p": 1,
"frequency_penalty": 0.0,
"presence_penalty": 0.6
"presence_penalty": 0.6,
"auth_user": "",
"auth_password": ""
}
api_key:openai api_key
Expand All @@ -138,6 +142,8 @@ temperature: GPT热度,0到1,默认0.9。数字越大创造力越强,但
top_p: 使用温度采样的替代方法称为核心采样,其中模型考虑具有top_p概率质量的令牌的结果。因此,0.1 意味着只考虑包含前 10% 概率质量的代币。
frequency_penalty:
presence_penalty:
auth_user": http基本认证用户名(空表示不开启验证)
auth_password": http基本认证密码
````

# 免责声明 Disclaimers
Expand Down
4 changes: 3 additions & 1 deletion config.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
"temperature": 0.9,
"top_p": 1,
"frequency_penalty": 0.0,
"presence_penalty": 0.6
"presence_penalty": 0.6,
"auth_user": "",
"auth_password": ""
}
14 changes: 13 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package config
import (
"encoding/json"
"fmt"
"github.com/869413421/chatgpt-web/pkg/logger"
"log"
"os"
"strconv"
"sync"

"github.com/869413421/chatgpt-web/pkg/logger"
)

// Configuration 项目配置
Expand All @@ -29,6 +30,8 @@ type Configuration struct {
TopP float32 `json:"top_p"`
PresencePenalty float32 `json:"presence_penalty"`
FrequencyPenalty float32 `json:"frequency_penalty"`
AuthUser string `json:"auth_user"` // 账号,默认空不验证
AuthPassword string `json:"auth_password"` // 密码
}

var config *Configuration
Expand Down Expand Up @@ -74,6 +77,8 @@ func LoadConfig() *Configuration {
PresencePenalty := os.Getenv("PRES")
BotDesc := os.Getenv("BOT_DESC")
Proxy := os.Getenv("PROXY")
AuthUser := os.Getenv("AUTH_USER")
AuthPassword := os.Getenv("AUTH_PASSWORD")
if ApiKey != "" {
config.ApiKey = ApiKey
}
Expand Down Expand Up @@ -129,6 +134,13 @@ func LoadConfig() *Configuration {
}
config.PresencePenalty = float32(temp)
}
if AuthUser != "" {
config.AuthUser = AuthUser
}

if AuthPassword != "" {
config.AuthPassword = AuthPassword
}
})
if config.ApiKey == "" {
logger.Danger("config err: api key required")
Expand Down
9 changes: 9 additions & 0 deletions routes/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ package routes
import (
. "github.com/869413421/chatgpt-web/app/http/controllers"
"github.com/869413421/chatgpt-web/app/middlewares"
"github.com/869413421/chatgpt-web/config"
"github.com/gin-gonic/gin"
)

var chatController = NewChatController()

// RegisterWebRoutes 注册路由
func RegisterWebRoutes(router *gin.Engine) {

router.Use(middlewares.Cors())

cnf := config.LoadConfig()
if len(cnf.AuthUser) > 0 {
gin.BasicAuth(gin.Accounts{
cnf.AuthUser: cnf.AuthPassword,
})
}
router.GET("/", chatController.Index)
router.POST("/completion", chatController.Completion)
}

0 comments on commit 0d010c6

Please sign in to comment.