Skip to content

Commit

Permalink
feat: if no available API, revive one randomly
Browse files Browse the repository at this point in the history
  • Loading branch information
Leizhenpeng committed Mar 10, 2023
1 parent 1487e21 commit fefea3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion code/services/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package loadbalancer

import (
"fmt"
"math/rand"
"sync"
"time"
)

type API struct {
Expand Down Expand Up @@ -36,7 +39,12 @@ func (lb *LoadBalancer) GetAPI() *API {
}
}
if len(availableAPIs) == 0 {
return nil
//随机复活一个
fmt.Printf("No available API, revive one randomly\n")
rand.Seed(time.Now().UnixNano())
index := rand.Intn(len(lb.apis))
lb.apis[index].Available = true
return lb.apis[index]
}

selectedAPI := availableAPIs[0]
Expand Down
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,14 @@ docker run -d --name feishu-chatgpt -p 9000:9000 \
--env BOT_NAME=chatGpt \
--env OPENAI_KEY="sk-xxx1,sk-xxx2,sk-xxx3" \
--env API_URL="https://api.openai.com" \
--env HTTP_PROXY="http://host.docker.internal:7890" \
--env HTTP_PROXY="" \
feishu-chatgpt:latest
```

注意:
- `BOT_NAME` 为飞书机器人名称,例如 `chatGpt`
- `OPENAI_KEY` 为openai key,多个key用逗号分隔,例如 `sk-xxx1,sk-xxx2,sk-xxx3`
- `HTTP_PROXY` 为宿主机的proxy地址,例如 `http://host.docker.internal:7890`
- `API_URL` 为openai api 接口地址,例如 `https://api.openai.com`, 没有反向代理的话,可以不用设置
---

小白简易化 docker 部署
Expand Down

0 comments on commit fefea3b

Please sign in to comment.