From ebb3ec3fe68f5009f1d73ef47861239b6424ac2a Mon Sep 17 00:00:00 2001 From: HugeFrog24 <62775760+HugeFrog24@users.noreply.github.com> Date: Tue, 22 Oct 2024 19:29:24 +0200 Subject: [PATCH] Per-bot API keys implemented --- bot.go | 5 ++--- config.go | 1 + config/default.json | 1 + main.go | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bot.go b/bot.go index 443ae13..8274ce0 100644 --- a/bot.go +++ b/bot.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "log" - "os" "strings" "sync" "time" @@ -76,8 +75,8 @@ func NewBot(db *gorm.DB, config BotConfig, clock Clock, tgClient TelegramClient) return nil, err } - // Initialize Anthropic client - anthropicClient := anthropic.NewClient(os.Getenv("ANTHROPIC_API_KEY")) + // Use the per-bot Anthropic API key + anthropicClient := anthropic.NewClient(config.AnthropicAPIKey) b := &Bot{ db: db, diff --git a/config.go b/config.go index 2d1e556..650cde4 100644 --- a/config.go +++ b/config.go @@ -20,6 +20,7 @@ type BotConfig struct { SystemPrompts map[string]string `json:"system_prompts"` Active bool `json:"active"` // New field to control bot activity OwnerTelegramID int64 `json:"owner_telegram_id"` + AnthropicAPIKey string `json:"anthropic_api_key"` // Add this line } // Custom unmarshalling to handle anthropic.Model diff --git a/config/default.json b/config/default.json index 036fd74..f7ddd8b 100644 --- a/config/default.json +++ b/config/default.json @@ -3,6 +3,7 @@ "active": false, "telegram_token": "YOUR_TELEGRAM_BOT_TOKEN", "owner_telegram_id": 111111111, + "anthropic_api_key": "YOUR_SPECIFIC_ANTHROPIC_API_KEY", "memory_size": 10, "messages_per_hour": 20, "messages_per_day": 100, diff --git a/main.go b/main.go index 1e6c2aa..7237211 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ func main() { } // Check for required environment variables - checkRequiredEnvVars() + // checkRequiredEnvVars() // Initialize database db, err := initDB()