Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

✨ feat: support larksuite #10

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
17 changes: 14 additions & 3 deletions larkgpt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"log"
"os"

"github.com/bytemate/larkgpt/larkgpt"
"github.com/joho/godotenv"

"github.com/bytemate/larkgpt/larkgpt"
)

func main() {
Expand All @@ -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,
Expand Down