open_source_app.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import logging
  2. from typing import Optional
  3. from embedchain.apps.app import App
  4. from embedchain.config import (BaseLlmConfig, ChromaDbConfig,
  5. OpenSourceAppConfig)
  6. from embedchain.embedder.gpt4all import GPT4AllEmbedder
  7. from embedchain.helper.json_serializable import register_deserializable
  8. from embedchain.llm.gpt4all import GPT4ALLLlm
  9. from embedchain.vectordb.chroma import ChromaDB
  10. gpt4all_model = None
  11. @register_deserializable
  12. class OpenSourceApp(App):
  13. """
  14. The embedchain Open Source App.
  15. Comes preconfigured with the best open source LLM, embedding model, database.
  16. Methods:
  17. add(source, data_type): adds the data from the given URL to the vector db.
  18. query(query): finds answer to the given query using vector database and LLM.
  19. chat(query): finds answer to the given query using vector database and LLM, with conversation history.
  20. .. deprecated:: 0.0.64
  21. Use `App` instead.
  22. """
  23. def __init__(
  24. self,
  25. config: OpenSourceAppConfig = None,
  26. llm_config: BaseLlmConfig = None,
  27. chromadb_config: Optional[ChromaDbConfig] = None,
  28. system_prompt: Optional[str] = None,
  29. ):
  30. """
  31. Initialize a new `CustomApp` instance.
  32. Since it's opinionated you don't have to choose a LLM, database and embedder.
  33. However, you can configure those.
  34. .. deprecated:: 0.0.64
  35. Use `App` instead.
  36. :param config: Config for the app instance. This is the most basic configuration,
  37. that does not fall into the LLM, database or embedder category, defaults to None
  38. :type config: OpenSourceAppConfig, optional
  39. :param llm_config: Allows you to configure the LLM, e.g. how many documents to return.
  40. example: `from embedchain.config import LlmConfig`, defaults to None
  41. :type llm_config: BaseLlmConfig, optional
  42. :param chromadb_config: Allows you to configure the open source database,
  43. example: `from embedchain.config import ChromaDbConfig`, defaults to None
  44. :type chromadb_config: Optional[ChromaDbConfig], optional
  45. :param system_prompt: System prompt that will be provided to the LLM as such.
  46. Please don't use for the time being, as it's not supported., defaults to None
  47. :type system_prompt: Optional[str], optional
  48. :raises TypeError: `OpenSourceAppConfig` or `LlmConfig` invalid.
  49. """
  50. logging.warning(
  51. "DEPRECATION WARNING: Please use `App` instead of `OpenSourceApp`."
  52. "`OpenSourceApp` will be removed in a future release."
  53. "Please refer to https://docs.embedchain.ai/advanced/app_types#customapp for instructions."
  54. )
  55. super().__init__(
  56. config=config,
  57. llm=GPT4ALLLlm(config=llm_config),
  58. db=ChromaDB(config=chromadb_config),
  59. embedder=GPT4AllEmbedder(),
  60. system_prompt=system_prompt,
  61. )