Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: custom complex types #222

Open
gsakkis opened this issue Jan 26, 2024 · 0 comments
Open

Feature request: custom complex types #222

gsakkis opened this issue Jan 26, 2024 · 0 comments
Assignees

Comments

@gsakkis
Copy link

gsakkis commented Jan 26, 2024

Currently pydantic-settings determines whether a field is "complex" (nested) or not based on its annotation as follows:

def _annotation_is_complex_inner(annotation: type[Any] | None) -> bool:
    if lenient_issubclass(annotation, (str, bytes)):
        return False

    return lenient_issubclass(annotation, (BaseModel, Mapping, Sequence, tuple, set, frozenset, deque)) or is_dataclass(
        annotation
    )

It would be convenient if one could register other settings-like types as complex (either per model or globally) so that nested env variable explosion works. Case in point, a GenerationConfig from Hugging Face transformers.

Draft API:

class TransfomerModelSettings(BaseSettings):
    model_config = SettingsConfigDict(
        env_prefix="model__", complex_annotations=(GenerationConfig,)
    )

    name_or_path: str
    generation_settings: GenerationConfig = GenerationConfig()

Then one could pass via env vars any of the dozens GenerationConfig fields:

export model__name_or_path=foo 
export model__max_new_tokens=123
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants