config.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. # Cache DIR
  29. ####################################
  30. CACHE_DIR = f"{DATA_DIR}/cache"
  31. Path(CACHE_DIR).mkdir(parents=True, exist_ok=True)
  32. ####################################
  33. # OLLAMA_API_BASE_URL
  34. ####################################
  35. OLLAMA_API_BASE_URL = os.environ.get(
  36. "OLLAMA_API_BASE_URL", "http://localhost:11434/api"
  37. )
  38. if ENV == "prod":
  39. if OLLAMA_API_BASE_URL == "/ollama/api":
  40. OLLAMA_API_BASE_URL = "http://host.docker.internal:11434/api"
  41. ####################################
  42. # OPENAI_API
  43. ####################################
  44. OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "")
  45. OPENAI_API_BASE_URL = os.environ.get("OPENAI_API_BASE_URL", "")
  46. if OPENAI_API_BASE_URL == "":
  47. OPENAI_API_BASE_URL = "https://api.openai.com/v1"
  48. ####################################
  49. # WEBUI
  50. ####################################
  51. ENABLE_SIGNUP = os.environ.get("ENABLE_SIGNUP", True)
  52. DEFAULT_MODELS = os.environ.get("DEFAULT_MODELS", None)
  53. DEFAULT_PROMPT_SUGGESTIONS = os.environ.get(
  54. "DEFAULT_PROMPT_SUGGESTIONS",
  55. [
  56. {
  57. "title": ["Help me study", "vocabulary for a college entrance exam"],
  58. "content": "Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option.",
  59. },
  60. {
  61. "title": ["Give me ideas", "for what to do with my kids' art"],
  62. "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.",
  63. },
  64. {
  65. "title": ["Tell me a fun fact", "about the Roman Empire"],
  66. "content": "Tell me a random fun fact about the Roman Empire",
  67. },
  68. {
  69. "title": ["Show me a code snippet", "of a website's sticky header"],
  70. "content": "Show me a code snippet of a website's sticky header in CSS and JavaScript.",
  71. },
  72. ],
  73. )
  74. DEFAULT_USER_ROLE = "pending"
  75. USER_PERMISSIONS = {"chat": {"deletion": True}}
  76. ####################################
  77. # WEBUI_VERSION
  78. ####################################
  79. WEBUI_VERSION = os.environ.get("WEBUI_VERSION", "v1.0.0-alpha.100")
  80. ####################################
  81. # WEBUI_AUTH (Required for security)
  82. ####################################
  83. WEBUI_AUTH = True
  84. ####################################
  85. # WEBUI_SECRET_KEY
  86. ####################################
  87. WEBUI_SECRET_KEY = os.environ.get(
  88. "WEBUI_SECRET_KEY",
  89. os.environ.get(
  90. "WEBUI_JWT_SECRET_KEY", "t0p-s3cr3t"
  91. ), # DEPRECATED: remove at next major version
  92. )
  93. if WEBUI_AUTH and WEBUI_SECRET_KEY == "":
  94. raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND)
  95. ####################################
  96. # RAG
  97. ####################################
  98. CHROMA_DATA_PATH = f"{DATA_DIR}/vector_db"
  99. EMBED_MODEL = "all-MiniLM-L6-v2"
  100. CHROMA_CLIENT = chromadb.PersistentClient(
  101. path=CHROMA_DATA_PATH,
  102. settings=Settings(allow_reset=True, anonymized_telemetry=False),
  103. )
  104. CHUNK_SIZE = 1500
  105. CHUNK_OVERLAP = 100
  106. ####################################
  107. # Transcribe
  108. ####################################
  109. WHISPER_MODEL = os.getenv("WHISPER_MODEL", "base")
  110. WHISPER_MODEL_DIR = os.getenv("WHISPER_MODEL_DIR", f"{CACHE_DIR}/whisper/models")