From 2a38be371f4055dda639d7853e1f253d7fe32d86 Mon Sep 17 00:00:00 2001 From: liuhuapiaoyuan <278780765@qq.com> Date: Tue, 14 May 2024 17:55:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=99=AE=E5=8F=B7=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E6=89=93=E5=BC=80gpt-4o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend-api/backend-api.go | 183 ++++++++++++++++++++++++++++++++----- backend-api/me.go | 15 --- config.yaml | 2 +- 3 files changed, 160 insertions(+), 40 deletions(-) diff --git a/backend-api/backend-api.go b/backend-api/backend-api.go index 9c6b5ef..6a375a3 100644 --- a/backend-api/backend-api.go +++ b/backend-api/backend-api.go @@ -200,7 +200,7 @@ func ProxyAll(r *ghttp.Request) { if isCreateConversation { CreateConversation(r, userId, chatgptId, userToken, r.UserAgent(), path) } else if isLoadModels { - //AttachGPT4Mobile(ctx, response) + AttachGPT4O(ctx, response) } else if isShare { originalBody, shouldReturn, returnValue := loadRespString(response) if shouldReturn { @@ -250,35 +250,170 @@ func ProxyAll(r *ghttp.Request) { } -// 处理models 增加gpt-4-mobile -func AttachGPT4Mobile(ctx g.Ctx, response *http.Response) error { +// 处理models 增加gpt-4O +func AttachGPT4O(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) - - categories := resJson.Get("categories").Array() - - categories = append(categories, gjson.New(`{ - "category": "gpt_4", - "human_category_name": "GPT-4", - "subscription_level": "plus", - "default_model": "gpt-4", - "browsing_model": "gpt-4-browsing", - "code_interpreter_model": "gpt-4-code-interpreter", - "plugins_model": "gpt-4-plugins" - }`)) - resJson.Set("categories", categories) - modifiedBody = resJson.String() + if !strings.Contains(modifiedBody, "gpt-4") { + modifiedBody = `{ + "models": [ + { + "slug": "text-davinci-002-render-sha", + "max_tokens": 8191, + "title": "Default (GPT-3.5)", + "description": "我们最快的模型,非常适合大多数日常任务。", + "tags": [ + "gpt3.5" + ], + "capabilities": {}, + "product_features": {} + }, + { + "slug": "gpt-4o", + "max_tokens": 8192, + "title": "Scallion", + "description": "浏览、高级数据分析和 DALL·E 现已集成到 GPT-4 中", + "tags": [ + "confidential", + "gpt4" + ], + "capabilities": {}, + "product_features": { + "attachments": { + "type": "retrieval", + "accepted_mime_types": [ + "text/x-java", + "application/x-latext", + "text/javascript", + "text/x-script.python", + "application/pdf", + "text/html", + "text/x-php", + "text/x-c", + "text/x-csharp", + "application/vnd.openxmlformats-officedocument.presentationml.presentation", + "text/x-tex", + "application/json", + "text/plain", + "application/msword", + "text/x-ruby", + "text/markdown", + "text/x-sh", + "text/x-typescript", + "text/x-c++", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document" + ], + "image_mime_types": [ + "image/jpeg", + "image/gif", + "image/webp", + "image/png" + ], + "can_accept_all_mime_types": true + } + }, + "enabled_tools": [ + "tools", + "tools2" + ] + }, + { + "slug": "auto", + "max_tokens": 8192, + "title": "Dynamic", + "description": "使用合适的模型来满足我的请求", + "tags": [ + "confidential", + "gpt4" + ], + "capabilities": {}, + "product_features": { + "attachments": { + "type": "retrieval", + "accepted_mime_types": [ + "text/x-java", + "application/x-latext", + "text/javascript", + "text/x-script.python", + "application/pdf", + "text/html", + "text/x-php", + "text/x-c", + "text/x-csharp", + "application/vnd.openxmlformats-officedocument.presentationml.presentation", + "text/x-tex", + "application/json", + "text/plain", + "application/msword", + "text/x-ruby", + "text/markdown", + "text/x-sh", + "text/x-typescript", + "text/x-c++", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document" + ], + "image_mime_types": [ + "image/jpeg", + "image/gif", + "image/webp", + "image/png" + ], + "can_accept_all_mime_types": true + } + }, + "enabled_tools": [ + "tools", + "tools2" + ] + } + ], + "categories": [ + { + "category": "gpt_3.5", + "human_category_name": "GPT-3.5", + "human_category_short_name": "3.5", + "icon": "bolt", + "icon_src": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMi41NjU1IDIuMTEwN0MxMy41Njg2IDAuOTIxNiAxNS40OTU2IDEuODU3NjEgMTUuMTgxIDMuMzgxMjJMMTQuMjI3NCA4LjAwMDAzSDE5LjkyMzlDMjEuMTk5OSA4LjAwMDAzIDIxLjg5MzIgOS40OTE5NyAyMS4wNzA0IDEwLjQ2NzNMMTEuNDM0MyAyMS44ODk0QzEwLjQzMTEgMjMuMDc4NSA4LjUwNDI0IDIyLjE0MjUgOC44MTg3OSAyMC42MTg5TDkuNzcyMzYgMTZINC4wNzU4OEMyLjc5OTg3IDE2IDIuMTA2NTggMTQuNTA4MSAyLjkyOTM4IDEzLjUzMjhMMTIuNTY1NSAyLjExMDdaIiBmaWxsPSIjMjgyODI4Ii8+Cjwvc3ZnPgo=", + "subscription_level": "free", + "default_model": "text-davinci-002-render-sha", + "code_interpreter_model": "text-davinci-002-render-sha-code-interpreter", + "plugins_model": "text-davinci-002-render-sha-plugins", + "color": "#47C761", + "short_explainer": "非常适合用于日常任务", + "tagline": "最快速" + }, + { + "category": "AG8PqS2q", + "human_category_name": "GPT-4o", + "human_category_short_name": "4o", + "icon": "stars", + "icon_src": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTE5LjkxOTQgMC44OTY4ODhDMTkuODkzOCAwLjY3MDk5NCAxOS43MDI4IDAuNTAwMjMgMTkuNDc1NSAwLjVDMTkuMjQ4MSAwLjQ5OTc3IDE5LjA1NjcgMC42NzAxMzEgMTkuMDMwOCAwLjg5NTk4QzE4LjkwOTQgMS45NDc0IDE4LjU5NzIgMi42Njg3MiAxOC4xMDggMy4xNTc5NkMxNy42MTg3IDMuNjQ3MjEgMTYuODk3NCAzLjk1OTQ1IDE1Ljg0NTkgNC4wODA3MkMxNS42MjAxIDQuMTA2NzcgMTUuNDQ5OCA0LjI5ODEyIDE1LjQ1IDQuNTI1NDZDMTUuNDUwMiA0Ljc1MjggMTUuNjIxIDQuOTQzOCAxNS44NDY5IDQuOTY5MzhDMTYuODgwNSA1LjA4NjQ2IDE3LjYxODMgNS4zOTg2NCAxOC4xMiA1Ljg5MTI1QzE4LjYxODkgNi4zODExOCAxOC45MzcgNy4xMDE0NyAxOS4wMjk1IDguMTQyMzVDMTkuMDUwMSA4LjM3MzI5IDE5LjI0MzYgOC41NTAyNiAxOS40NzU1IDguNTVDMTkuNzA3MyA4LjU0OTc0IDE5LjkwMDYgOC4zNzIzNCAxOS45MjA1IDguMTQxM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zMSAxMS45OTU3IDIyLjQ0OTFDMTIuMjIzNCAxOS44MTc4IDEzLjA0MSAxNy45MjQgMTQuMzMyNCAxNi42MzI0QzE1LjYyNCAxNS4zNDEgMTcuNTE3OCAxNC41MjM0IDIwLjE0OTEgMTQuMjk1N0MyMC43NDMxIDE0LjI0NDMgMjEuMTk5MyAxMy43NDc1IDIxLjIgMTMuMTUxM0MyMS4yMDA3IDEyLjU1NTEgMjAuNzQ1NiAxMi4wNTczIDIwLjE1MTggMTIuMDA0NUMxNy40NzUxIDExLjc2NjggMTUuNjIzMSAxMC45NDg3IDE0LjM2MzMgOS42NjU1OUMxMy4wOTY1IDguMzc1NTUgMTIuMjkzNyA2LjQ3ODUyIDExLjk5MjYgMy44MjA1N1oiIGZpbGw9IiMyODI4MjgiLz4KPC9zdmc+Cg==", + "subscription_level": "plus", + "default_model": "gpt-4o", + "color": "#5B41F9", + "short_explainer": "Newest and most advanced model", + "tagline": "智能且快速" + }, + { + "category": "auto", + "human_category_name": "Dynamic", + "human_category_short_name": "", + "icon": "connected", + "icon_src": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgZmlsbD0ibm9uZSIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJjdXJyZW50Q29sb3IiIGZpbGwtcnVsZT0iZXZlbm9kZCIgZD0iTTEyIDcuNDJhMjIgMjIgMCAwIDAtMi40NTMgMi4xMjdBMjIgMjIgMCAwIDAgNy40MiAxMmEyMiAyMiAwIDAgMCAyLjEyNyAyLjQ1M2MuODA3LjgwOCAxLjYzNiAxLjUyIDIuNDUzIDIuMTI4YTIyIDIyIDAgMCAwIDIuNDUzLTIuMTI4QTIyIDIyIDAgMCAwIDE2LjU4IDEyYTIyIDIyIDAgMCAwLTIuMTI3LTIuNDUzQTIyIDIyIDAgMCAwIDEyIDcuNDJtMS43NTEtMS4xNT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bGU9ImV2ZW5vZGQiPjwvcGF0aD48L3N2Zz4=", + "subscription_level": "free", + "default_model": "auto", + "plugins_model": "gpt-4-plugins", + "color": "", + "short_explainer": "为改善速度和智能程度而进行了优化。", + "tagline": "" + } + ] + }` + } // 将修改后的内容写回响应体 response.Body = io.NopCloser(bytes.NewBufferString(modifiedBody)) // 更新Content-Length diff --git a/backend-api/me.go b/backend-api/me.go index d94868d..8b54e18 100644 --- a/backend-api/me.go +++ b/backend-api/me.go @@ -20,25 +20,10 @@ func Me(r *ghttp.Request) { return } resStr, err := ProxyRequestGet("/backend-api/me", r) - - // UpStream := config.CHATPROXY - // // 请求后端接口 - // res, err := g.Client().SetHeaderMap(map[string]string{ - // "Authorization": "Bearer " + AccessToken, - // "User-Agent": r.Header.Get("User-Agent"), - // "authKey": config.AUTHKEY(ctx), - // }).Get(ctx, UpStream+"/backend-api/me") if err != nil { r.Response.WriteStatus(http.StatusUnauthorized) return } - // resStr := res.ReadAllString() - // if res.StatusCode != http.StatusOK { - // r.Response.Status = res.StatusCode - // r.Response.Write(resStr) - - // return - // } resJson := gjson.New(resStr) resJson.Set("email", "admin@closeai.com") resJson.Set("name", record["user_username"].String()+expireTime) diff --git a/config.yaml b/config.yaml index 59496c9..5faf7dc 100644 --- a/config.yaml +++ b/config.yaml @@ -55,7 +55,7 @@ modules: enable: 1 # 接入网关地址 -# CHATPROXY: "https://chat.openai.com" +CHATPROXY: "https://chat.openai.com" JA3_PROXY: "http://a:b@host.docker.internal:9988" #CHATPROXY: "http://host.docker.internal:7999" #CHATPROXY: "https://chatgpt.ggss.club/gateway"