diff --git a/README.md b/README.md index 495039b8..ba331947 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用 + [x] [OhMyGPT](https://aigptx.top?aff=uFpUl2Kf) + [x] [AI Proxy](https://aiproxy.io/?i=OneAPI) (邀请码:`OneAPI`) + [x] [OpenAI-SB](https://openai-sb.com) + + [x] [API2GPT](http://console.api2gpt.com/m/00002S) + [x] [CloseAI](https://console.openai-asia.com/r/2412) + [x] [AI.LS](https://ai.ls) + [x] [OpenAI Max](https://openaimax.com) diff --git a/common/constants.go b/common/constants.go index 23fb3584..f7467d68 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1,9 +1,10 @@ package common import ( - "github.com/google/uuid" "sync" "time" + + "github.com/google/uuid" ) var StartTime = time.Now().Unix() // unit: second @@ -133,6 +134,7 @@ const ( ChannelTypeAILS = 9 ChannelTypeAIProxy = 10 ChannelTypePaLM = 11 + ChannelTypeAPI2GPT = 12 ) var ChannelBaseURLs = []string{ @@ -148,4 +150,5 @@ var ChannelBaseURLs = []string{ "https://api.caipacity.com", // 9 "https://api.aiproxy.io", // 10 "", // 11 + "https://api.api2gpt.com", // 12 } diff --git a/controller/channel-billing.go b/controller/channel-billing.go index 1ff7ff42..c9c52475 100644 --- a/controller/channel-billing.go +++ b/controller/channel-billing.go @@ -54,6 +54,13 @@ type AIProxyUserOverviewResponse struct { } `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 func GetAuthHeader(token string) http.Header { h := http.Header{} @@ -127,6 +134,23 @@ func updateChannelAIProxyBalance(channel *model.Channel) (float64, error) { 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) { baseURL := common.ChannelBaseURLs[channel.Type] switch channel.Type { @@ -142,6 +166,8 @@ func updateChannelBalance(channel *model.Channel) (float64, error) { return updateChannelOpenAISBBalance(channel) case common.ChannelTypeAIProxy: return updateChannelAIProxyBalance(channel) + case common.ChannelTypeAPI2GPT: + return updateChannelAPI2GPTBalance(channel) default: return 0, errors.New("尚未实现") } diff --git a/web/src/components/ChannelsTable.js b/web/src/components/ChannelsTable.js index f5f25ae9..7bc683ea 100644 --- a/web/src/components/ChannelsTable.js +++ b/web/src/components/ChannelsTable.js @@ -36,6 +36,8 @@ function renderBalance(type, balance) { return ¥{(balance / 10000).toFixed(2)}; case 10: // AI Proxy return {renderNumber(balance)}; + case 12: // API2GPT + return ¥{balance.toFixed(2)}; default: return 不支持; } diff --git a/web/src/constants/channel.constants.js b/web/src/constants/channel.constants.js index f84a4deb..6498f033 100644 --- a/web/src/constants/channel.constants.js +++ b/web/src/constants/channel.constants.js @@ -8,5 +8,6 @@ export const CHANNEL_OPTIONS = [ { key: 6, text: 'OpenAI Max', value: 6, color: 'violet' }, { key: 7, text: 'OhMyGPT', value: 7, color: 'purple' }, { 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' } ];