base_app_config.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import logging
  2. from typing import Optional
  3. from embedchain.config.base_config import BaseConfig
  4. from embedchain.helpers.json_serializable import JSONSerializable
  5. from embedchain.vectordb.base import BaseVectorDB
  6. class BaseAppConfig(BaseConfig, JSONSerializable):
  7. """
  8. Parent config to initialize an instance of `App`.
  9. """
  10. def __init__(
  11. self,
  12. log_level: str = "WARNING",
  13. db: Optional[BaseVectorDB] = None,
  14. id: Optional[str] = None,
  15. collect_metrics: bool = True,
  16. collection_name: Optional[str] = None,
  17. ):
  18. """
  19. Initializes a configuration class instance for an App.
  20. Most of the configuration is done in the `App` class itself.
  21. :param log_level: Debug level ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], defaults to "WARNING"
  22. :type log_level: str, optional
  23. :param db: A database class. It is recommended to set this directly in the `App` class, not this config,
  24. defaults to None
  25. :type db: Optional[BaseVectorDB], optional
  26. :param id: ID of the app. Document metadata will have this id., defaults to None
  27. :type id: Optional[str], optional
  28. :param collect_metrics: Send anonymous telemetry to improve embedchain, defaults to True
  29. :type collect_metrics: Optional[bool], optional
  30. :param collection_name: Default collection name. It's recommended to use app.db.set_collection_name() instead,
  31. defaults to None
  32. :type collection_name: Optional[str], optional
  33. """
  34. self.id = id
  35. self.collect_metrics = True if (collect_metrics is True or collect_metrics is None) else False
  36. self.collection_name = collection_name
  37. if db:
  38. self._db = db
  39. logging.warning(
  40. "DEPRECATION WARNING: Please supply the database as the second parameter during app init. "
  41. "Such as `app(config=config, db=db)`."
  42. )
  43. if collection_name:
  44. logging.warning("DEPRECATION WARNING: Please supply the collection name to the database config.")
  45. return
  46. def _setup_logging(self, log_level):
  47. logging.basicConfig(format="%(asctime)s [%(name)s] [%(levelname)s] %(message)s", level=log_level)
  48. self.logger = logging.getLogger(__name__)