AppConfig.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import os
  2. from chromadb.utils import embedding_functions
  3. from .BaseAppConfig import BaseAppConfig
  4. class AppConfig(BaseAppConfig):
  5. """
  6. Config to initialize an embedchain custom `App` instance, with extra config options.
  7. """
  8. def __init__(self, log_level=None, host=None, port=None, id=None):
  9. """
  10. :param log_level: Optional. (String) Debug level
  11. ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'].
  12. :param id: Optional. ID of the app. Document metadata will have this id.
  13. :param host: Optional. Hostname for the database server.
  14. :param port: Optional. Port for the database server.
  15. """
  16. super().__init__(log_level=log_level, ef=AppConfig.default_embedding_function(), host=host, port=port, id=id)
  17. @staticmethod
  18. def default_embedding_function():
  19. """
  20. Sets embedding function to default (`text-embedding-ada-002`).
  21. :raises ValueError: If the template is not valid as template should contain
  22. $context and $query
  23. :returns: The default embedding function for the app class.
  24. """
  25. if os.getenv("OPENAI_API_KEY") is None and os.getenv("OPENAI_ORGANIZATION") is None:
  26. raise ValueError("OPENAI_API_KEY or OPENAI_ORGANIZATION environment variables not provided") # noqa:E501
  27. return embedding_functions.OpenAIEmbeddingFunction(
  28. api_key=os.getenv("OPENAI_API_KEY"),
  29. organization_id=os.getenv("OPENAI_ORGANIZATION"),
  30. model_name="text-embedding-ada-002",
  31. )