custom_app.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import logging
  2. from typing import Optional
  3. from embedchain.apps.app import App
  4. from embedchain.config import CustomAppConfig
  5. from embedchain.embedder.base import BaseEmbedder
  6. from embedchain.helper.json_serializable import register_deserializable
  7. from embedchain.llm.base import BaseLlm
  8. from embedchain.vectordb.base import BaseVectorDB
  9. @register_deserializable
  10. class CustomApp(App):
  11. """
  12. Embedchain's custom app allows for most flexibility.
  13. You can craft your own mix of various LLMs, vector databases and embedding model/functions.
  14. Methods:
  15. add(source, data_type): adds the data from the given URL to the vector db.
  16. query(query): finds answer to the given query using vector database and LLM.
  17. chat(query): finds answer to the given query using vector database and LLM, with conversation history.
  18. .. deprecated:: 0.0.64
  19. Use `App` instead.
  20. """
  21. def __init__(
  22. self,
  23. config: Optional[CustomAppConfig] = None,
  24. llm: BaseLlm = None,
  25. db: BaseVectorDB = None,
  26. embedder: BaseEmbedder = None,
  27. system_prompt: Optional[str] = None,
  28. ):
  29. """
  30. Initialize a new `CustomApp` instance. You have to choose a LLM, database and embedder.
  31. .. deprecated:: 0.0.64
  32. Use `App` instead.
  33. :param config: Config for the app instance. This is the most basic configuration,
  34. that does not fall into the LLM, database or embedder category, defaults to None
  35. :type config: Optional[CustomAppConfig], optional
  36. :param llm: LLM Class instance. example: `from embedchain.llm.openai import OpenAILlm`, defaults to None
  37. :type llm: BaseLlm
  38. :param db: The database to use for storing and retrieving embeddings,
  39. example: `from embedchain.vectordb.chroma_db import ChromaDb`, defaults to None
  40. :type db: BaseVectorDB
  41. :param embedder: The embedder (embedding model and function) use to calculate embeddings.
  42. example: `from embedchain.embedder.gpt4all_embedder import GPT4AllEmbedder`, defaults to None
  43. :type embedder: BaseEmbedder
  44. :param system_prompt: System prompt that will be provided to the LLM as such, defaults to None
  45. :type system_prompt: Optional[str], optional
  46. :raises ValueError: LLM, database or embedder has not been defined.
  47. :raises TypeError: LLM, database or embedder is not a valid class instance.
  48. """
  49. logging.warning(
  50. "DEPRECATION WARNING: Please use `App` instead of `CustomApp`. "
  51. "`CustomApp` will be removed in a future release. "
  52. "Please refer to https://docs.embedchain.ai/advanced/app_types#opensourceapp for instructions."
  53. )
  54. super().__init__(config=config, llm=llm, db=db, embedder=embedder, system_prompt=system_prompt)