support API2GPT platform
This commit is contained in:
parent
d91e7dcfdc
commit
a124bbe42d
@ -1,9 +1,10 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
var StartTime = time.Now().Unix() // unit: second
|
var StartTime = time.Now().Unix() // unit: second
|
||||||
@ -133,6 +134,7 @@ const (
|
|||||||
ChannelTypeAILS = 9
|
ChannelTypeAILS = 9
|
||||||
ChannelTypeAIProxy = 10
|
ChannelTypeAIProxy = 10
|
||||||
ChannelTypePaLM = 11
|
ChannelTypePaLM = 11
|
||||||
|
ChannelTypeAPI2GPT = 12
|
||||||
)
|
)
|
||||||
|
|
||||||
var ChannelBaseURLs = []string{
|
var ChannelBaseURLs = []string{
|
||||||
@ -148,4 +150,5 @@ var ChannelBaseURLs = []string{
|
|||||||
"https://api.caipacity.com", // 9
|
"https://api.caipacity.com", // 9
|
||||||
"https://api.aiproxy.io", // 10
|
"https://api.aiproxy.io", // 10
|
||||||
"", // 11
|
"", // 11
|
||||||
|
"https://api.api2gpt.com", // 12
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,13 @@ type AIProxyUserOverviewResponse struct {
|
|||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type API2GPTUsageResponse struct {
|
||||||
|
Object string `json:"object"`
|
||||||
|
TotalGranted float64 `json:"total_granted"`
|
||||||
|
TotalUsed float64 `json:"total_used"`
|
||||||
|
TotalRemaining float64 `json:"total_remaining"`
|
||||||
|
}
|
||||||
|
|
||||||
// GetAuthHeader get auth header
|
// GetAuthHeader get auth header
|
||||||
func GetAuthHeader(token string) http.Header {
|
func GetAuthHeader(token string) http.Header {
|
||||||
h := http.Header{}
|
h := http.Header{}
|
||||||
@ -127,6 +134,23 @@ func updateChannelAIProxyBalance(channel *model.Channel) (float64, error) {
|
|||||||
return response.Data.TotalPoints, nil
|
return response.Data.TotalPoints, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateChannelAPI2GPTBalance(channel *model.Channel) (float64, error) {
|
||||||
|
url := "https://api.api2gpt.com/dashboard/billing/credit_grants"
|
||||||
|
body, err := GetResponseBody("GET", url, channel, GetAuthHeader(channel.Key))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
response := API2GPTUsageResponse{}
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
fmt.Print(response)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
channel.UpdateBalance(response.TotalRemaining)
|
||||||
|
return response.TotalRemaining, nil
|
||||||
|
}
|
||||||
|
|
||||||
func updateChannelBalance(channel *model.Channel) (float64, error) {
|
func updateChannelBalance(channel *model.Channel) (float64, error) {
|
||||||
baseURL := common.ChannelBaseURLs[channel.Type]
|
baseURL := common.ChannelBaseURLs[channel.Type]
|
||||||
switch channel.Type {
|
switch channel.Type {
|
||||||
@ -142,6 +166,8 @@ func updateChannelBalance(channel *model.Channel) (float64, error) {
|
|||||||
return updateChannelOpenAISBBalance(channel)
|
return updateChannelOpenAISBBalance(channel)
|
||||||
case common.ChannelTypeAIProxy:
|
case common.ChannelTypeAIProxy:
|
||||||
return updateChannelAIProxyBalance(channel)
|
return updateChannelAIProxyBalance(channel)
|
||||||
|
case common.ChannelTypeAPI2GPT:
|
||||||
|
return updateChannelAPI2GPTBalance(channel)
|
||||||
default:
|
default:
|
||||||
return 0, errors.New("尚未实现")
|
return 0, errors.New("尚未实现")
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ function renderBalance(type, balance) {
|
|||||||
return <span>¥{(balance / 10000).toFixed(2)}</span>;
|
return <span>¥{(balance / 10000).toFixed(2)}</span>;
|
||||||
case 10: // AI Proxy
|
case 10: // AI Proxy
|
||||||
return <span>{renderNumber(balance)}</span>;
|
return <span>{renderNumber(balance)}</span>;
|
||||||
|
case 12: // API2GPT
|
||||||
|
return <span>{renderNumber(balance)}</span>;
|
||||||
default:
|
default:
|
||||||
return <span>不支持</span>;
|
return <span>不支持</span>;
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,6 @@ export const CHANNEL_OPTIONS = [
|
|||||||
{ key: 6, text: 'OpenAI Max', value: 6, color: 'violet' },
|
{ key: 6, text: 'OpenAI Max', value: 6, color: 'violet' },
|
||||||
{ key: 7, text: 'OhMyGPT', value: 7, color: 'purple' },
|
{ key: 7, text: 'OhMyGPT', value: 7, color: 'purple' },
|
||||||
{ key: 9, text: 'AI.LS', value: 9, color: 'yellow' },
|
{ key: 9, text: 'AI.LS', value: 9, color: 'yellow' },
|
||||||
{ key: 10, text: 'AI Proxy', value: 10, color: 'purple' }
|
{ key: 10, text: 'AI Proxy', value: 10, color: 'purple' },
|
||||||
|
{ key: 12, text: 'API2GPT', value: 12, color: 'blue' }
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user