configuration.mdx 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ---
  2. title: '⚙️ Custom configurations'
  3. ---
  4. Embedchain is made to work out of the box. However, for advanced users we're also offering configuration options. All of these configuration options are optional and have sane defaults.
  5. ## Examples
  6. ### General
  7. Here's the readme example with configuration options.
  8. ```python
  9. import os
  10. from embedchain import App
  11. from embedchain.config import AppConfig, AddConfig, QueryConfig, ChunkerConfig
  12. from chromadb.utils import embedding_functions
  13. # Example: set the log level for debugging
  14. config = AppConfig(log_level="DEBUG")
  15. naval_chat_bot = App(config)
  16. # Example: specify a custom collection name
  17. config = AppConfig(collection_name="naval_chat_bot")
  18. naval_chat_bot = App(config)
  19. # Example: define your own chunker config for `youtube_video`
  20. chunker_config = ChunkerConfig(chunk_size=1000, chunk_overlap=100, length_function=len)
  21. naval_chat_bot.add("youtube_video", "https://www.youtube.com/watch?v=3qHkcs3kG44", AddConfig(chunker=chunker_config))
  22. add_config = AddConfig()
  23. naval_chat_bot.add("pdf_file", "https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf", add_config)
  24. naval_chat_bot.add("web_page", "https://nav.al/feedback", add_config)
  25. naval_chat_bot.add("web_page", "https://nav.al/agi", add_config)
  26. naval_chat_bot.add_local("qna_pair", ("Who is Naval Ravikant?", "Naval Ravikant is an Indian-American entrepreneur and investor."), add_config)
  27. query_config = QueryConfig()
  28. print(naval_chat_bot.query("What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?", query_config))
  29. ```
  30. ### Custom prompt template
  31. Here's the example of using custom prompt template with `.query`
  32. ```python
  33. from embedchain.config import QueryConfig
  34. from embedchain.embedchain import App
  35. from string import Template
  36. import wikipedia
  37. einstein_chat_bot = App()
  38. # Embed Wikipedia page
  39. page = wikipedia.page("Albert Einstein")
  40. einstein_chat_bot.add("text", page.content)
  41. # Example: use your own custom template with `$context` and `$query`
  42. einstein_chat_template = Template("""
  43. You are Albert Einstein, a German-born theoretical physicist,
  44. widely ranked among the greatest and most influential scientists of all time.
  45. Use the following information about Albert Einstein to respond to
  46. the human's query acting as Albert Einstein.
  47. Context: $context
  48. Keep the response brief. If you don't know the answer, just say that you don't know, don't try to make up an answer.
  49. Human: $query
  50. Albert Einstein:""")
  51. query_config = QueryConfig(template=einstein_chat_template)
  52. queries = [
  53. "Where did you complete your studies?",
  54. "Why did you win nobel prize?",
  55. "Why did you divorce your first wife?",
  56. ]
  57. for query in queries:
  58. response = einstein_chat_bot.query(query, query_config)
  59. print("Query: ", query)
  60. print("Response: ", response)
  61. # Output
  62. # Query: Where did you complete your studies?
  63. # Response: I completed my secondary education at the Argovian cantonal school in Aarau, Switzerland.
  64. # Query: Why did you win nobel prize?
  65. # Response: I won the Nobel Prize in Physics in 1921 for my services to Theoretical Physics, particularly for my discovery of the law of the photoelectric effect.
  66. # Query: Why did you divorce your first wife?
  67. # Response: We divorced due to living apart for five years.
  68. ```