Skip to content

Commit

Permalink
Refactor code to improve performance and readability
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhou26 committed Apr 4, 2024
1 parent c353124 commit d25a0cf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/chatgpt/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var (
)

func getWSURL(token string, retry int) (string, error) {
//request, err := fhttp.NewRequest(fhttp.MethodPost, "https://chat.openai.com/backend-api/register-websocket", nil)
//request, err := fhttp.NewRequest(fhttp.MethodPost, "https://chat.openai.com/backend-anon/register-websocket", nil)
//if err != nil {
// return "", err
//}
Expand All @@ -72,7 +72,7 @@ func getWSURL(token string, retry int) (string, error) {
var WSSResp chatgpt_types.ChatGPTWSSResponse
_, err := httpclient.NewStdClient().Client.R().
SetResult(&WSSResp).
Post("https://chat.openai.com/backend-api/register-websocket")
Post("https://chat.openai.com/backend-anon/register-websocket")
logger.Logger.Info(fmt.Sprint("getWSURL: ", WSSResp.WssUrl))
if err != nil {
if retry > 3 {
Expand Down Expand Up @@ -245,7 +245,7 @@ func POSTTurnStile(client *httpclient.RestyClient, secret *tokens.Secret, proxy
if secret.IsFree {
client.Client.SetHeader("oai-device-id", secret.Token)
}
path := "/backend-api/sentinel/chat-requirements"
path := "/backend-anon/sentinel/chat-requirements"
var result *chatgpt_types.RequirementsResponse
response, err := client.Client.R().
SetBody(`{"conversation_mode_kind":"primary_assistant"}`).
Expand All @@ -270,7 +270,7 @@ type urlAttr struct {
}

func getURLAttribution(access_token string, puid string, url string) string {
request, err := fhttp.NewRequest(fhttp.MethodPost, "https://chat.openai.com/backend-api/attributions", bytes.NewBuffer([]byte(`{"urls":["`+url+`"]}`)))
request, err := fhttp.NewRequest(fhttp.MethodPost, "https://chat.openai.com/backend-anon/attributions", bytes.NewBuffer([]byte(`{"urls":["`+url+`"]}`)))
if err != nil {
return ""
}
Expand Down Expand Up @@ -370,7 +370,7 @@ func GETengines(secret *tokens.Secret, proxy string) (*EnginesData, int, error)
if proxy != "" {
client.SetProxy(proxy)
}
reqUrl := "https://chat.openai.com/backend-api/models"
reqUrl := "https://chat.openai.com/backend-anon/models"
req, _ := fhttp.NewRequest("GET", reqUrl, nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", userAgent)
Expand Down Expand Up @@ -642,7 +642,7 @@ func Handler(c *gin.Context, response *http.Response, secret *tokens.Secret, uui
continue
}
if original_response.Message.Content.ContentType == "multimodal_text" {
apiUrl := "https://chat.openai.com/backend-api/files/"
apiUrl := "https://chat.openai.com/backend-anon/files/"
if FILES_REVERSE_PROXY != "" {
apiUrl = FILES_REVERSE_PROXY
}
Expand Down

0 comments on commit d25a0cf

Please sign in to comment.