AppConfig.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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__(
  17. log_level=log_level, embedding_fn=AppConfig.default_embedding_function(), host=host, port=port, id=id
  18. )
  19. @staticmethod
  20. def default_embedding_function():
  21. """
  22. Sets embedding function to default (`text-embedding-ada-002`).
  23. :raises ValueError: If the template is not valid as template should contain
  24. $context and $query
  25. :returns: The default embedding function for the app class.
  26. """
  27. if os.getenv("OPENAI_API_KEY") is None and os.getenv("OPENAI_ORGANIZATION") is None:
  28. raise ValueError("OPENAI_API_KEY or OPENAI_ORGANIZATION environment variables not provided") # noqa:E501
  29. return embedding_functions.OpenAIEmbeddingFunction(
  30. api_key=os.getenv("OPENAI_API_KEY"),
  31. organization_id=os.getenv("OPENAI_ORGANIZATION"),
  32. model_name="text-embedding-ada-002",
  33. )