mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-15 04:33:42 +08:00
♻️ refactor: 重构moderation接口
This commit is contained in:
@@ -21,6 +21,7 @@ type BaseProvider struct {
|
||||
ChatCompletions string
|
||||
Embeddings string
|
||||
AudioSpeech string
|
||||
Moderation string
|
||||
AudioTranscriptions string
|
||||
AudioTranslations string
|
||||
Proxy string
|
||||
@@ -125,3 +126,24 @@ func (p *BaseProvider) HandleErrorResp(resp *http.Response) (openAIErrorWithStat
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (p *BaseProvider) SupportAPI(relayMode int) bool {
|
||||
switch relayMode {
|
||||
case common.RelayModeChatCompletions:
|
||||
return p.ChatCompletions != ""
|
||||
case common.RelayModeCompletions:
|
||||
return p.Completions != ""
|
||||
case common.RelayModeEmbeddings:
|
||||
return p.Embeddings != ""
|
||||
case common.RelayModeAudioSpeech:
|
||||
return p.AudioSpeech != ""
|
||||
case common.RelayModeAudioTranscription:
|
||||
return p.AudioTranscriptions != ""
|
||||
case common.RelayModeAudioTranslation:
|
||||
return p.AudioTranslations != ""
|
||||
case common.RelayModeModerations:
|
||||
return p.Moderation != ""
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ type ProviderInterface interface {
|
||||
GetBaseURL() string
|
||||
GetFullRequestURL(requestURL string, modelName string) string
|
||||
GetRequestHeaders() (headers map[string]string)
|
||||
SupportAPI(relayMode int) bool
|
||||
}
|
||||
|
||||
// 完成接口
|
||||
@@ -31,6 +32,12 @@ type EmbeddingsInterface interface {
|
||||
EmbeddingsAction(request *types.EmbeddingRequest, isModelMapped bool, promptTokens int) (usage *types.Usage, errWithCode *types.OpenAIErrorWithStatusCode)
|
||||
}
|
||||
|
||||
// 审查接口
|
||||
type ModerationInterface interface {
|
||||
ProviderInterface
|
||||
ModerationAction(request *types.ModerationRequest, isModelMapped bool, promptTokens int) (usage *types.Usage, errWithCode *types.OpenAIErrorWithStatusCode)
|
||||
}
|
||||
|
||||
// 余额接口
|
||||
type BalanceInterface interface {
|
||||
BalanceAction(channel *model.Channel) (float64, error)
|
||||
|
||||
Reference in New Issue
Block a user