♻️ refactor: 重构moderation接口

This commit is contained in:
Martial BE
2023-11-29 16:54:37 +08:00
parent 455269c145
commit 1c7c2d40bb
10 changed files with 183 additions and 28 deletions

View File

@@ -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
}
}

View File

@@ -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)