use package
This commit is contained in:
parent
7fb669ace7
commit
58279b4009
@ -1,10 +1,12 @@
|
||||
package chatgpt
|
||||
|
||||
import (
|
||||
arkose_req "freechatgpt/internal/chatgpt"
|
||||
"fmt"
|
||||
chatgpt_types "freechatgpt/typings/chatgpt"
|
||||
official_types "freechatgpt/typings/official"
|
||||
"strings"
|
||||
|
||||
arkose "github.com/acheong08/funcaptcha"
|
||||
)
|
||||
|
||||
func ConvertAPIRequest(api_request official_types.APIRequest) chatgpt_types.ChatGPTRequest {
|
||||
@ -13,7 +15,12 @@ func ConvertAPIRequest(api_request official_types.APIRequest) chatgpt_types.Chat
|
||||
chatgpt_request.Model = "text-davinci-002-render-sha"
|
||||
}
|
||||
if strings.HasPrefix(api_request.Model, "gpt-4") {
|
||||
arkose_req.Get_arkose_token()
|
||||
token, err := arkose.GetOpenAIToken()
|
||||
if err == nil {
|
||||
chatgpt_request.ArkoseToken = token
|
||||
} else {
|
||||
fmt.Println("Error getting Arkose token: ", err)
|
||||
}
|
||||
chatgpt_request.Model = api_request.Model
|
||||
}
|
||||
if api_request.Model == "gpt-4" {
|
||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.20
|
||||
require (
|
||||
github.com/acheong08/OpenAIAuth v0.0.0-20230609193408-55a0f33f1057
|
||||
github.com/acheong08/endless v0.0.0-20230615162514-90545c7793fd
|
||||
github.com/acheong08/funcaptcha v0.2.1-0.20230626140502-adeab195a0b3
|
||||
github.com/acheong08/funcaptcha v0.2.1-0.20230626152808-543148a3c981
|
||||
github.com/bogdanfinn/fhttp v0.5.23
|
||||
github.com/bogdanfinn/tls-client v1.4.0
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
|
2
go.sum
2
go.sum
@ -4,6 +4,8 @@ github.com/acheong08/endless v0.0.0-20230615162514-90545c7793fd h1:oIpfrRhD7Jus4
|
||||
github.com/acheong08/endless v0.0.0-20230615162514-90545c7793fd/go.mod h1:0yO7neMeJLvKk/B/fq5votDY8rByrOPDubpvU+6saKo=
|
||||
github.com/acheong08/funcaptcha v0.2.1-0.20230626140502-adeab195a0b3 h1:3SiHkE69H/JWT19fpIvjRScPDx5DnWnzzZpR5V4vHkQ=
|
||||
github.com/acheong08/funcaptcha v0.2.1-0.20230626140502-adeab195a0b3/go.mod h1:fKxNB5i7g9h6QDTIY1YZamwFmMpAJK++wMYij5NuMm4=
|
||||
github.com/acheong08/funcaptcha v0.2.1-0.20230626152808-543148a3c981 h1:ibvQvXMdniYRTYJFDaUJvG+25BF/bQxzE3AfDtv+0Ag=
|
||||
github.com/acheong08/funcaptcha v0.2.1-0.20230626152808-543148a3c981/go.mod h1:VupbjtVAODvgyAB3Zo86fOA53G+UAmaV/Rk9jUCGuTU=
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/bogdanfinn/fhttp v0.5.23 h1:4Xb5OjYArB8GpnUw4A4r5jmt8UW0/Cvey3R9nS2dC9U=
|
||||
|
@ -3,22 +3,13 @@ package chatgpt
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"freechatgpt/typings"
|
||||
chatgpt_types "freechatgpt/typings/chatgpt"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
arkose "github.com/acheong08/funcaptcha"
|
||||
|
||||
http "github.com/bogdanfinn/fhttp"
|
||||
tls_client "github.com/bogdanfinn/tls-client"
|
||||
@ -69,80 +60,12 @@ func init() {
|
||||
proxies = append(proxies, proxy)
|
||||
}
|
||||
}
|
||||
// generate timestamp in 1687790752 format
|
||||
timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1000000000)
|
||||
bx = fmt.Sprintf(`[{"key":"api_type","value":"js"},{"key":"p","value":1},{"key":"f","value":"9711bd3695defe0844fb8fd8a722f38b"},{"key":"n","value":"%s"},{"key":"wh","value":"80b13fd48b8da8e4157eeb6f9e9fbedb|5ab5738955e0611421b686bc95655ad0"},{"key":"enhanced_fp","value":[{"key":"webgl_extensions","value":null},{"key":"webgl_extensions_hash","value":null},{"key":"webgl_renderer","value":null},{"key":"webgl_vendor","value":null},{"key":"webgl_version","value":null},{"key":"webgl_shading_language_version","value":null},{"key":"webgl_aliased_line_width_range","value":null},{"key":"webgl_aliased_point_size_range","value":null},{"key":"webgl_antialiasing","value":null},{"key":"webgl_bits","value":null},{"key":"webgl_max_params","value":null},{"key":"webgl_max_viewport_dims","value":null},{"key":"webgl_unmasked_vendor","value":null},{"key":"webgl_unmasked_renderer","value":null},{"key":"webgl_vsf_params","value":null},{"key":"webgl_vsi_params","value":null},{"key":"webgl_fsf_params","value":null},{"key":"webgl_fsi_params","value":null},{"key":"webgl_hash_webgl","value":null},{"key":"user_agent_data_brands","value":null},{"key":"user_agent_data_mobile","value":null},{"key":"navigator_connection_downlink","value":null},{"key":"navigator_connection_downlink_max","value":null},{"key":"network_info_rtt","value":null},{"key":"network_info_save_data","value":null},{"key":"network_info_rtt_type","value":null},{"key":"screen_pixel_depth","value":24},{"key":"navigator_device_memory","value":null},{"key":"navigator_languages","value":"en-US,en"},{"key":"window_inner_width","value":0},{"key":"window_inner_height","value":0},{"key":"window_outer_width","value":0},{"key":"window_outer_height","value":0},{"key":"browser_detection_firefox","value":true},{"key":"browser_detection_brave","value":false},{"key":"audio_codecs","value":"{\"ogg\":\"probably\",\"mp3\":\"maybe\",\"wav\":\"probably\",\"m4a\":\"maybe\",\"aac\":\"maybe\"}"},{"key":"video_codecs","value":"{\"ogg\":\"probably\",\"h264\":\"probably\",\"webm\":\"probably\",\"mpeg4v\":\"\",\"mpeg4a\":\"\",\"theora\":\"\"}"},{"key":"media_query_dark_mode","value":false},{"key":"headless_browser_phantom","value":false},{"key":"headless_browser_selenium","value":false},{"key":"headless_browser_nightmare_js","value":false},{"key":"document__referrer","value":""},{"key":"window__ancestor_origins","value":null},{"key":"window__tree_index","value":[1]},{"key":"window__tree_structure","value":"[[],[]]"},{"key":"window__location_href","value":"https://tcr9i.chat.openai.com/v2/1.5.2/enforcement.64b3a4e29686f93d52816249ecbf9857.html#35536E1E-65B4-4D96-9D97-6ADB7EFF8147"},{"key":"client_config__sitedata_location_href","value":"https://chat.openai.com/"},{"key":"client_config__surl","value":"https://tcr9i.chat.openai.com"},{"key":"mobile_sdk__is_sdk"},{"key":"client_config__language","value":null},{"key":"audio_fingerprint","value":"35.73833402246237"}]},{"key":"fe","value":["DNT:1","L:en-US","D:24","PR:1","S:0,0","AS:false","TO:0","SS:true","LS:true","IDB:true","B:false","ODB:false","CPUC:unknown","PK:Linux x86_64","CFP:330110783","FR:false","FOS:false","FB:false","JSF:Arial,Arial Narrow,Bitstream Vera Sans Mono,Bookman Old Style,Century Schoolbook,Courier,Courier New,Helvetica,MS Gothic,MS PGothic,Palatino,Palatino Linotype,Times,Times New Roman","P:Chrome PDF Viewer,Chromium PDF Viewer,Microsoft Edge PDF Viewer,PDF Viewer,WebKit built-in PDF","T:0,false,false","H:2","SWF:false"]},{"key":"ife_hash","value":"2a007a5daef41ee943d5fc73a0a8c312"},{"key":"cs","value":1},{"key":"jsbd","value":"{\"HL\":2,\"NCE\":true,\"DT\":\"\",\"NWD\":\"false\",\"DOTO\":1,\"DMTO\":1}"}]`,
|
||||
base64.StdEncoding.EncodeToString([]byte(timestamp)))
|
||||
// var bt = new Date() ['getTime']() / 1000
|
||||
bt := time.Now().UnixMicro() / 1000000
|
||||
// bw = Math.round(bt - (bt % 21600)
|
||||
bw = strconv.FormatInt(bt-(bt%21600), 10)
|
||||
token, err := Get_arkose_token()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
println(token)
|
||||
}
|
||||
|
||||
func random_int(min int, max int) int {
|
||||
return min + rand.Intn(max-min)
|
||||
}
|
||||
|
||||
var (
|
||||
bx string
|
||||
bv string = "Mozilla/5.0 (X11; Linux x86_64; rv:114.0) Gecko/20100101 Firefox/114.0"
|
||||
bw string
|
||||
)
|
||||
|
||||
func Get_arkose_token() (string, error) {
|
||||
bda := arkose.Encrypt(bx, bv+bw)
|
||||
bda = base64.StdEncoding.EncodeToString([]byte(bda))
|
||||
form := url.Values{
|
||||
"bda": {bda},
|
||||
"public_key": {"35536E1E-65B4-4D96-9D97-6ADB7EFF8147"},
|
||||
"site": {"https://chat.openai.com"},
|
||||
"userbrowser": {bv},
|
||||
"capi_version": {"1.5.2"},
|
||||
"capi_mode": {"lightbox"},
|
||||
"style_theme": {"default"},
|
||||
"rnd": {strconv.FormatFloat(rand.Float64(), 'f', -1, 64)},
|
||||
}
|
||||
req, _ := http.NewRequest(http.MethodPost, "https://tcr9i.chat.openai.com/fc/gt2/public_key/35536E1E-65B4-4D96-9D97-6ADB7EFF8147", strings.NewReader(form.Encode()))
|
||||
req.Header.Set("Host", "tcr9i.chat.openai.com")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:114.0) Gecko/20100101 Firefox/114.0")
|
||||
req.Header.Set("Accept", "*/*")
|
||||
req.Header.Set("Accept-Language", "en-US,en;q=0.5")
|
||||
req.Header.Set("Accept-Encoding", "gzip, deflate, br")
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
||||
req.Header.Set("Origin", "https://tcr9i.chat.openai.com")
|
||||
req.Header.Set("DNT", "1")
|
||||
req.Header.Set("Connection", "keep-alive")
|
||||
req.Header.Set("Referer", "https://tcr9i.chat.openai.com/v2/1.5.2/enforcement.64b3a4e29686f93d52816249ecbf9857.html")
|
||||
req.Header.Set("Sec-Fetch-Dest", "empty")
|
||||
req.Header.Set("Sec-Fetch-Mode", "cors")
|
||||
req.Header.Set("Sec-Fetch-Site", "same-origin")
|
||||
req.Header.Set("TE", "trailers")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
return "", errors.New("status code " + resp.Status)
|
||||
}
|
||||
type arkose_response struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
var arkose arkose_response
|
||||
err = json.NewDecoder(resp.Body).Decode(&arkose)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
println(arkose.Token)
|
||||
return arkose.Token, nil
|
||||
|
||||
}
|
||||
|
||||
func POSTconversation(message chatgpt_types.ChatGPTRequest, access_token string) (*http.Response, error) {
|
||||
if http_proxy != "" && len(proxies) == 0 {
|
||||
client.SetProxy(http_proxy)
|
||||
|
Reference in New Issue
Block a user