BaseAppConfig.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import logging
  2. from typing import Optional
  3. from embedchain.config.BaseConfig import BaseConfig
  4. from embedchain.helper_classes.json_serializable import JSONSerializable
  5. from embedchain.vectordb.base_vector_db import BaseVectorDB
  6. class BaseAppConfig(BaseConfig, JSONSerializable):
  7. """
  8. Parent config to initialize an instance of `App`, `OpenSourceApp` or `CustomApp`.
  9. """
  10. def __init__(
  11. self,
  12. log_level=None,
  13. db: Optional[BaseVectorDB] = None,
  14. id=None,
  15. collect_metrics: bool = True,
  16. collection_name: Optional[str] = None,
  17. ):
  18. """
  19. :param log_level: Optional. (String) Debug level
  20. ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'].
  21. :param db: Optional. (Vector) database instance to use for embeddings. Deprecated in favor of app(..., db).
  22. :param id: Optional. ID of the app. Document metadata will have this id.
  23. :param collect_metrics: Defaults to True. Send anonymous telemetry to improve embedchain.
  24. :param db_type: Optional. Initializes a default vector database of the given type.
  25. Using the `db` argument is preferred.
  26. :param es_config: Optional. elasticsearch database config to be used for connection
  27. :param collection_name: Optional. Default collection name.
  28. It's recommended to use app.set_collection_name() instead.
  29. """
  30. self._setup_logging(log_level)
  31. self.id = id
  32. self.collect_metrics = True if (collect_metrics is True or collect_metrics is None) else False
  33. self.collection_name = collection_name
  34. if db:
  35. self._db = db
  36. logging.warning(
  37. "DEPRECATION WARNING: Please supply the database as the second parameter during app init. "
  38. "Such as `app(config=config, db=db)`."
  39. )
  40. if collection_name:
  41. logging.warning("DEPRECATION WARNING: Please supply the collection name to the database config.")
  42. return
  43. def _setup_logging(self, debug_level):
  44. level = logging.WARNING # Default level
  45. if debug_level is not None:
  46. level = getattr(logging, debug_level.upper(), None)
  47. if not isinstance(level, int):
  48. raise ValueError(f"Invalid log level: {debug_level}")
  49. logging.basicConfig(format="%(asctime)s [%(name)s] [%(levelname)s] %(message)s", level=level)
  50. self.logger = logging.getLogger(__name__)
  51. return