Skip to content

Commit

Permalink
Merge branch 'master' of github.com:liuhuapiaoyuan/chatgpt-mirror-server
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhuapiaoyuan committed Jan 6, 2024
2 parents 0583439 + 6b70eb4 commit 7af9852
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
29 changes: 29 additions & 0 deletions backend-api/backend-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ func ProxyAll(r *ghttp.Request) {
// 如果path 以 ‘backend-api/files’ startwith开头
isCreateConversation := strings.HasPrefix(path, "/backend-api/conversation/gen_title")
isShare := strings.HasPrefix(path, "/backend-api/share/creat")
isLoadModels := strings.HasPrefix(path, "/backend-api/models")

if isCreateConversation {
CreateConversation(ctx, userId, accessToken, r.UserAgent(), path)
} else if isLoadModels {
AttachGPT4Mobile(ctx, response)
} else if isShare {
originalBody, shouldReturn, returnValue := loadRespString(response)
if shouldReturn {
Expand Down Expand Up @@ -125,6 +128,32 @@ func ProxyAll(r *ghttp.Request) {

}

// 处理models 增加gpt-4-mobile
func AttachGPT4Mobile(ctx g.Ctx, response *http.Response) error {
// 提取 /backend-api/models
originalBody, shouldReturn, returnValue := loadRespString(response)
if shouldReturn {
return returnValue
}
modifiedBody := string(originalBody)
if strings.Contains(modifiedBody, "gpt-4") {
resJson := gjson.New(modifiedBody)
models := resJson.Get("models").Array()
newObject := gjson.New(`{"capabilities":{},"description":"Browsing, Advanced Data Analysis, and DALL·E are now built into GPT-4","enabled_tools":["tools","tools2"],"max_tokens":32767,"product_features":{"attachments":{"accepted_mime_types":["text/x-csharp","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/x-tex","text/x-typescript","text/plain","text/x-ruby","application/msword","text/x-php","text/x-c++","text/markdown","application/x-latext","text/x-c","text/javascript","text/html","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/json","text/x-java","application/pdf","text/x-script.python","text/x-sh"],"can_accept_all_mime_types":true,"image_mime_types":["image/jpeg","image/webp","image/gif","image/png"],"type":"retrieval"}},"slug":"gpt-4-mobile","tags":["confidential","gpt4","plus"],"title":"GPT4 (Mobile)"}`)
models = append(models, newObject)
resJson.Set("models", models)
modifiedBody = resJson.String()
}
// 将修改后的内容写回响应体
response.Body = io.NopCloser(bytes.NewBufferString(modifiedBody))
// 更新Content-Length
response.ContentLength = int64(len(modifiedBody))
response.Header.Set("Content-Length", strconv.Itoa(len(modifiedBody)))
// 删除Content-Encoding头部
response.Header.Del("Content-Encoding")
return nil
}

// 创建信息,接受参数 conversationId
func CreateConversation(ctx g.Ctx, userId int, AccessToken string, userAgent string, conversationPath string) {
// 提取 /backend-api/conversation/gen_title/{id}
Expand Down
11 changes: 5 additions & 6 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
server:
serverRoot: "resource/public"
clientMaxBodySize: 104857600 # 100MB in bytes 100*1024*1024
clientMaxBodySize: 104857600 # 100MB in bytes 100*1024*1024

logger:
path: "./data/logs/"
file: "{Y-m-d}.log"
level : "all"
level: "all"
stdout: true


database:
# default:
# type: "sqlite" # 数据库类型
Expand All @@ -33,7 +32,7 @@ redis:
cool:
address: "127.0.0.1:6379"
db: 0

cool:
autoMigrate: true
eps: true
Expand Down Expand Up @@ -62,5 +61,5 @@ CHATPROXY: "https://demo.xyhelper.cn"
AUTHKEY: "xyhelper"
ONLYTOKEN: false
CDNHOST: "https://file.chatgpt.ggss.club"

# 5a07e29c-31d8-4976-ba66-f183598587d9
ASSET_PREFIX: "https://cdn.chatgpt.ggss.club"
# 5a07e29c-31d8-4976-ba66-f183598587d9
3 changes: 2 additions & 1 deletion modules/chatgpt/service/chatgpt_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func (s *ChatgptSessionService) ModifyAfter(ctx g.Ctx, method string, param map[
return
}
// 如果是手工模式不用处理
if param["mode"] == 0 {
if param["mode"] != 0 {
g.Log().Debug(ctx, "手工模式不需要刷新")
return
}
officialSession := gjson.New(param["officialSession"])
Expand Down

0 comments on commit 7af9852

Please sign in to comment.