diff --git a/.env.example b/.env.example index 212d1e7..d013a48 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,7 @@ APP_ID= APP_SECRET= +LARK_OPEN_BASE_URL= +LARK_WWW_BASE_URL= CHATGPT_API_KEY= CHATGPT_API_URL= ENABLE_SESSION_FOR_LARK_GROUP=true \ No newline at end of file diff --git a/larkgpt/client.go b/larkgpt/client.go index 5440627..2494910 100644 --- a/larkgpt/client.go +++ b/larkgpt/client.go @@ -18,8 +18,10 @@ type Client struct { type ClientConfig struct { // Lark - AppID string - AppSecret string + AppID string + AppSecret string + LarkOpenBaseURL string + LarkWWWBaseURL string // ChatGPT ChatGPTAPIKey string @@ -40,7 +42,16 @@ func New(config *ClientConfig) *Client { res.metricsIns = new(noneMetrics) } - res.larkIns = newLarkClient(lark.New(lark.WithAppCredential(config.AppID, config.AppSecret)), res.metricsIns) + larkOption := []lark.ClientOptionFunc{ + lark.WithAppCredential(config.AppID, config.AppSecret), + } + if config.LarkOpenBaseURL != "" { + larkOption = append(larkOption, lark.WithOpenBaseURL(config.LarkOpenBaseURL)) + } + if config.LarkWWWBaseURL != "" { + larkOption = append(larkOption, lark.WithWWWBaseURL(config.LarkWWWBaseURL)) + } + res.larkIns = newLarkClient(lark.New(larkOption...), res.metricsIns) res.chatGPTIns = newChatGPTClient(config.ChatGPTAPIURL, config.ChatGPTAPIKey, res.metricsIns) diff --git a/main.go b/main.go index bc44d5e..f1c3feb 100644 --- a/main.go +++ b/main.go @@ -4,8 +4,9 @@ import ( "log" "os" - "github.com/bytemate/larkgpt/larkgpt" "github.com/joho/godotenv" + + "github.com/bytemate/larkgpt/larkgpt" ) func main() { @@ -30,6 +31,8 @@ func loadConfig() (*larkgpt.ClientConfig, error) { return &larkgpt.ClientConfig{ AppID: os.Getenv("APP_ID"), AppSecret: os.Getenv("APP_SECRET"), + LarkOpenBaseURL: os.Getenv("LARK_OPEN_BASE_URL"), // default is https://open.feishu.cn, for larksuite, please use https://open.larksuite.com + LarkWWWBaseURL: os.Getenv("LARK_WWW_BASE_URL"), // default is https://www.feishu.cn, for larksuite, please use https://www.larksuite.com ChatGPTAPIKey: os.Getenv("CHATGPT_API_KEY"), ChatGPTAPIURL: os.Getenv("CHATGPT_API_URL"), ServerPort: port,