Skip to content

Commit

Permalink
chroe: 抽离 baseurl
Browse files Browse the repository at this point in the history
  • Loading branch information
aurorax-neo committed Apr 4, 2024
1 parent ce472a8 commit ce2c894
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewStdClient() *RestyClient {
},
}),
}
client.Client.SetBaseURL("https://chat.openai.com")
client.Client.SetRetryCount(3)
client.Client.SetRetryWaitTime(5 * time.Second)
client.Client.SetRetryMaxWaitTime(20 * time.Second)
Expand Down
13 changes: 5 additions & 8 deletions internal/chatgpt/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ func POSTTurnStile(client *httpclient.RestyClient, secret *tokens.Secret, proxy
if secret.IsFree {
client.Client.SetHeader("oai-device-id", secret.Token)
}
apiUrl := "https://chat.openai.com/backend-api/sentinel/chat-requirements"
path := "/backend-api/sentinel/chat-requirements"
var result *chatgpt_types.RequirementsResponse
response, err := client.Client.R().
SetBody(`{"conversation_mode_kind":"primary_assistant"}`).
SetResult(&result).
Post(apiUrl)
Post(path)
if err != nil {
logger.Logger.Debug(fmt.Sprint("POSTTurnStile: ", err))
return nil, err
Expand Down Expand Up @@ -305,14 +305,11 @@ func POSTconversation(client *httpclient.RestyClient, message chatgpt_types.Chat
if proxy != "" {
client.Client.SetProxy(proxy)
}
apiUrl := "https://chat.openai.com/backend-anon/conversation"
if API_REVERSE_PROXY != "" {
apiUrl = API_REVERSE_PROXY
}
path := "/backend-anon/conversation"
arkoseToken := message.ArkoseToken
message.ArkoseToken = ""
// Clear cookies
index, err := client.Client.R().Get("https://chat.openai.com")
index, err := client.Client.R().Get("")
cookies := index.Cookies()
if secret.PUID != "" {
cookies = append(cookies, &http.Cookie{
Expand All @@ -336,7 +333,7 @@ func POSTconversation(client *httpclient.RestyClient, message chatgpt_types.Chat
response, err := client.Client.R().
SetBody(message).
SetDoNotParseResponse(true).
Post(apiUrl)
Post(path)
if err != nil {
return &http.Response{}, err
}
Expand Down

0 comments on commit ce2c894

Please sign in to comment.