(c *gin.Context, info *relaycommon.RelayInfo)
| 18 | ) |
| 19 | |
| 20 | func getAndValidAudioRequest(c *gin.Context, info *relaycommon.RelayInfo) (*dto.AudioRequest, error) { |
| 21 | audioRequest := &dto.AudioRequest{} |
| 22 | err := common.UnmarshalBodyReusable(c, audioRequest) |
| 23 | if err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | switch info.RelayMode { |
| 27 | case relayconstant.RelayModeAudioSpeech: |
| 28 | if audioRequest.Model == "" { |
| 29 | return nil, errors.New("model is required") |
| 30 | } |
| 31 | if setting.ShouldCheckPromptSensitive() { |
| 32 | words, err := service.CheckSensitiveInput(audioRequest.Input) |
| 33 | if err != nil { |
| 34 | common.LogWarn(c, fmt.Sprintf("user sensitive words detected: %s", strings.Join(words, ","))) |
| 35 | return nil, err |
| 36 | } |
| 37 | } |
| 38 | default: |
| 39 | err = c.Request.ParseForm() |
| 40 | if err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | formData := c.Request.PostForm |
| 44 | if audioRequest.Model == "" { |
| 45 | audioRequest.Model = formData.Get("model") |
| 46 | } |
| 47 | |
| 48 | if audioRequest.Model == "" { |
| 49 | return nil, errors.New("model is required") |
| 50 | } |
| 51 | audioRequest.ResponseFormat = formData.Get("response_format") |
| 52 | if audioRequest.ResponseFormat == "" { |
| 53 | audioRequest.ResponseFormat = "json" |
| 54 | } |
| 55 | } |
| 56 | return audioRequest, nil |
| 57 | } |
| 58 | |
| 59 | func AudioHelper(c *gin.Context) (newAPIError *types.NewAPIError) { |
| 60 | relayInfo := relaycommon.GenRelayInfoOpenAIAudio(c) |
no test coverage detected