Skip to content

Commit

Permalink
Respect .env and other config ins ettings
Browse files Browse the repository at this point in the history
  • Loading branch information
jlowin committed Nov 11, 2023
1 parent c1fd8fa commit d962fa2
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/marvin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit d962fa2

Please sign in to comment.