From d962fa2bdce883075b8b79a845c38598623b822b Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Fri, 10 Nov 2023 20:50:41 -0500 Subject: [PATCH] Respect .env and other config ins ettings --- src/marvin/settings.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/marvin/settings.py b/src/marvin/settings.py index 43c26e399..5e116f380 100644 --- a/src/marvin/settings.py +++ b/src/marvin/settings.py @@ -2,30 +2,32 @@ from contextlib import contextmanager from typing import Any, Optional -from pydantic import BaseModel, ConfigDict, Field, SecretStr +from pydantic import Field, SecretStr from pydantic_settings import BaseSettings, SettingsConfigDict -class ChatCompletionSettings(BaseModel): +class MarvinSettings(BaseSettings): + model_config = SettingsConfigDict( + env_prefix="marvin_", + env_file="~/.marvin/.env", + extra="allow", + arbitrary_types_allowed=True, + ) + + +class ChatCompletionSettings(MarvinSettings): model: str = Field( default="gpt-4-1106-preview", description="The default chat model to use.", ) - model_config = ConfigDict( - extra="allow", - arbitrary_types_allowed=True, - ) - -class ChatSettings(BaseSettings): +class ChatSettings(MarvinSettings): completions: ChatCompletionSettings = Field(default_factory=ChatCompletionSettings) -class OpenAISettings(BaseSettings): - model_config = SettingsConfigDict( - env_prefix="marvin_openai_", env_file="~/.marvin/.env" - ) +class OpenAISettings(MarvinSettings): + model_config = SettingsConfigDict(env_prefix="marvin_openai_") api_key: Optional[SecretStr] = Field( default=None, @@ -40,7 +42,7 @@ class OpenAISettings(BaseSettings): chat: ChatSettings = Field(default_factory=ChatSettings) -class Settings(BaseSettings): +class Settings(MarvinSettings): model_config = SettingsConfigDict(env_prefix="marvin_") openai: OpenAISettings = Field(default_factory=OpenAISettings)