mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-14 06:17:23 +00:00
refactor(settings): treat unset spellings of every optional string as None
Review follow-up. The per-group secret validators normalised a hand-picked list of API keys, which left other optional credentials and overrides (OPEN_ROUTER_API_KEY, S3 and Daytona keys, ELASTIC_PASSWORD, the OIDC trio, connector client ids, MICROSOFT_AUTHORITY, MCP_OAUTH_REDIRECT_URI) holding the literal "None" or "" a .env file spells "unset" with, so truthiness checks and fallbacks downstream saw a value. One rule on the group base replaces those lists: every Optional[str] field maps "", "None" and whitespace to None and strips real values. Plain str fields are left alone. The OIDC required-settings check therefore also rejects those spellings. EMBEDDINGS_POOLING is Literal["cls", "mean"] with case-insensitive parsing; its consumer silently ignored anything else. Bounds added where the consumer rejects or misbehaves on the value: SCHEDULE_RUN_OUTPUT_RETENTION_DAYS and MESSAGE_EVENTS_RETENTION_DAYS (the cleanup repositories raise on <= 0), EMBEDDINGS_DELEGATE_TIMEOUT, the remote-device idle/pairing/invocation TTLs and CELERY_VISIBILITY_TIMEOUT (> 0), REMOTE_DEVICE_CMD_QUEUE_TTL_SECONDS (> 605, the documented drain deadline), GRAPHRAG_MAX_CHUNKS_FOR_EXTRACTION (>= 0; negative would slice the pending list from the end). The generated reference now renders generic type arguments (dict[str, int] rather than dict).
This commit is contained in:
1 parent
f882ef49a7
commit
5578039c19
13 files changed
+113
-67
No files matched your search
@@ -2,12 +2,12 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
from typing import Literal, Optional
|
||||
|
||||
from pydantic import Field, field_validator
|
||||
|
||||
from docsgpt.core.paths import home_dir
|
||||
from docsgpt.core.settings._shared import SettingsGroup, normalize_secret
|
||||
from docsgpt.core.settings._shared import SettingsGroup, normalize_choice
|
||||
|
||||
|
||||
class EmbeddingsSettings(SettingsGroup):
|
||||
@@ -56,7 +56,7 @@ class EmbeddingsSettings(SettingsGroup):
|
||||
"default is the temp dir."
|
||||
),
|
||||
)
|
||||
EMBEDDINGS_POOLING: Optional[str] = Field(
|
||||
EMBEDDINGS_POOLING: Optional[Literal["cls", "mean"]] = Field(
|
||||
default=None,
|
||||
description=(
|
||||
'Pooling strategy ("cls" or "mean"). Read from the model\'s own repository; set only for a '
|
||||
@@ -79,10 +79,10 @@ class EmbeddingsSettings(SettingsGroup):
|
||||
)
|
||||
EMBEDDINGS_QUEUE: str = Field(default="embeddings", description="Celery queue the embed task is routed to.")
|
||||
EMBEDDINGS_DELEGATE_TIMEOUT: int = Field(
|
||||
default=60, description="Seconds the API waits for the worker to return an embedding."
|
||||
default=60, gt=0, description="Seconds the API waits for the worker to return an embedding."
|
||||
)
|
||||
|
||||
@field_validator("EMBEDDINGS_KEY", mode="before")
|
||||
@field_validator("EMBEDDINGS_POOLING", mode="before")
|
||||
@classmethod
|
||||
def _normalize_embeddings_secrets(cls, v):
|
||||
return normalize_secret(v)
|
||||
def _normalize_pooling(cls, v):
|
||||
return normalize_choice(v)
|
||||
Reference in new issue
Block a user