Skip to content

Commit

Permalink
Use lazy decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Aug 19, 2024
1 parent 83f5e80 commit 417b442
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions griptape/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from attrs import define, field

from griptape.utils.decorators import lazy_property

from .base_config import BaseConfig
from .drivers.openai_driver_config import OpenAiDriverConfig
from .logging.logging_config import LoggingConfig
Expand All @@ -17,26 +19,13 @@ class _Config(BaseConfig):
_logging_config: Optional[LoggingConfig] = field(default=None, alias="logging")
_driver_config: Optional[BaseDriverConfig] = field(default=None, alias="drivers")

@property
@lazy_property()
def driver_config(self) -> BaseDriverConfig:
"""Lazily instantiates the drivers configuration to avoid client errors like missing API key."""
if self._driver_config is None:
self._driver_config = OpenAiDriverConfig()
return self._driver_config

@driver_config.setter
def driver_config(self, drivers: BaseDriverConfig) -> None:
self._driver_config = drivers
return OpenAiDriverConfig()

@property
@lazy_property()
def logging_config(self) -> LoggingConfig:
if self._logging_config is None:
self._logging_config = LoggingConfig()
return self._logging_config

@logging_config.setter
def logging_config(self, logging: LoggingConfig) -> None:
self._logging_config = logging
return LoggingConfig()


config = _Config()

0 comments on commit 417b442

Please sign in to comment.