mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-14 20:23:46 +08:00
🎨 调整供应商目录结构,合并文本输出函数
This commit is contained in:
30
providers/closeai/balance.go
Normal file
30
providers/closeai/balance.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package closeai
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"one-api/common"
|
||||
"one-api/model"
|
||||
)
|
||||
|
||||
func (p *CloseaiProxyProvider) Balance(channel *model.Channel) (float64, error) {
|
||||
fullRequestURL := p.GetFullRequestURL("/sb-api/user/status", "")
|
||||
fullRequestURL = fmt.Sprintf("%s?api_key=%s", fullRequestURL, channel.Key)
|
||||
headers := p.GetRequestHeaders()
|
||||
|
||||
client := common.NewClient()
|
||||
req, err := client.NewRequest("GET", fullRequestURL, common.WithBody(nil), common.WithHeader(headers))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
var response OpenAICreditGrants
|
||||
err = client.SendRequest(req, &response)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
channel.UpdateBalance(response.TotalAvailable)
|
||||
|
||||
return response.TotalAvailable, nil
|
||||
}
|
||||
18
providers/closeai/base.go
Normal file
18
providers/closeai/base.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package closeai
|
||||
|
||||
import (
|
||||
"one-api/providers/openai"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type CloseaiProxyProvider struct {
|
||||
*openai.OpenAIProvider
|
||||
}
|
||||
|
||||
// 创建 CloseaiProxyProvider
|
||||
func CreateCloseaiProxyProvider(c *gin.Context) *CloseaiProxyProvider {
|
||||
return &CloseaiProxyProvider{
|
||||
OpenAIProvider: openai.CreateOpenAIProvider(c, "https://api.closeai-proxy.xyz"),
|
||||
}
|
||||
}
|
||||
8
providers/closeai/type.go
Normal file
8
providers/closeai/type.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package closeai
|
||||
|
||||
type OpenAICreditGrants struct {
|
||||
Object string `json:"object"`
|
||||
TotalGranted float64 `json:"total_granted"`
|
||||
TotalUsed float64 `json:"total_used"`
|
||||
TotalAvailable float64 `json:"total_available"`
|
||||
}
|
||||
Reference in New Issue
Block a user