OpenSourceAppConfig.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from typing import Optional
  2. from chromadb.utils import embedding_functions
  3. from .BaseAppConfig import BaseAppConfig
  4. class OpenSourceAppConfig(BaseAppConfig):
  5. """
  6. Config to initialize an embedchain custom `OpenSourceApp` instance, with extra config options.
  7. """
  8. def __init__(
  9. self,
  10. log_level=None,
  11. host=None,
  12. port=None,
  13. id=None,
  14. collection_name=None,
  15. collect_metrics: Optional[bool] = None,
  16. model=None,
  17. ):
  18. """
  19. :param log_level: Optional. (String) Debug level
  20. ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'].
  21. :param id: Optional. ID of the app. Document metadata will have this id.
  22. :param collection_name: Optional. Collection name for the database.
  23. :param host: Optional. Hostname for the database server.
  24. :param port: Optional. Port for the database server.
  25. :param collect_metrics: Defaults to True. Send anonymous telemetry to improve embedchain.
  26. :param model: Optional. GPT4ALL uses the model to instantiate the class.
  27. So unlike `App`, it has to be provided before querying.
  28. """
  29. self.model = model or "orca-mini-3b.ggmlv3.q4_0.bin"
  30. super().__init__(
  31. log_level=log_level,
  32. embedding_fn=OpenSourceAppConfig.default_embedding_function(),
  33. host=host,
  34. port=port,
  35. id=id,
  36. collection_name=collection_name,
  37. collect_metrics=collect_metrics,
  38. )
  39. @staticmethod
  40. def default_embedding_function():
  41. """
  42. Sets embedding function to default (`all-MiniLM-L6-v2`).
  43. :returns: The default embedding function
  44. """
  45. try:
  46. return embedding_functions.SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2")
  47. except ValueError as e:
  48. print(e)
  49. raise ModuleNotFoundError(
  50. "The open source app requires extra dependencies. Install with `pip install embedchain[opensource]`"
  51. ) from None