forked from retoor/devplacepy
docs: add CLAUDE.md with project guidelines and conventions, document new devii admin quota reset endpoints and CLI commands, update README with coverage CI and devii_admin_daily_usd config, add European date normalization to ProjectForm model
This commit is contained in:
@@ -67,10 +67,24 @@ class Settings:
|
||||
daily_limit_usd: float
|
||||
|
||||
|
||||
def _default_ai_key() -> str:
|
||||
env_key = os.environ.get("DEVII_AI_KEY", "")
|
||||
if env_key:
|
||||
return env_key
|
||||
try:
|
||||
from devplacepy.database import internal_gateway_key
|
||||
key = internal_gateway_key()
|
||||
if key:
|
||||
return key
|
||||
except Exception: # noqa: BLE001 - no local DB / remote-only: fall back to a random key
|
||||
pass
|
||||
return str(uuid.uuid4())
|
||||
|
||||
|
||||
def load_settings() -> Settings:
|
||||
return Settings(
|
||||
ai_url=os.environ.get("DEVII_AI_URL", DEFAULT_AI_URL),
|
||||
ai_key=os.environ.get("DEVII_AI_KEY", str(uuid.uuid4())),
|
||||
ai_key=_default_ai_key(),
|
||||
ai_model=os.environ.get("DEVII_AI_MODEL", DEFAULT_AI_MODEL),
|
||||
base_url=os.environ.get("DEVII_BASE_URL", DEFAULT_BASE_URL).rstrip("/"),
|
||||
timeout_seconds=float(os.environ.get("DEVII_TIMEOUT", DEFAULT_TIMEOUT_SECONDS)),
|
||||
@@ -119,6 +133,7 @@ FIELD_VERIFY_REQUIRED = "devii_verify_required"
|
||||
FIELD_MAX_ITERATIONS = "devii_max_iterations"
|
||||
FIELD_USER_DAILY_USD = "devii_user_daily_usd"
|
||||
FIELD_GUEST_DAILY_USD = "devii_guest_daily_usd"
|
||||
FIELD_ADMIN_DAILY_USD = "devii_admin_daily_usd"
|
||||
FIELD_GUESTS_ENABLED = "devii_guests_enabled"
|
||||
FIELD_PRICE_CACHE_HIT = "devii_price_cache_hit"
|
||||
FIELD_PRICE_CACHE_MISS = "devii_price_cache_miss"
|
||||
@@ -133,7 +148,17 @@ FIELD_RSEARCH_TIMEOUT = "devii_rsearch_timeout"
|
||||
LESSONS_DB_PATH = os.environ.get("DEVII_LESSONS_DB", "devii_lessons.db")
|
||||
|
||||
|
||||
def build_settings(config: dict, base_url: str, api_key: str, owner_kind: str = "guest") -> Settings:
|
||||
def effective_daily_limit(config: dict, owner_kind: str, is_admin: bool = False) -> float:
|
||||
if is_admin:
|
||||
return float(config.get(FIELD_ADMIN_DAILY_USD, 0.0) or 0.0)
|
||||
if owner_kind == "guest":
|
||||
return float(config.get(FIELD_GUEST_DAILY_USD, 0.05) or 0.0)
|
||||
return float(config.get(FIELD_USER_DAILY_USD, 1.0) or 0.0)
|
||||
|
||||
|
||||
def build_settings(
|
||||
config: dict, base_url: str, api_key: str, owner_kind: str = "guest", is_admin: bool = False
|
||||
) -> Settings:
|
||||
configured_key = config[FIELD_AI_KEY] or str(uuid.uuid4())
|
||||
ai_key = api_key if (owner_kind == "user" and api_key) else configured_key
|
||||
return Settings(
|
||||
@@ -166,8 +191,5 @@ def build_settings(config: dict, base_url: str, api_key: str, owner_kind: str =
|
||||
rsearch_enabled=bool(config.get(FIELD_RSEARCH_ENABLED, True)),
|
||||
rsearch_url=(config.get(FIELD_RSEARCH_URL) or DEFAULT_RSEARCH_URL).rstrip("/"),
|
||||
rsearch_timeout_seconds=float(config.get(FIELD_RSEARCH_TIMEOUT) or DEFAULT_RSEARCH_TIMEOUT_SECONDS),
|
||||
daily_limit_usd=float(
|
||||
(config.get(FIELD_GUEST_DAILY_USD, 0.05) if owner_kind == "guest"
|
||||
else config.get(FIELD_USER_DAILY_USD, 1.0)) or 0.0
|
||||
),
|
||||
daily_limit_usd=effective_daily_limit(config, owner_kind, is_admin),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user