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
e0ce8bf2
authored
Feb 18, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Improve CompletionRatio handling with thread-safe access and initialization
parent
0fcd243f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
common/model-ratio.go
+15
-14
No files found.
common/model-ratio.go
View file @
e0ce8bf2
...
@@ -233,7 +233,11 @@ var (
...
@@ -233,7 +233,11 @@ var (
modelRatioMapMutex
=
sync
.
RWMutex
{}
modelRatioMapMutex
=
sync
.
RWMutex
{}
)
)
var
CompletionRatio
map
[
string
]
float64
=
nil
var
(
CompletionRatio
map
[
string
]
float64
=
nil
CompletionRatioMutex
=
sync
.
RWMutex
{}
)
var
defaultCompletionRatio
=
map
[
string
]
float64
{
var
defaultCompletionRatio
=
map
[
string
]
float64
{
"gpt-4-gizmo-*"
:
2
,
"gpt-4-gizmo-*"
:
2
,
"gpt-4o-gizmo-*"
:
3
,
"gpt-4o-gizmo-*"
:
3
,
...
@@ -334,10 +338,17 @@ func GetDefaultModelRatioMap() map[string]float64 {
...
@@ -334,10 +338,17 @@ func GetDefaultModelRatioMap() map[string]float64 {
return
defaultModelRatio
return
defaultModelRatio
}
}
func
CompletionRatio2JSONString
()
string
{
func
GetCompletionRatioMap
()
map
[
string
]
float64
{
CompletionRatioMutex
.
Lock
()
defer
CompletionRatioMutex
.
Unlock
()
if
CompletionRatio
==
nil
{
if
CompletionRatio
==
nil
{
CompletionRatio
=
defaultCompletionRatio
CompletionRatio
=
defaultCompletionRatio
}
}
return
CompletionRatio
}
func
CompletionRatio2JSONString
()
string
{
GetCompletionRatioMap
()
jsonBytes
,
err
:=
json
.
Marshal
(
CompletionRatio
)
jsonBytes
,
err
:=
json
.
Marshal
(
CompletionRatio
)
if
err
!=
nil
{
if
err
!=
nil
{
SysError
(
"error marshalling completion ratio: "
+
err
.
Error
())
SysError
(
"error marshalling completion ratio: "
+
err
.
Error
())
...
@@ -345,12 +356,9 @@ func CompletionRatio2JSONString() string {
...
@@ -345,12 +356,9 @@ func CompletionRatio2JSONString() string {
return
string
(
jsonBytes
)
return
string
(
jsonBytes
)
}
}
func
UpdateCompletionRatioByJSONString
(
jsonStr
string
)
error
{
CompletionRatio
=
make
(
map
[
string
]
float64
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
CompletionRatio
)
}
func
GetCompletionRatio
(
name
string
)
float64
{
func
GetCompletionRatio
(
name
string
)
float64
{
GetCompletionRatioMap
()
if
strings
.
Contains
(
name
,
"/"
)
{
if
strings
.
Contains
(
name
,
"/"
)
{
if
ratio
,
ok
:=
CompletionRatio
[
name
];
ok
{
if
ratio
,
ok
:=
CompletionRatio
[
name
];
ok
{
return
ratio
return
ratio
...
@@ -476,10 +484,3 @@ func GetAudioCompletionRatio(name string) float64 {
...
@@ -476,10 +484,3 @@ func GetAudioCompletionRatio(name string) float64 {
}
}
return
2
return
2
}
}
func
GetCompletionRatioMap
()
map
[
string
]
float64
{
if
CompletionRatio
==
nil
{
CompletionRatio
=
defaultCompletionRatio
}
return
CompletionRatio
}
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