test_apps.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import os
  2. import unittest
  3. from embedchain import App, CustomApp, Llama2App, OpenSourceApp
  4. from embedchain.config import ChromaDbConfig
  5. from embedchain.embedder.base import BaseEmbedder
  6. from embedchain.llm.base import BaseLlm
  7. from embedchain.vectordb.base import BaseVectorDB
  8. from embedchain.vectordb.chroma import ChromaDB
  9. class TestApps(unittest.TestCase):
  10. try:
  11. del os.environ["OPENAI_KEY"]
  12. except KeyError:
  13. pass
  14. def test_app(self):
  15. app = App()
  16. self.assertIsInstance(app.llm, BaseLlm)
  17. self.assertIsInstance(app.db, BaseVectorDB)
  18. self.assertIsInstance(app.embedder, BaseEmbedder)
  19. def test_custom_app(self):
  20. app = CustomApp()
  21. self.assertIsInstance(app.llm, BaseLlm)
  22. self.assertIsInstance(app.db, BaseVectorDB)
  23. self.assertIsInstance(app.embedder, BaseEmbedder)
  24. def test_opensource_app(self):
  25. app = OpenSourceApp()
  26. self.assertIsInstance(app.llm, BaseLlm)
  27. self.assertIsInstance(app.db, BaseVectorDB)
  28. self.assertIsInstance(app.embedder, BaseEmbedder)
  29. def test_llama2_app(self):
  30. os.environ["REPLICATE_API_TOKEN"] = "-"
  31. app = Llama2App()
  32. self.assertIsInstance(app.llm, BaseLlm)
  33. self.assertIsInstance(app.db, BaseVectorDB)
  34. self.assertIsInstance(app.embedder, BaseEmbedder)
  35. class TestConfigForAppComponents(unittest.TestCase):
  36. collection_name = "my-test-collection"
  37. def test_constructor_config(self):
  38. """
  39. Test that app can be configured through the app constructor.
  40. """
  41. app = App(db_config=ChromaDbConfig(collection_name=self.collection_name))
  42. self.assertEqual(app.db.config.collection_name, self.collection_name)
  43. def test_component_config(self):
  44. """
  45. Test that app can also be configured by passing a configured component to the app
  46. """
  47. database = ChromaDB(config=ChromaDbConfig(collection_name=self.collection_name))
  48. app = App(db=database)
  49. self.assertEqual(app.db.config.collection_name, self.collection_name)