Per-bot API keys implemented

This commit is contained in:
HugeFrog24
2024-10-22 19:29:24 +02:00
parent 298517a79a
commit ebb3ec3fe6
4 changed files with 5 additions and 4 deletions

5
bot.go
View File

@@ -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,

View File

@@ -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

View File

@@ -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,

View File

@@ -25,7 +25,7 @@ func main() {
}
// Check for required environment variables
checkRequiredEnvVars()
// checkRequiredEnvVars()
// Initialize database
db, err := initDB()