base.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. from embedchain import CustomApp
  2. from embedchain.config import AddConfig, CustomAppConfig, QueryConfig
  3. from embedchain.helper_classes.json_serializable import (
  4. JSONSerializable, register_deserializable)
  5. from embedchain.models import EmbeddingFunctions, Providers
  6. @register_deserializable
  7. class BaseBot(JSONSerializable):
  8. def __init__(self, app_config=None):
  9. if app_config is None:
  10. app_config = CustomAppConfig(embedding_fn=EmbeddingFunctions.OPENAI, provider=Providers.OPENAI)
  11. self.app_config = app_config
  12. self.app = CustomApp(config=self.app_config)
  13. def add(self, data, config: AddConfig = None):
  14. """Add data to the bot"""
  15. config = config if config else AddConfig()
  16. self.app.add(data, config=config)
  17. def query(self, query, config: QueryConfig = None):
  18. """Query bot"""
  19. config = config if config else QueryConfig()
  20. return self.app.query(query, config=config)
  21. def start(self):
  22. """Start the bot's functionality."""
  23. raise NotImplementedError("Subclasses must implement the start method.")