diff --git a/conversion/requests/chatgpt/convert.go b/conversion/requests/chatgpt/convert.go index 27e0b32b..b6da5446 100644 --- a/conversion/requests/chatgpt/convert.go +++ b/conversion/requests/chatgpt/convert.go @@ -14,9 +14,6 @@ import ( func ConvertAPIRequest(api_request official_types.APIRequest, secret *tokens.Secret, requireArk bool, proxy string) chatgpt_types.ChatGPTRequest { chatgpt_request := chatgpt_types.NewChatGPTRequest() var api_version int - if secret.PUID == "" { - api_request.Model = "gpt-3.5" - } if strings.HasPrefix(api_request.Model, "gpt-3.5") { api_version = 3 chatgpt_request.Model = "text-davinci-002-render-sha" @@ -24,6 +21,9 @@ func ConvertAPIRequest(api_request official_types.APIRequest, secret *tokens.Sec api_version = 4 chatgpt_request.Model = api_request.Model // Cover some models like gpt-4-32k + if api_request.Model == "gpt-4o" { + chatgpt_request.Model = "gpt-4o" + } if len(api_request.Model) >= 7 && api_request.Model[6] >= 48 && api_request.Model[6] <= 57 { chatgpt_request.Model = "gpt-4" } diff --git a/go.mod b/go.mod index 59536267..75649158 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.21 require ( github.com/EDDYCJY/fake-useragent v0.2.0 + github.com/PuerkitoBio/goquery v1.9.1 github.com/acheong08/endless v0.0.0-20230615162514-90545c7793fd github.com/bogdanfinn/fhttp v0.5.27 github.com/bogdanfinn/tls-client v1.7.2 @@ -14,10 +15,10 @@ require ( github.com/joho/godotenv v1.5.1 github.com/pkoukk/tiktoken-go v0.1.6 github.com/xqdoo00o/funcaptcha v0.0.0-20240403090732-1b604d808f6c + golang.org/x/crypto v0.21.0 ) require ( - github.com/PuerkitoBio/goquery v1.9.1 // indirect github.com/andybalholm/brotli v1.0.5 // indirect github.com/andybalholm/cascadia v1.3.2 // indirect github.com/bogdanfinn/utls v1.6.1 // indirect @@ -47,7 +48,6 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect golang.org/x/arch v0.5.0 // indirect - golang.org/x/crypto v0.21.0 // indirect golang.org/x/net v0.22.0 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/httpclient/Iaurorahttpclient.go b/httpclient/Iaurorahttpclient.go index 91f3beb8..412dc406 100644 --- a/httpclient/Iaurorahttpclient.go +++ b/httpclient/Iaurorahttpclient.go @@ -8,6 +8,8 @@ import ( type AuroraHttpClient interface { Request(method HttpMethod, url string, headers AuroraHeaders, cookies []*http.Cookie, body io.Reader) (*http.Response, error) SetProxy(url string) error + SetCookies(rawUrl string, cookies []*http.Cookie) + GetCookies(rawUrl string) []*http.Cookie } type HttpMethod string diff --git a/httpclient/bogdanfinn/tls_client.go b/httpclient/bogdanfinn/tls_client.go index 917b1561..a96b9622 100644 --- a/httpclient/bogdanfinn/tls_client.go +++ b/httpclient/bogdanfinn/tls_client.go @@ -22,7 +22,7 @@ func NewStdClient() *TlsClient { client, _ := tls_client.NewHttpClient(tls_client.NewNoopLogger(), []tls_client.HttpClientOption{ tls_client.WithCookieJar(tls_client.NewCookieJar()), tls_client.WithTimeoutSeconds(600), - tls_client.WithClientProfile(profiles.Safari_15_6_1), + tls_client.WithClientProfile(profiles.Chrome_117), }...) stdClient := &TlsClient{Client: client} @@ -128,3 +128,28 @@ func (t *TlsClient) SetCookies(rawUrl string, cookies []*http.Cookie) { } t.Client.GetCookieJar().SetCookies(u, fcookies) } + +func (t *TlsClient) GetCookies(rawUrl string) []*http.Cookie { + currUrl, err := url.Parse(rawUrl) + if err != nil { + return nil + } + + var cookies []*http.Cookie + for _, c := range t.Client.GetCookies(currUrl) { + cookies = append(cookies, &http.Cookie{ + Name: c.Name, + Value: c.Value, + Path: c.Path, + Domain: c.Domain, + Expires: c.Expires, + RawExpires: c.RawExpires, + MaxAge: c.MaxAge, + Secure: c.Secure, + HttpOnly: c.HttpOnly, + SameSite: http.SameSite(c.SameSite), + }) + } + return cookies +} + diff --git a/initialize/handlers.go b/initialize/handlers.go index 7cc37f84..d516554e 100644 --- a/initialize/handlers.go +++ b/initialize/handlers.go @@ -301,15 +301,6 @@ func (h *Handler) engines(c *gin.Context) { Object: "list", } var resModelList []ResData - if len(resp.Models) > 2 { - res_data := ResData{ - ID: "gpt-4-mobile", - Object: "model", - Created: 1685474247, - OwnedBy: "openai", - } - resModelList = append(resModelList, res_data) - } for _, model := range resp.Models { res_data := ResData{ ID: model.Slug, diff --git a/internal/chatgpt/request.go b/internal/chatgpt/request.go index 01763cde..1d6691cf 100644 --- a/internal/chatgpt/request.go +++ b/internal/chatgpt/request.go @@ -77,6 +77,7 @@ var ( func GetDpl(client httpclient.AuroraHttpClient, proxy string) { requestURL := strings.Replace(BaseURL, "/backend-anon", "", 1) + "/?oai-dm=1" + if len(cachedScripts) > 0 { return } @@ -85,6 +86,7 @@ func GetDpl(client httpclient.AuroraHttpClient, proxy string) { } header := createBaseHeader() response, err := client.Request(http.MethodGet, requestURL, header, nil, nil) + if err != nil { return } @@ -104,10 +106,13 @@ func GetDpl(client httpclient.AuroraHttpClient, proxy string) { } }) if BasicCookies == nil { - for _, cookie := range response.Cookies() { + for _, cookie := range client.GetCookies("https://chatgpt.com") { if cookie.Name == "oai-did" { continue } + if cookie.Name == "__Secure-next-auth.callback-url" { + cookie.Value = "https://chatgpt.com" + } BasicCookies = append(BasicCookies, cookie) } } @@ -277,7 +282,8 @@ func getParseTime() string { func getConfig() []interface{} { rand.New(rand.NewSource(time.Now().UnixNano())) script := cachedScripts[rand.Intn(len(cachedScripts))] - return []interface{}{cachedHardware, getParseTime(), int64(4294705152), 0, userAgent, script, cachedDpl, "zh-CN", "zh-CN,en,en-GB,en-US", 0} + + return []interface{}{cachedHardware, getParseTime(), int64(4294705152), 0, userAgent, script, cachedDpl, "zh-CN", "zh-CN,en,en-GB,en-US", 0, "userAgentData−[object NavigatorUAData]", "_reactListening4pw0k9ttxw", "onpopstate"} } func CalcProofToken(client httpclient.AuroraHttpClient, require *ChatRequire, proxy string) string { @@ -952,11 +958,13 @@ func createBaseHeader() httpclient.AuroraHeaders { header.Set("origin", "https://chatgpt.com") header.Set("referer", "https://chatgpt.com/") header.Set("sec-ch-ua", `"Google Chrome";v="120", "Not:A-Brand";v="120", "Chromium";v="99"`) + header.Set("priority", "u=1, i") header.Set("sec-ch-ua-mobile", "?0") header.Set("sec-ch-ua-platform", `"Linux"`) header.Set("sec-fetch-dest", "empty") header.Set("sec-fetch-mode", "cors") header.Set("sec-fetch-site", "same-origin") + header.Set("Connection", "close") header.Set("user-agent", userAgent) return header }