forked from bubbuild/bub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
80 lines (63 loc) · 2.52 KB
/
settings.py
File metadata and controls
80 lines (63 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""Application settings."""
from __future__ import annotations
import os
from pathlib import Path
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
"""Runtime settings loaded from environment and .env files."""
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
env_prefix="BUB_",
case_sensitive=False,
extra="ignore",
env_parse_none_str="null",
)
model: str = "openrouter:qwen/qwen3-coder-next"
api_key: str | None = None
api_base: str | None = None
use_responses: bool = False
ollama_api_key: str | None = None
ollama_api_base: str | None = None
llm_api_key: str | None = Field(default=None, validation_alias="LLM_API_KEY")
openrouter_api_key: str | None = Field(default=None, validation_alias="OPENROUTER_API_KEY")
max_tokens: int = Field(default=1024, ge=1)
model_timeout_seconds: int | None = 90
system_prompt: str = ""
home: str | None = None
workspace_path: str | None = None
tape_name: str = "bub"
max_steps: int = Field(default=20, ge=1)
proactive_response: bool = False
message_delay_seconds: int = 10
message_debounce_seconds: int = 1
telegram_enabled: bool = False
telegram_token: str | None = None
telegram_allow_from: list[str] = Field(default_factory=list)
telegram_allow_chats: list[str] = Field(default_factory=list)
telegram_proxy: str | None = Field(default=None)
discord_enabled: bool = False
discord_token: str | None = None
discord_allow_from: list[str] = Field(default_factory=list)
discord_allow_channels: list[str] = Field(default_factory=list)
discord_command_prefix: str = "!"
discord_proxy: str | None = None
@property
def resolved_api_key(self) -> str | None:
if self.api_key:
return self.api_key
if self.llm_api_key:
return self.llm_api_key
if self.openrouter_api_key:
return self.openrouter_api_key
return os.getenv("LLM_API_KEY") or os.getenv("OPENROUTER_API_KEY")
def resolve_home(self) -> Path:
if self.home:
return Path(self.home).expanduser().resolve()
return (Path.home() / ".bub").resolve()
def load_settings(workspace_path: Path | None = None) -> Settings:
"""Load settings with optional workspace override."""
if workspace_path is None:
return Settings()
return Settings(workspace_path=str(workspace_path.resolve()))