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
2390c2cb
authored
Nov 11, 2023
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完全移除近似估算token功能
parent
5894e7dc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
3 additions
and
20 deletions
+3
-20
common/constants.go
+1
-1
controller/relay-utils.go
+2
-9
model/option.go
+0
-3
web/src/components/OperationSetting.js
+0
-7
No files found.
common/constants.go
View file @
2390c2cb
...
...
@@ -84,7 +84,7 @@ var ChannelDisableThreshold = 5.0
var
AutomaticDisableChannelEnabled
=
false
var
QuotaRemindThreshold
=
1000
var
PreConsumedQuota
=
500
var
ApproximateTokenEnabled
=
false
var
RetryTimes
=
0
var
RootUserEmail
=
""
...
...
controller/relay-utils.go
View file @
2390c2cb
...
...
@@ -8,7 +8,6 @@ import (
"io"
"net/http"
"one-api/common"
"regexp"
"strconv"
"strings"
)
...
...
@@ -60,9 +59,6 @@ func getTokenEncoder(model string) *tiktoken.Tiktoken {
}
func
getTokenNum
(
tokenEncoder
*
tiktoken
.
Tiktoken
,
text
string
)
int
{
if
common
.
ApproximateTokenEnabled
{
return
int
(
float64
(
len
(
text
))
*
0.38
)
}
return
len
(
tokenEncoder
.
Encode
(
text
,
nil
,
nil
))
}
...
...
@@ -118,11 +114,8 @@ func countTokenText(text string, model string) int {
func
errorWrapper
(
err
error
,
code
string
,
statusCode
int
)
*
OpenAIErrorWithStatusCode
{
text
:=
err
.
Error
()
// 定义一个正则表达式匹配URL
urlPattern
:=
`http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+`
urlRegexp
,
reErr
:=
regexp
.
Compile
(
urlPattern
)
if
reErr
==
nil
{
text
=
urlRegexp
.
ReplaceAllString
(
text
,
"https://api.openai.com"
)
if
strings
.
Contains
(
text
,
"Post"
)
{
text
=
"请求上游地址失败"
}
//避免暴露内部错误
...
...
model/option.go
View file @
2390c2cb
...
...
@@ -34,7 +34,6 @@ func InitOptionMap() {
common
.
OptionMap
[
"TurnstileCheckEnabled"
]
=
strconv
.
FormatBool
(
common
.
TurnstileCheckEnabled
)
common
.
OptionMap
[
"RegisterEnabled"
]
=
strconv
.
FormatBool
(
common
.
RegisterEnabled
)
common
.
OptionMap
[
"AutomaticDisableChannelEnabled"
]
=
strconv
.
FormatBool
(
common
.
AutomaticDisableChannelEnabled
)
common
.
OptionMap
[
"ApproximateTokenEnabled"
]
=
strconv
.
FormatBool
(
common
.
ApproximateTokenEnabled
)
common
.
OptionMap
[
"LogConsumeEnabled"
]
=
strconv
.
FormatBool
(
common
.
LogConsumeEnabled
)
common
.
OptionMap
[
"DisplayInCurrencyEnabled"
]
=
strconv
.
FormatBool
(
common
.
DisplayInCurrencyEnabled
)
common
.
OptionMap
[
"DisplayTokenStatEnabled"
]
=
strconv
.
FormatBool
(
common
.
DisplayTokenStatEnabled
)
...
...
@@ -153,8 +152,6 @@ func updateOptionMap(key string, value string) (err error) {
common
.
EmailDomainRestrictionEnabled
=
boolValue
case
"AutomaticDisableChannelEnabled"
:
common
.
AutomaticDisableChannelEnabled
=
boolValue
case
"ApproximateTokenEnabled"
:
common
.
ApproximateTokenEnabled
=
boolValue
case
"LogConsumeEnabled"
:
common
.
LogConsumeEnabled
=
boolValue
case
"DisplayInCurrencyEnabled"
:
...
...
web/src/components/OperationSetting.js
View file @
2390c2cb
...
...
@@ -19,7 +19,6 @@ const OperationSetting = () => {
LogConsumeEnabled
:
''
,
DisplayInCurrencyEnabled
:
''
,
DisplayTokenStatEnabled
:
''
,
ApproximateTokenEnabled
:
''
,
RetryTimes
:
0
});
const
[
originInputs
,
setOriginInputs
]
=
useState
({});
...
...
@@ -201,12 +200,6 @@ const OperationSetting = () => {
name
=
'DisplayTokenStatEnabled'
onChange
=
{
handleInputChange
}
/
>
<
Form
.
Checkbox
checked
=
{
inputs
.
ApproximateTokenEnabled
===
'true'
}
label
=
'使用近似的方式估算 token 数以减少计算量'
name
=
'ApproximateTokenEnabled'
onChange
=
{
handleInputChange
}
/
>
<
/Form.Group
>
<
Form
.
Button
onClick
=
{()
=>
{
submitConfig
(
'general'
).
then
();
...
...
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