mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-10-16 08:04:10 +00:00
refactor: refactor relay part (#957)
* refactor: refactor relay part * refactor: refactor config part
This commit is contained in:
37
relay/util/validation.go
Normal file
37
relay/util/validation.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"one-api/relay/channel/openai"
|
||||
"one-api/relay/constant"
|
||||
)
|
||||
|
||||
func ValidateTextRequest(textRequest *openai.GeneralOpenAIRequest, relayMode int) error {
|
||||
if textRequest.MaxTokens < 0 || textRequest.MaxTokens > math.MaxInt32/2 {
|
||||
return errors.New("max_tokens is invalid")
|
||||
}
|
||||
if textRequest.Model == "" {
|
||||
return errors.New("model is required")
|
||||
}
|
||||
switch relayMode {
|
||||
case constant.RelayModeCompletions:
|
||||
if textRequest.Prompt == "" {
|
||||
return errors.New("field prompt is required")
|
||||
}
|
||||
case constant.RelayModeChatCompletions:
|
||||
if textRequest.Messages == nil || len(textRequest.Messages) == 0 {
|
||||
return errors.New("field messages is required")
|
||||
}
|
||||
case constant.RelayModeEmbeddings:
|
||||
case constant.RelayModeModerations:
|
||||
if textRequest.Input == "" {
|
||||
return errors.New("field input is required")
|
||||
}
|
||||
case constant.RelayModeEdits:
|
||||
if textRequest.Instruction == "" {
|
||||
return errors.New("field instruction is required")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user