From 2fa28f70a6de71a953e74db0d817801d128183cb Mon Sep 17 00:00:00 2001 From: abc Date: Fri, 29 Dec 2023 10:44:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/chatgpt/service/chatgpt_session.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/chatgpt/service/chatgpt_session.go b/modules/chatgpt/service/chatgpt_session.go index a22be45..e3135a4 100644 --- a/modules/chatgpt/service/chatgpt_session.go +++ b/modules/chatgpt/service/chatgpt_session.go @@ -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"]) From 6b70eb4cf4b0b1a99d4e0bd1b938641af8613ba3 Mon Sep 17 00:00:00 2001 From: abc Date: Tue, 2 Jan 2024 02:48:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E7=94=B1=E4=BA=8E=E7=8B=AC?= =?UTF-8?q?=E7=AB=8B=E8=AE=A1=E8=B4=B9=EF=BC=8C=E6=89=80=E4=BB=A5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0gpt4-mobile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend-api/backend-api.go | 29 +++++++++++++++++++ config.yaml | 11 ++++--- .../template/WtU07IOQoMFgLEFUvpFfy/chat.html | 1 + .../WtU07IOQoMFgLEFUvpFfy/discovery.html | 1 + .../WtU07IOQoMFgLEFUvpFfy/editor.html | 1 + .../template/WtU07IOQoMFgLEFUvpFfy/g.html | 1 + .../template/WtU07IOQoMFgLEFUvpFfy/gc.html | 1 + .../template/WtU07IOQoMFgLEFUvpFfy/mine.html | 1 + .../template/WtU07IOQoMFgLEFUvpFfy/slug.html | 1 + 9 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 resource/template/WtU07IOQoMFgLEFUvpFfy/chat.html create mode 100644 resource/template/WtU07IOQoMFgLEFUvpFfy/discovery.html create mode 100644 resource/template/WtU07IOQoMFgLEFUvpFfy/editor.html create mode 100644 resource/template/WtU07IOQoMFgLEFUvpFfy/g.html create mode 100644 resource/template/WtU07IOQoMFgLEFUvpFfy/gc.html create mode 100644 resource/template/WtU07IOQoMFgLEFUvpFfy/mine.html create mode 100644 resource/template/WtU07IOQoMFgLEFUvpFfy/slug.html diff --git a/backend-api/backend-api.go b/backend-api/backend-api.go index 68a018a..fcedcd5 100644 --- a/backend-api/backend-api.go +++ b/backend-api/backend-api.go @@ -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 { @@ -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} diff --git a/config.yaml b/config.yaml index 8e862a9..907c3b6 100644 --- a/config.yaml +++ b/config.yaml @@ -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" # 数据库类型 @@ -33,7 +32,7 @@ redis: cool: address: "127.0.0.1:6379" db: 0 - + cool: autoMigrate: true eps: true @@ -62,5 +61,5 @@ CHATPROXY: "https://demo.xyhelper.cn" AUTHKEY: "xyhelper" ONLYTOKEN: false CDNHOST: "https://file.chatgpt.ggss.club" - -# 5a07e29c-31d8-4976-ba66-f183598587d9 \ No newline at end of file +ASSET_PREFIX: "https://cdn.chatgpt.ggss.club" +# 5a07e29c-31d8-4976-ba66-f183598587d9 diff --git a/resource/template/WtU07IOQoMFgLEFUvpFfy/chat.html b/resource/template/WtU07IOQoMFgLEFUvpFfy/chat.html new file mode 100644 index 0000000..94f5d78 --- /dev/null +++ b/resource/template/WtU07IOQoMFgLEFUvpFfy/chat.html @@ -0,0 +1 @@ +{{.envScript}}ChatGPT
\ No newline at end of file diff --git a/resource/template/WtU07IOQoMFgLEFUvpFfy/discovery.html b/resource/template/WtU07IOQoMFgLEFUvpFfy/discovery.html new file mode 100644 index 0000000..2cbb12a --- /dev/null +++ b/resource/template/WtU07IOQoMFgLEFUvpFfy/discovery.html @@ -0,0 +1 @@ +{{.envScript}}ChatGPT
\ No newline at end of file diff --git a/resource/template/WtU07IOQoMFgLEFUvpFfy/editor.html b/resource/template/WtU07IOQoMFgLEFUvpFfy/editor.html new file mode 100644 index 0000000..0ad9a3b --- /dev/null +++ b/resource/template/WtU07IOQoMFgLEFUvpFfy/editor.html @@ -0,0 +1 @@ +{{.envScript}}ChatGPT
\ No newline at end of file diff --git a/resource/template/WtU07IOQoMFgLEFUvpFfy/g.html b/resource/template/WtU07IOQoMFgLEFUvpFfy/g.html new file mode 100644 index 0000000..adda6bc --- /dev/null +++ b/resource/template/WtU07IOQoMFgLEFUvpFfy/g.html @@ -0,0 +1 @@ +{{.envScript}}ChatGPT
\ No newline at end of file diff --git a/resource/template/WtU07IOQoMFgLEFUvpFfy/gc.html b/resource/template/WtU07IOQoMFgLEFUvpFfy/gc.html new file mode 100644 index 0000000..b63d997 --- /dev/null +++ b/resource/template/WtU07IOQoMFgLEFUvpFfy/gc.html @@ -0,0 +1 @@ +{{.envScript}}ChatGPT
\ No newline at end of file diff --git a/resource/template/WtU07IOQoMFgLEFUvpFfy/mine.html b/resource/template/WtU07IOQoMFgLEFUvpFfy/mine.html new file mode 100644 index 0000000..2702f15 --- /dev/null +++ b/resource/template/WtU07IOQoMFgLEFUvpFfy/mine.html @@ -0,0 +1 @@ +{{.envScript}}ChatGPT
\ No newline at end of file diff --git a/resource/template/WtU07IOQoMFgLEFUvpFfy/slug.html b/resource/template/WtU07IOQoMFgLEFUvpFfy/slug.html new file mode 100644 index 0000000..94e2859 --- /dev/null +++ b/resource/template/WtU07IOQoMFgLEFUvpFfy/slug.html @@ -0,0 +1 @@ +{{.envScript}}ChatGPT
\ No newline at end of file