🎨 Change the method of getting channel parameters

This commit is contained in:
Martial BE
2023-12-26 16:40:50 +08:00
parent 47b72b850f
commit eeb867da10
34 changed files with 67 additions and 120 deletions

View File

@@ -6,6 +6,7 @@ import (
"io"
"net/http"
"one-api/common"
"one-api/model"
"one-api/types"
"strings"
@@ -28,17 +29,22 @@ type BaseProvider struct {
ImagesVariations string
Proxy string
Context *gin.Context
Channel *model.Channel
}
// 获取基础URL
func (p *BaseProvider) GetBaseURL() string {
if p.Context.GetString("base_url") != "" {
return p.Context.GetString("base_url")
if p.Channel.GetBaseURL() != "" {
return p.Channel.GetBaseURL()
}
return p.BaseURL
}
func (p *BaseProvider) SetChannel(channel *model.Channel) {
p.Channel = channel
}
// 获取完整请求URL
func (p *BaseProvider) GetFullRequestURL(requestURL string, modelName string) string {
baseURL := strings.TrimSuffix(p.GetBaseURL(), "/")

View File

@@ -12,6 +12,7 @@ type ProviderInterface interface {
GetFullRequestURL(requestURL string, modelName string) string
GetRequestHeaders() (headers map[string]string)
SupportAPI(relayMode int) bool
SetChannel(channel *model.Channel)
}
// 完成接口