config.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import os
  2. import chromadb
  3. from chromadb import Settings
  4. from secrets import token_bytes
  5. from base64 import b64encode
  6. from constants import ERROR_MESSAGES
  7. from pathlib import Path
  8. try:
  9. from dotenv import load_dotenv, find_dotenv
  10. load_dotenv(find_dotenv("../.env"))
  11. except ImportError:
  12. print("dotenv not installed, skipping...")
  13. ####################################
  14. # ENV (dev,test,prod)
  15. ####################################
  16. ENV = os.environ.get("ENV", "dev")
  17. ####################################
  18. # DATA/FRONTEND BUILD DIR
  19. ####################################
  20. DATA_DIR = str(Path(os.getenv("DATA_DIR", "./data")).resolve())
  21. FRONTEND_BUILD_DIR = str(Path(os.getenv("FRONTEND_BUILD_DIR", "../build")))
  22. ####################################
  23. # File Upload DIR
  24. ####################################
  25. UPLOAD_DIR = f"{DATA_DIR}/uploads"
  26. Path(UPLOAD_DIR).mkdir(parents=True, exist_ok=True)
  27. ####################################
  28. # OLLAMA_API_BASE_URL
  29. ####################################
  30. OLLAMA_API_BASE_URL = os.environ.get(
  31. "OLLAMA_API_BASE_URL", "http://localhost:11434/api"
  32. )
  33. if ENV == "prod":
  34. if OLLAMA_API_BASE_URL == "/ollama/api":
  35. OLLAMA_API_BASE_URL = "http://host.docker.internal:11434/api"
  36. ####################################
  37. # OPENAI_API
  38. ####################################
  39. OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "")
  40. OPENAI_API_BASE_URL = os.environ.get("OPENAI_API_BASE_URL", "")
  41. if OPENAI_API_BASE_URL == "":
  42. OPENAI_API_BASE_URL = "https://api.openai.com/v1"
  43. ####################################
  44. # WEBUI
  45. ####################################
  46. DEFAULT_MODELS = os.environ.get("DEFAULT_MODELS", None)
  47. DEFAULT_PROMPT_SUGGESTIONS = os.environ.get(
  48. "DEFAULT_PROMPT_SUGGESTIONS",
  49. [
  50. {
  51. "title": ["Help me study", "vocabulary for a college entrance exam"],
  52. "content": "Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option.",
  53. },
  54. {
  55. "title": ["Give me ideas", "for what to do with my kids' art"],
  56. "content": "What are 5 creative things I could do with my kids' art? I don't want to throw them away, but it's also so much clutter.",
  57. },
  58. {
  59. "title": ["Tell me a fun fact", "about the Roman Empire"],
  60. "content": "Tell me a random fun fact about the Roman Empire",
  61. },
  62. {
  63. "title": ["Show me a code snippet", "of a website's sticky header"],
  64. "content": "Show me a code snippet of a website's sticky header in CSS and JavaScript.",
  65. },
  66. ],
  67. )
  68. ####################################
  69. # WEBUI_VERSION
  70. ####################################
  71. WEBUI_VERSION = os.environ.get("WEBUI_VERSION", "v1.0.0-alpha.61")
  72. ####################################
  73. # WEBUI_AUTH (Required for security)
  74. ####################################
  75. WEBUI_AUTH = True
  76. ####################################
  77. # WEBUI_JWT_SECRET_KEY
  78. ####################################
  79. WEBUI_JWT_SECRET_KEY = os.environ.get("WEBUI_JWT_SECRET_KEY", "t0p-s3cr3t")
  80. if WEBUI_AUTH and WEBUI_JWT_SECRET_KEY == "":
  81. raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND)
  82. ####################################
  83. # RAG
  84. ####################################
  85. CHROMA_DATA_PATH = f"{DATA_DIR}/vector_db"
  86. EMBED_MODEL = "all-MiniLM-L6-v2"
  87. CHROMA_CLIENT = chromadb.PersistentClient(
  88. path=CHROMA_DATA_PATH, settings=Settings(allow_reset=True)
  89. )
  90. CHUNK_SIZE = 1500
  91. CHUNK_OVERLAP = 100