base_app_config.py 2.3 KB

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