Merge pull request #95 from songquanpeng/main
Fork Sync: Update from parent repository
This commit is contained in:
commit
2b3e4759ed
@ -148,6 +148,7 @@ const (
|
|||||||
ChannelTypeAIProxy = 10
|
ChannelTypeAIProxy = 10
|
||||||
ChannelTypePaLM = 11
|
ChannelTypePaLM = 11
|
||||||
ChannelTypeAPI2GPT = 12
|
ChannelTypeAPI2GPT = 12
|
||||||
|
ChannelTypeAIGC2D = 13
|
||||||
)
|
)
|
||||||
|
|
||||||
var ChannelBaseURLs = []string{
|
var ChannelBaseURLs = []string{
|
||||||
@ -164,4 +165,5 @@ var ChannelBaseURLs = []string{
|
|||||||
"https://api.aiproxy.io", // 10
|
"https://api.aiproxy.io", // 10
|
||||||
"", // 11
|
"", // 11
|
||||||
"https://api.api2gpt.com", // 12
|
"https://api.api2gpt.com", // 12
|
||||||
|
"https://api.aigc2d.com", // 13
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,14 @@ type API2GPTUsageResponse struct {
|
|||||||
TotalRemaining float64 `json:"total_remaining"`
|
TotalRemaining float64 `json:"total_remaining"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type APGC2DGPTUsageResponse struct {
|
||||||
|
//Grants interface{} `json:"grants"`
|
||||||
|
Object string `json:"object"`
|
||||||
|
TotalAvailable float64 `json:"total_available"`
|
||||||
|
TotalGranted float64 `json:"total_granted"`
|
||||||
|
TotalUsed float64 `json:"total_used"`
|
||||||
|
}
|
||||||
|
|
||||||
// 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{}
|
||||||
@ -151,6 +159,21 @@ func updateChannelAPI2GPTBalance(channel *model.Channel) (float64, error) {
|
|||||||
return response.TotalRemaining, nil
|
return response.TotalRemaining, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateChannelAIGC2DBalance(channel *model.Channel) (float64, error) {
|
||||||
|
url := "https://api.aigc2d.com/dashboard/billing/credit_grants"
|
||||||
|
body, err := GetResponseBody("GET", url, channel, GetAuthHeader(channel.Key))
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
response := APGC2DGPTUsageResponse{}
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
channel.UpdateBalance(response.TotalAvailable)
|
||||||
|
return response.TotalAvailable, 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 {
|
||||||
@ -171,6 +194,8 @@ func updateChannelBalance(channel *model.Channel) (float64, error) {
|
|||||||
return updateChannelAIProxyBalance(channel)
|
return updateChannelAIProxyBalance(channel)
|
||||||
case common.ChannelTypeAPI2GPT:
|
case common.ChannelTypeAPI2GPT:
|
||||||
return updateChannelAPI2GPTBalance(channel)
|
return updateChannelAPI2GPTBalance(channel)
|
||||||
|
case common.ChannelTypeAIGC2D:
|
||||||
|
return updateChannelAIGC2DBalance(channel)
|
||||||
default:
|
default:
|
||||||
return 0, errors.New("尚未实现")
|
return 0, errors.New("尚未实现")
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ function renderBalance(type, balance) {
|
|||||||
return <span>{renderNumber(balance)}</span>;
|
return <span>{renderNumber(balance)}</span>;
|
||||||
case 12: // API2GPT
|
case 12: // API2GPT
|
||||||
return <span>¥{balance.toFixed(2)}</span>;
|
return <span>¥{balance.toFixed(2)}</span>;
|
||||||
|
case 13: // AIGC2D
|
||||||
|
return <span>{renderNumber(balance)}</span>;
|
||||||
default:
|
default:
|
||||||
return <span>不支持</span>;
|
return <span>不支持</span>;
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,6 @@ export const CHANNEL_OPTIONS = [
|
|||||||
{ 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' }
|
{ key: 12, text: 'API2GPT', value: 12, color: 'blue' },
|
||||||
|
{ key: 13, text: 'AIGC2D', value: 13, color: 'purple' }
|
||||||
];
|
];
|
Loading…
Reference in New Issue
Block a user