Skip to content

Commit

Permalink
修改openai web chat可以设置代理api url
Browse files Browse the repository at this point in the history
  • Loading branch information
zatxm committed May 13, 2024
1 parent f51004f commit 287d8c3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions etc/c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ openai:
# auth_proxy_url: http://127.0.0.1:1081
# web登录后放置cookie的文件夹
cookie_path: /anp/data/cookies
# openai web chat url,可以修改为任意代理地址
# 不设置默认官方https://chatgpt.com容易出盾
# 目前chat.openai.com还能用,建议设置成这个
chat_web_url: https://chat.openai.com

# 谷歌gemini接口
# https://makersuite.google.com/app/apikey申请
Expand Down
5 changes: 5 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type httpsInfo struct {
type openai struct {
AuthProxyUrl string `yaml:"auth_proxy_url"`
CookiePath string `yaml:"cookie_path"`
ChatWebUrl string `yaml:"chat_web_url"`
}

type gemini struct {
Expand Down Expand Up @@ -139,3 +140,7 @@ func ClaudeProxyUrl() string {
func CozeProxyUrl() string {
return cfg.Coze.ProxyUrl
}

func OpenaiChatWebUrl() string {
return cfg.Openai.ChatWebUrl
}
8 changes: 6 additions & 2 deletions internal/openai/api/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ func askConversationWebHttp(p types.OpenAiCompletionChatRequest, mt, auth string
}
}

webChatUrl := config.OpenaiChatWebUrl()
if webChatUrl == "" {
webChatUrl = cst.ChatOriginUrl
}
// anon token
requirementsUrl := chatCfg["requirementsUrl"]
requirementsUrl := webChatUrl + chatCfg["requirementsPath"]
req, err := http.NewRequest(http.MethodPost, requirementsUrl, nil)
if err != nil {
fhblade.Log.Error("chat-requirements new req err",
Expand Down Expand Up @@ -217,7 +221,7 @@ func askConversationWebHttp(p types.OpenAiCompletionChatRequest, mt, auth string
p.ForceRateLimit = false
p.WebsocketRequestId = uuid.NewString()
reqJson, _ := fhblade.Json.Marshal(p)
chatUrl := chatCfg["askUrl"]
chatUrl := webChatUrl + chatCfg["askPath"]
req, err = http.NewRequest(http.MethodPost, chatUrl, bytes.NewReader(reqJson))
if err != nil {
client.CcPool.Put(gClient)
Expand Down
8 changes: 4 additions & 4 deletions internal/openai/cst/c.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ var (
OaiDeviceId = uuid.NewString()
ChatAskMap = map[string]map[string]string{
"backend-anon": map[string]string{
"requirementsUrl": "https://chatgpt.com/backend-anon/sentinel/chat-requirements",
"askUrl": "https://chatgpt.com/backend-anon/conversation",
"requirementsPath": "/backend-anon/sentinel/chat-requirements",
"askPath": "/backend-anon/conversation",
},
"backend-api": map[string]string{
"requirementsUrl": "https://chatgpt.com/backend-api/sentinel/chat-requirements",
"askUrl": "https://chatgpt.com/backend-api/conversation",
"requirementsPath": "/backend-api/sentinel/chat-requirements",
"askPath": "/backend-api/conversation",
},
}
)

0 comments on commit 287d8c3

Please sign in to comment.