Skip to content

Commit

Permalink
重新接入的自定义请求库 (aurora-develop#108)
Browse files Browse the repository at this point in the history
* 1 (aurora-develop#86)

* 1

* fix

* hi (aurora-develop#90)

* 1

* fix

* fix: fix some bug (aurora-develop#87)

Co-authored-by: aurorax-neo <[email protected]>

---------

Co-authored-by: aurorax-neo <[email protected]>

* 将tls客户端抽离封装成aurora请求库,重新定制接口,并实现基础请求功能。

* 1 (aurora-develop#100)

* Update chatgpt request.go to use environment variable for BaseURL

* Update README.md (aurora-develop#98)

* Test au (aurora-develop#99)

* 1 (aurora-develop#86)

* 1

* fix

* hi (aurora-develop#90)

* 1

* fix

* fix: fix some bug (aurora-develop#87)

Co-authored-by: aurorax-neo <[email protected]>

---------

Co-authored-by: aurorax-neo <[email protected]>

* 将tls客户端抽离封装成aurora请求库,重新定制接口,并实现基础请求功能。

---------

Co-authored-by: xiaofei <[email protected]>
Co-authored-by: aurorax-neo <[email protected]>

---------

Co-authored-by: learnLi <[email protected]>
Co-authored-by: aurorax-neo <[email protected]>

* Refactor tls_client_test.go to use environment variable for BaseURL

* 正式接入抽离的客户端库。

---------

Co-authored-by: xiaofei <[email protected]>
Co-authored-by: aurorax-neo <[email protected]>
Co-authored-by: xiaozhou26 <[email protected]>
  • Loading branch information
4 people authored Apr 5, 2024
1 parent 50fb134 commit 24767b0
Show file tree
Hide file tree
Showing 5 changed files with 7,086 additions and 7,163 deletions.
30 changes: 18 additions & 12 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
chatgptrequestconverter "aurora/conversion/requests/chatgpt"
"aurora/httpclient/bogdanfinn"
"aurora/internal/chatgpt"
"aurora/internal/proxys"
"aurora/internal/tokens"
Expand Down Expand Up @@ -33,7 +34,8 @@ func (h *Handler) refresh(c *gin.Context) {
return
}
proxyUrl := h.proxy.GetProxyIP()
openaiRefreshToken, status, err := chatgpt.GETTokenForRefreshToken(refreshToken.RefreshToken, proxyUrl)
client := bogdanfinn.NewStdClient()
openaiRefreshToken, status, err := chatgpt.GETTokenForRefreshToken(client, refreshToken.RefreshToken, proxyUrl)
if err != nil {
c.JSON(400, gin.H{
"message": "Request must be proper JSON",
Expand All @@ -59,7 +61,8 @@ func (h *Handler) session(c *gin.Context) {
return
}
proxy_url := h.proxy.GetProxyIP()
openaiSessionToken, status, err := chatgpt.GETTokenForSessionToken(sessionToken.SessionToken, proxy_url)
client := bogdanfinn.NewStdClient()
openaiSessionToken, status, err := chatgpt.GETTokenForSessionToken(client, sessionToken.SessionToken, proxy_url)
if err != nil {
c.JSON(400, gin.H{"error": gin.H{
"message": "Request must be proper JSON",
Expand Down Expand Up @@ -96,7 +99,8 @@ func (h *Handler) refresh_handler(c *gin.Context) {
}

proxy_url := h.proxy.GetProxyIP()
openaiRefreshToken, status, err := chatgpt.GETTokenForRefreshToken(refresh_token.RefreshToken, proxy_url)
client := bogdanfinn.NewStdClient()
openaiRefreshToken, status, err := chatgpt.GETTokenForRefreshToken(client, refresh_token.RefreshToken, proxy_url)
if err != nil {
c.JSON(400, gin.H{
"message": "Request must be proper JSON",
Expand All @@ -122,7 +126,8 @@ func (h *Handler) session_handler(c *gin.Context) {
return
}
proxy_url := h.proxy.GetProxyIP()
openaiSessionToken, status, err := chatgpt.GETTokenForSessionToken(session_token.SessionToken, proxy_url)
client := bogdanfinn.NewStdClient()
openaiSessionToken, status, err := chatgpt.GETTokenForSessionToken(client, session_token.SessionToken, proxy_url)
if err != nil {
c.JSON(400, gin.H{"error": gin.H{
"message": "Request must be proper JSON",
Expand Down Expand Up @@ -163,7 +168,8 @@ func (h *Handler) nightmare(c *gin.Context) {
}

uid := uuid.NewString()
turnStile, status, err := chatgpt.InitTurnStile(secret, proxyUrl)
client := bogdanfinn.NewStdClient()
turnStile, status, err := chatgpt.InitTurnStile(client, secret, proxyUrl)
if err != nil {
c.JSON(status, gin.H{
"message": err.Error(),
Expand All @@ -174,7 +180,7 @@ func (h *Handler) nightmare(c *gin.Context) {
return
}
if !secret.IsFree {
err = chatgpt.InitWSConn(secret.Token, uid, proxyUrl)
err = chatgpt.InitWSConn(client, secret.Token, uid, proxyUrl)
if err != nil {
c.JSON(500, gin.H{"error": "unable to create ws tunnel"})
return
Expand All @@ -185,7 +191,7 @@ func (h *Handler) nightmare(c *gin.Context) {

translated_request := chatgptrequestconverter.ConvertAPIRequest(original_request, secret, turnStile.Arkose, proxyUrl)

response, err := chatgpt.POSTconversation(translated_request, secret, turnStile, proxyUrl)
response, err := chatgpt.POSTconversation(client, translated_request, secret, turnStile, proxyUrl)

if err != nil {
c.JSON(500, gin.H{
Expand All @@ -201,7 +207,7 @@ func (h *Handler) nightmare(c *gin.Context) {
for i := 3; i > 0; i-- {
var continue_info *chatgpt.ContinueInfo
var response_part string
response_part, continue_info = chatgpt.Handler(c, response, secret, uid, translated_request, original_request.Stream)
response_part, continue_info = chatgpt.Handler(c, response, client, secret, uid, translated_request, original_request.Stream)
full_response += response_part
if continue_info == nil {
break
Expand All @@ -214,7 +220,7 @@ func (h *Handler) nightmare(c *gin.Context) {
if turnStile.Arkose {
chatgptrequestconverter.RenewTokenForRequest(&translated_request, secret.PUID, proxyUrl)
}
response, err = chatgpt.POSTconversation(translated_request, secret, turnStile, proxyUrl)
response, err = chatgpt.POSTconversation(client, translated_request, secret, turnStile, proxyUrl)

if err != nil {
c.JSON(500, gin.H{
Expand All @@ -238,7 +244,7 @@ func (h *Handler) nightmare(c *gin.Context) {
chatgpt.UnlockSpecConn(secret.Token, uid)
}

func (h *Handler) engines_handler(c *gin.Context) {
func (h *Handler) engines(c *gin.Context) {
proxyUrl := h.proxy.GetProxyIP()
secret := h.token.GetSecret()
authHeader := c.GetHeader("Authorization")
Expand All @@ -253,8 +259,8 @@ func (h *Handler) engines_handler(c *gin.Context) {
c.JSON(400, gin.H{"error": "Not Account Found."})
return
}

resp, status, err := chatgpt.GETengines(secret, proxyUrl)
client := bogdanfinn.NewStdClient()
resp, status, err := chatgpt.GETengines(client, secret, proxyUrl)
if err != nil {
c.JSON(500, gin.H{
"error": "error sending request",
Expand Down
5 changes: 3 additions & 2 deletions httpclient/bogdanfinn/tls_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package bogdanfinn

import (
"aurora/httpclient"
"io"
"net/http"

fhttp "github.com/bogdanfinn/fhttp"
tls_client "github.com/bogdanfinn/tls-client"
"github.com/bogdanfinn/tls-client/profiles"
"io"
"net/http"
)

type TlsClient struct {
Expand Down
Loading

0 comments on commit 24767b0

Please sign in to comment.