config.py 3.1 KB

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