Skip to content

Commit

Permalink
Update BaseURL in request.go
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhou26 committed Apr 7, 2024
1 parent 543b5c3 commit c685ce7
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions internal/chatgpt/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/joho/godotenv"
)

var HostURL string
var BaseURL string

func init() {
Expand All @@ -39,9 +38,6 @@ func init() {
if BaseURL == "" {
BaseURL = "https://chat.openai.com/backend-anon"
}
if HostURL == "" {
HostURL = "https://chat.openai.com/backend-anon"
}
}

type connInfo struct {
Expand All @@ -62,7 +58,7 @@ var (
)

func getWSURL(client httpclient.AuroraHttpClient, token string, retry int) (string, error) {
requestURL := HostURL + "/register-websocket"
requestURL := BaseURL + "/register-websocket"
header := make(httpclient.AuroraHeaders)
header.Set("User-Agent", userAgent)
header.Set("Accept", "*/*")
Expand Down Expand Up @@ -291,7 +287,7 @@ type urlAttr struct {
}

func getURLAttribution(client httpclient.AuroraHttpClient, access_token string, puid string, url string) string {
requestURL := HostURL + "/attributions"
requestURL := BaseURL + "/attributions"
payload := bytes.NewBuffer([]byte(`{"urls":["` + url + `"]}`))
header := make(httpclient.AuroraHeaders)
if puid != "" {
Expand Down Expand Up @@ -322,7 +318,7 @@ func POSTconversation(client httpclient.AuroraHttpClient, message chatgpt_types.
if proxy != "" {
client.SetProxy(proxy)
}
apiUrl := HostURL + "/conversation"
apiUrl := BaseURL + "/conversation"
if API_REVERSE_PROXY != "" {
apiUrl = API_REVERSE_PROXY
}
Expand Down Expand Up @@ -394,7 +390,7 @@ func GETengines(client httpclient.AuroraHttpClient, secret *tokens.Secret, proxy
if proxy != "" {
client.SetProxy(proxy)
}
reqUrl := HostURL + "/models"
reqUrl := BaseURL + "/models"
header := make(httpclient.AuroraHeaders)
header.Set("Content-Type", "application/json")
header.Set("User-Agent", userAgent)
Expand Down Expand Up @@ -645,8 +641,8 @@ func Handler(c *gin.Context, response *http.Response, client httpclient.AuroraHt
attr := urlAttrMap[citation.Metadata.URL]
if attr == "" {
u, _ := url.Parse(citation.Metadata.URL)
HostURL := u.Scheme + "://" + u.Host + "/"
attr = getURLAttribution(client, secret.Token, secret.PUID, HostURL)
BaseURL := u.Scheme + "://" + u.Host + "/"
attr = getURLAttribution(client, secret.Token, secret.PUID, BaseURL)
if attr != "" {
urlAttrMap[citation.Metadata.URL] = attr
}
Expand All @@ -663,7 +659,7 @@ func Handler(c *gin.Context, response *http.Response, client httpclient.AuroraHt
continue
}
if original_response.Message.Content.ContentType == "multimodal_text" {
apiUrl := HostURL + "/files/"
apiUrl := BaseURL + "/files/"
if FILES_REVERSE_PROXY != "" {
apiUrl = FILES_REVERSE_PROXY
}
Expand Down

0 comments on commit c685ce7

Please sign in to comment.