75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
// DeepRes — Telegram bot for deep research
|
|
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
type Config struct {
|
|
// Telegram
|
|
TelegramToken string
|
|
|
|
// Database
|
|
DatabaseURL string
|
|
|
|
// NATS
|
|
NATSURL string
|
|
|
|
// SearXNG
|
|
SearXNGURL string
|
|
|
|
// LLM API (OpenRouter)
|
|
OpenRouterKey string
|
|
LLMModel string
|
|
|
|
// Embeddings (E5 via sentence-transformers HTTP server)
|
|
EmbedURL string
|
|
|
|
// Prices in Telegram Stars
|
|
FastResearchCost int
|
|
DeepResearchCost int
|
|
FreeFastPerDay int
|
|
}
|
|
|
|
func Load() *Config {
|
|
cfg := &Config{
|
|
TelegramToken: mustEnv("TELEGRAM_TOKEN"),
|
|
DatabaseURL: mustEnv("DATABASE_URL"),
|
|
NATSURL: getEnv("NATS_URL", "nats://localhost:4222"),
|
|
SearXNGURL: getEnv("SEARXNG_URL", "http://localhost:4000"),
|
|
OpenRouterKey: mustEnv("OPENROUTER_API_KEY"),
|
|
LLMModel: getEnv("LLM_MODEL", "deepseek/deepseek-v4-flash"),
|
|
EmbedURL: getEnv("EMBED_URL", "http://localhost:8081"),
|
|
FastResearchCost: getEnvInt("FAST_COST", 1),
|
|
DeepResearchCost: getEnvInt("DEEP_COST", 5),
|
|
FreeFastPerDay: getEnvInt("FREE_FAST_PER_DAY", 3),
|
|
}
|
|
return cfg
|
|
}
|
|
|
|
func getEnv(key, defaultVal string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return defaultVal
|
|
}
|
|
|
|
func getEnvInt(key string, defaultVal int) int {
|
|
if v := os.Getenv(key); v != "" {
|
|
if i, err := strconv.Atoi(v); err == nil {
|
|
return i
|
|
}
|
|
}
|
|
return defaultVal
|
|
}
|
|
|
|
func mustEnv(key string) string {
|
|
v := os.Getenv(key)
|
|
if v == "" {
|
|
panic(fmt.Sprintf("required environment variable %s is not set", key))
|
|
}
|
|
return v
|
|
}
|