-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
167 lines (129 loc) · 5.18 KB
/
config.py
File metadata and controls
167 lines (129 loc) · 5.18 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"""
Autocoder Configuration
=======================
Centralized configuration using Pydantic BaseSettings.
Loads settings from environment variables and .env files.
"""
from typing import Optional
from urllib.parse import urlparse
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict
class AutocoderConfig(BaseSettings):
"""Centralized configuration for Autocoder.
Settings are loaded from:
1. Environment variables (highest priority)
2. .env file in project root
3. Default values (lowest priority)
Usage:
config = AutocoderConfig()
print(config.playwright_browser)
"""
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=False,
extra="ignore", # Ignore extra env vars
)
# ==========================================================================
# API Configuration
# ==========================================================================
anthropic_base_url: Optional[str] = Field(
default=None,
description="Base URL for Anthropic-compatible API"
)
anthropic_auth_token: Optional[str] = Field(
default=None,
description="Auth token for Anthropic-compatible API"
)
anthropic_api_key: Optional[str] = Field(
default=None,
description="Anthropic API key (if using Claude directly)"
)
api_timeout_ms: int = Field(
default=120000,
description="API request timeout in milliseconds"
)
# ==========================================================================
# Model Configuration
# ==========================================================================
anthropic_default_sonnet_model: str = Field(
default="claude-sonnet-4-20250514",
description="Default model for Sonnet tier"
)
anthropic_default_opus_model: str = Field(
default="claude-opus-4-20250514",
description="Default model for Opus tier"
)
anthropic_default_haiku_model: str = Field(
default="claude-haiku-3-5-20241022",
description="Default model for Haiku tier"
)
# ==========================================================================
# Playwright Configuration
# ==========================================================================
playwright_browser: str = Field(
default="firefox",
description="Browser to use for testing (firefox, chrome, webkit, msedge)"
)
playwright_headless: bool = Field(
default=True,
description="Run browser in headless mode"
)
# ==========================================================================
# Webhook Configuration
# ==========================================================================
progress_n8n_webhook_url: Optional[str] = Field(
default=None,
description="N8N webhook URL for progress notifications"
)
# ==========================================================================
# Server Configuration
# ==========================================================================
autocoder_allow_remote: bool = Field(
default=False,
description="Allow remote access to the server"
)
# ==========================================================================
# Computed Properties
# ==========================================================================
@property
def is_using_alternative_api(self) -> bool:
"""
Indicates whether an alternative Anthropic-compatible API endpoint and auth token are configured.
Returns:
True if both `anthropic_base_url` and `anthropic_auth_token` are set, False otherwise.
"""
return bool(self.anthropic_base_url and self.anthropic_auth_token)
@property
def is_using_ollama(self) -> bool:
"""
Determine whether the configuration targets a local Ollama instance.
Returns:
`true` if `anthropic_base_url` is set, `anthropic_auth_token` equals `"ollama"`, and the base URL's hostname is `localhost`, `127.0.0.1`, or `::1`; `false` otherwise.
"""
if not self.anthropic_base_url or self.anthropic_auth_token != "ollama":
return False
host = urlparse(self.anthropic_base_url).hostname or ""
return host in {"localhost", "127.0.0.1", "::1"}
# Global config instance (lazy loaded)
_config: Optional[AutocoderConfig] = None
def get_config() -> AutocoderConfig:
"""
Retrieve the global AutocoderConfig singleton.
Creates and caches the AutocoderConfig on first access by loading settings from the environment and .env file.
Returns:
The global AutocoderConfig instance; created on first access if not already initialized.
"""
global _config
if _config is None:
_config = AutocoderConfig()
return _config
def reload_config() -> AutocoderConfig:
"""
Reloads the global AutocoderConfig by re-reading environment variables.
Returns:
AutocoderConfig: The reloaded configuration instance.
"""
global _config
_config = AutocoderConfig()
return _config