优化 ChatGPT API 重试逻辑

This commit is contained in:
RockYang
2023-03-20 15:02:42 +08:00
parent 0ca104bac8
commit 3bb6814493
9 changed files with 167 additions and 113 deletions

View File

@@ -9,6 +9,7 @@ import (
"io/fs"
"log"
"net/http"
"net/url"
logger2 "openai/logger"
"openai/types"
"os"
@@ -32,6 +33,7 @@ func (s StaticFile) Open(name string) (fs.File, error) {
type Server struct {
Config *types.Config
ConfigPath string
Client *http.Client
History map[string][]types.Message
}
@@ -41,8 +43,17 @@ func NewServer(configPath string) (*Server, error) {
if err != nil {
return nil, err
}
uri := url.URL{}
proxy, _ := uri.Parse(config.ProxyURL)
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxy),
},
}
return &Server{
Config: config,
Client: client,
ConfigPath: configPath,
History: make(map[string][]types.Message, 16)}, nil
}