Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
196703ca
authored
Jun 25, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: validate the request first before send to OpenAI's server
parent
462ad0c5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
controller/relay-text.go
+20
-0
No files found.
controller/relay-text.go
View file @
196703ca
...
...
@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"io"
...
...
@@ -29,6 +30,25 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
if
relayMode
==
RelayModeModeration
&&
textRequest
.
Model
==
""
{
textRequest
.
Model
=
"text-moderation-latest"
}
// request validation
if
textRequest
.
Model
==
""
{
return
errorWrapper
(
errors
.
New
(
"model is required"
),
"required_field_missing"
,
http
.
StatusBadRequest
)
}
switch
relayMode
{
case
RelayModeCompletions
:
if
textRequest
.
Prompt
==
""
{
return
errorWrapper
(
errors
.
New
(
"prompt is required"
),
"required_field_missing"
,
http
.
StatusBadRequest
)
}
case
RelayModeChatCompletions
:
if
len
(
textRequest
.
Messages
)
==
0
{
return
errorWrapper
(
errors
.
New
(
"messages is required"
),
"required_field_missing"
,
http
.
StatusBadRequest
)
}
case
RelayModeEmbeddings
:
case
RelayModeModeration
:
if
textRequest
.
Input
==
""
{
return
errorWrapper
(
errors
.
New
(
"input is required"
),
"required_field_missing"
,
http
.
StatusBadRequest
)
}
}
baseURL
:=
common
.
ChannelBaseURLs
[
channelType
]
requestURL
:=
c
.
Request
.
URL
.
String
()
if
c
.
GetString
(
"base_url"
)
!=
""
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment