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
6b6027d1
authored
Jun 12, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: now the input field can be array type now (close #149)
parent
2d78cf30
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
controller/relay-utils.go
+14
-0
controller/relay.go
+2
-2
No files found.
controller/relay-utils.go
View file @
6b6027d1
...
...
@@ -58,6 +58,20 @@ func countTokenMessages(messages []Message, model string) int {
return
tokenNum
}
func
countTokenInput
(
input
any
,
model
string
)
int
{
switch
input
.
(
type
)
{
case
string
:
return
countTokenText
(
input
.
(
string
),
model
)
case
[]
string
:
text
:=
""
for
_
,
s
:=
range
input
.
([]
string
)
{
text
+=
s
}
return
countTokenText
(
text
,
model
)
}
return
0
}
func
countTokenText
(
text
string
,
model
string
)
int
{
tokenEncoder
:=
getTokenEncoder
(
model
)
token
:=
tokenEncoder
.
Encode
(
text
,
nil
,
nil
)
...
...
controller/relay.go
View file @
6b6027d1
...
...
@@ -38,7 +38,7 @@ type GeneralOpenAIRequest struct {
Temperature
float64
`json:"temperature"`
TopP
float64
`json:"top_p"`
N
int
`json:"n"`
Input
string
`json:"input"`
Input
any
`json:"input"`
}
type
ChatRequest
struct
{
...
...
@@ -189,7 +189,7 @@ func relayHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
case
RelayModeCompletions
:
promptTokens
=
countTokenText
(
textRequest
.
Prompt
,
textRequest
.
Model
)
case
RelayModeModeration
:
promptTokens
=
countToken
Tex
t
(
textRequest
.
Input
,
textRequest
.
Model
)
promptTokens
=
countToken
Inpu
t
(
textRequest
.
Input
,
textRequest
.
Model
)
}
preConsumedTokens
:=
common
.
PreConsumedQuota
if
textRequest
.
MaxTokens
!=
0
{
...
...
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