Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Commit

Permalink
remove excessive proxy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed May 1, 2023
1 parent 13150ef commit efb52c6
Showing 1 changed file with 1 addition and 35 deletions.
36 changes: 1 addition & 35 deletions internal/chatgpt/request.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package chatgpt

import (
"bufio"
"bytes"
"encoding/json"
"math/rand"
"os"
"strings"

typings "freechatgpt/internal/typings"

Expand All @@ -31,41 +28,10 @@ var (
API_REVERSE_PROXY = os.Getenv("API_REVERSE_PROXY")
)

func init() {
// Check for proxies.txt
if _, err := os.Stat("proxies.txt"); err == nil {
// Each line is a proxy, put in proxies array
file, _ := os.Open("proxies.txt")
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
// Split line by :
proxy := scanner.Text()
proxy_parts := strings.Split(proxy, ":")
if len(proxy_parts) == 2 {
proxy = "socks5://" + proxy
} else if len(proxy_parts) == 4 {
proxy = "socks5://" + proxy_parts[2] + ":" + proxy_parts[3] + "@" + proxy_parts[0] + ":" + proxy_parts[1]
} else {
continue
}
proxies = append(proxies, proxy)
}
}
}

func random_int(min int, max int) int {
return min + rand.Intn(max-min)
}

func SendRequest(message typings.ChatGPTRequest, access_token string) (*http.Response, error) {
if http_proxy != "" && len(proxies) > 0 {
if http_proxy != "" {
client.SetProxy(http_proxy)
}
// Take random proxy from proxies.txt
if len(proxies) > 0 {
client.SetProxy(proxies[random_int(0, len(proxies)-1)])
}

apiUrl := "https://chat.openai.com/backend-api/conversation"
if API_REVERSE_PROXY != "" {
Expand Down

0 comments on commit efb52c6

Please sign in to comment.