Files
opantoantro/config/config.go
T
Beyhan Ogur c56ae7194c feat: enable SSE streaming support in Anthropic handler
- Updated AnthropicHandler to check for streaming configuration before handling SSE transform.
- Modified handleStreaming to use the original request body instead of forcing stream to true.
- Adjusted the transformation logic in AnthropicToBifrost to respect the original stream setting.
- Added logging for SSE streaming configuration in the main application.
2026-05-11 15:28:56 +03:00

75 lines
2.0 KiB
Go

package config
import (
"os"
"strconv"
)
// Config holds all runtime configuration loaded from environment variables.
type Config struct {
Port string
OpenAIBackend string
OpenAIApiKey string
PostgresDSN string
DBPath string // SQLite database file path (when DB_MODE=sqlite)
DBMode string // "sqlite" or "pgs" — selects database driver
LogLevel string // "debug", "info", or "warn" — console log verbosity
RequestTimeoutSeconds int
OpenAIModel string // default model when client omits it
Streaming bool // enable/disable SSE streaming responses
}
// Load reads environment variables and returns a populated Config.
// All values MUST come from env — no hardcoded IPs or ports.
func Load() *Config {
timeoutSec := 30
if v := os.Getenv("REQUEST_TIMEOUT_SECONDS"); v != "" {
if parsed, err := strconv.Atoi(v); err == nil {
timeoutSec = parsed
}
}
dbMode := os.Getenv("DB_MODE")
dbPath := os.Getenv("DB_PATH")
logLevel := os.Getenv("LOG_LEVEL")
// Support both POSTGRES_DSN and DATABASE_DSN env keys
postgresDSN := os.Getenv("POSTGRES_DSN")
if postgresDSN == "" {
postgresDSN = os.Getenv("DATABASE_DSN")
}
port := os.Getenv("PORT")
if port == "" {
port = "8000"
}
openAIBackend := os.Getenv("OPENAI_BACKEND")
if openAIBackend == "" {
openAIBackend = "https://api.deepseek.com"
}
openAIApiKey := os.Getenv("OPENAI_KEY")
openAIModel := os.Getenv("OPENAI_MODEL")
streaming := true
if v := os.Getenv("STREAMING"); v != "" {
if parsed, err := strconv.ParseBool(v); err == nil {
streaming = parsed
}
}
return &Config{
Port: port,
OpenAIBackend: openAIBackend,
OpenAIApiKey: openAIApiKey,
PostgresDSN: postgresDSN,
DBPath: dbPath,
DBMode: dbMode,
LogLevel: logLevel,
RequestTimeoutSeconds: timeoutSec,
OpenAIModel: openAIModel,
Streaming: streaming,
}
}