Skip to content

Commit

Permalink
修复负数情况
Browse files Browse the repository at this point in the history
  • Loading branch information
aaakoako committed Mar 9, 2023
1 parent 41f3d4c commit fb1d490
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions code/services/gpt3.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ func (gpt *ChatGPT) getApiKey() (string, error) {
}
totalWeight := 0
for _, weight := range gpt.apiKeyWeights {
if weight <= 0 {
// 如果权重为0或负数,则永久禁用该apikey
continue
}
totalWeight += weight
}
if totalWeight == 0 {
Expand All @@ -185,6 +189,10 @@ func (gpt *ChatGPT) getApiKey() (string, error) {
}
randNum := rand.Intn(totalWeight)
for i, weight := range gpt.apiKeyWeights {
if weight <= 0 {
// 如果权重为0或负数,则跳过该apikey
continue
}
if randNum < weight {
gpt.currentApiKeyIndex = i
break
Expand Down

0 comments on commit fb1d490

Please sign in to comment.