app.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from typing import Optional
  2. from embedchain.config import (AppConfig, BaseEmbedderConfig, BaseLlmConfig,
  3. ChromaDbConfig)
  4. from embedchain.embedchain import EmbedChain
  5. from embedchain.embedder.openai import OpenAIEmbedder
  6. from embedchain.helper.json_serializable import register_deserializable
  7. from embedchain.llm.openai import OpenAILlm
  8. from embedchain.vectordb.chroma import ChromaDB
  9. @register_deserializable
  10. class App(EmbedChain):
  11. """
  12. The EmbedChain app in it's simplest and most straightforward form.
  13. An opinionated choice of LLM, vector database and embedding model.
  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. """
  19. def __init__(
  20. self,
  21. config: AppConfig = None,
  22. llm_config: BaseLlmConfig = None,
  23. chromadb_config: Optional[ChromaDbConfig] = None,
  24. system_prompt: Optional[str] = None,
  25. ):
  26. """
  27. Initialize a new `CustomApp` instance. You only have a few choices to make.
  28. :param config: Config for the app instance.
  29. This is the most basic configuration, that does not fall into the LLM, database or embedder category,
  30. defaults to None
  31. :type config: AppConfig, optional
  32. :param llm_config: Allows you to configure the LLM, e.g. how many documents to return,
  33. example: `from embedchain.config import LlmConfig`, defaults to None
  34. :type llm_config: BaseLlmConfig, optional
  35. :param chromadb_config: Allows you to configure the vector database,
  36. example: `from embedchain.config import ChromaDbConfig`, defaults to None
  37. :type chromadb_config: Optional[ChromaDbConfig], optional
  38. :param system_prompt: System prompt that will be provided to the LLM as such, defaults to None
  39. :type system_prompt: Optional[str], optional
  40. """
  41. if config is None:
  42. config = AppConfig()
  43. llm = OpenAILlm(config=llm_config)
  44. embedder = OpenAIEmbedder(config=BaseEmbedderConfig(model="text-embedding-ada-002"))
  45. database = ChromaDB(config=chromadb_config)
  46. super().__init__(config, llm, db=database, embedder=embedder, system_prompt=system_prompt)