config.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. import os
  2. import sys
  3. import logging
  4. import chromadb
  5. from chromadb import Settings
  6. from base64 import b64encode
  7. from bs4 import BeautifulSoup
  8. from pathlib import Path
  9. import json
  10. import yaml
  11. import markdown
  12. import requests
  13. import shutil
  14. from secrets import token_bytes
  15. from constants import ERROR_MESSAGES
  16. ####################################
  17. # Load .env file
  18. ####################################
  19. try:
  20. from dotenv import load_dotenv, find_dotenv
  21. load_dotenv(find_dotenv("../.env"))
  22. except ImportError:
  23. print("dotenv not installed, skipping...")
  24. ####################################
  25. # LOGGING
  26. ####################################
  27. log_levels = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]
  28. GLOBAL_LOG_LEVEL = os.environ.get("GLOBAL_LOG_LEVEL", "").upper()
  29. if GLOBAL_LOG_LEVEL in log_levels:
  30. logging.basicConfig(stream=sys.stdout, level=GLOBAL_LOG_LEVEL, force=True)
  31. else:
  32. GLOBAL_LOG_LEVEL = "INFO"
  33. log = logging.getLogger(__name__)
  34. log.info(f"GLOBAL_LOG_LEVEL: {GLOBAL_LOG_LEVEL}")
  35. log_sources = [
  36. "AUDIO",
  37. "COMFYUI",
  38. "CONFIG",
  39. "DB",
  40. "IMAGES",
  41. "LITELLM",
  42. "MAIN",
  43. "MODELS",
  44. "OLLAMA",
  45. "OPENAI",
  46. "RAG",
  47. "WEBHOOK",
  48. ]
  49. SRC_LOG_LEVELS = {}
  50. for source in log_sources:
  51. log_env_var = source + "_LOG_LEVEL"
  52. SRC_LOG_LEVELS[source] = os.environ.get(log_env_var, "").upper()
  53. if SRC_LOG_LEVELS[source] not in log_levels:
  54. SRC_LOG_LEVELS[source] = GLOBAL_LOG_LEVEL
  55. log.info(f"{log_env_var}: {SRC_LOG_LEVELS[source]}")
  56. log.setLevel(SRC_LOG_LEVELS["CONFIG"])
  57. WEBUI_NAME = os.environ.get("WEBUI_NAME", "Open WebUI")
  58. if WEBUI_NAME != "Open WebUI":
  59. WEBUI_NAME += " (Open WebUI)"
  60. WEBUI_URL = os.environ.get("WEBUI_URL", "http://localhost:3000")
  61. WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png"
  62. ####################################
  63. # ENV (dev,test,prod)
  64. ####################################
  65. ENV = os.environ.get("ENV", "dev")
  66. try:
  67. with open(f"../package.json", "r") as f:
  68. PACKAGE_DATA = json.load(f)
  69. except:
  70. PACKAGE_DATA = {"version": "0.0.0"}
  71. VERSION = PACKAGE_DATA["version"]
  72. # Function to parse each section
  73. def parse_section(section):
  74. items = []
  75. for li in section.find_all("li"):
  76. # Extract raw HTML string
  77. raw_html = str(li)
  78. # Extract text without HTML tags
  79. text = li.get_text(separator=" ", strip=True)
  80. # Split into title and content
  81. parts = text.split(": ", 1)
  82. title = parts[0].strip() if len(parts) > 1 else ""
  83. content = parts[1].strip() if len(parts) > 1 else text
  84. items.append({"title": title, "content": content, "raw": raw_html})
  85. return items
  86. try:
  87. with open("../CHANGELOG.md", "r") as file:
  88. changelog_content = file.read()
  89. except:
  90. changelog_content = ""
  91. # Convert markdown content to HTML
  92. html_content = markdown.markdown(changelog_content)
  93. # Parse the HTML content
  94. soup = BeautifulSoup(html_content, "html.parser")
  95. # Initialize JSON structure
  96. changelog_json = {}
  97. # Iterate over each version
  98. for version in soup.find_all("h2"):
  99. version_number = version.get_text().strip().split(" - ")[0][1:-1] # Remove brackets
  100. date = version.get_text().strip().split(" - ")[1]
  101. version_data = {"date": date}
  102. # Find the next sibling that is a h3 tag (section title)
  103. current = version.find_next_sibling()
  104. while current and current.name != "h2":
  105. if current.name == "h3":
  106. section_title = current.get_text().lower() # e.g., "added", "fixed"
  107. section_items = parse_section(current.find_next_sibling("ul"))
  108. version_data[section_title] = section_items
  109. # Move to the next element
  110. current = current.find_next_sibling()
  111. changelog_json[version_number] = version_data
  112. CHANGELOG = changelog_json
  113. ####################################
  114. # DATA/FRONTEND BUILD DIR
  115. ####################################
  116. DATA_DIR = str(Path(os.getenv("DATA_DIR", "./data")).resolve())
  117. FRONTEND_BUILD_DIR = str(Path(os.getenv("FRONTEND_BUILD_DIR", "../build")))
  118. try:
  119. with open(f"{DATA_DIR}/config.json", "r") as f:
  120. CONFIG_DATA = json.load(f)
  121. except:
  122. CONFIG_DATA = {}
  123. ####################################
  124. # Static DIR
  125. ####################################
  126. STATIC_DIR = str(Path(os.getenv("STATIC_DIR", "./static")).resolve())
  127. frontend_favicon = f"{FRONTEND_BUILD_DIR}/favicon.png"
  128. if os.path.exists(frontend_favicon):
  129. shutil.copyfile(frontend_favicon, f"{STATIC_DIR}/favicon.png")
  130. else:
  131. logging.warning(f"Frontend favicon not found at {frontend_favicon}")
  132. ####################################
  133. # CUSTOM_NAME
  134. ####################################
  135. CUSTOM_NAME = os.environ.get("CUSTOM_NAME", "")
  136. if CUSTOM_NAME:
  137. try:
  138. r = requests.get(f"https://api.openwebui.com/api/v1/custom/{CUSTOM_NAME}")
  139. data = r.json()
  140. if r.ok:
  141. if "logo" in data:
  142. WEBUI_FAVICON_URL = url = (
  143. f"https://api.openwebui.com{data['logo']}"
  144. if data["logo"][0] == "/"
  145. else data["logo"]
  146. )
  147. r = requests.get(url, stream=True)
  148. if r.status_code == 200:
  149. with open(f"{STATIC_DIR}/favicon.png", "wb") as f:
  150. r.raw.decode_content = True
  151. shutil.copyfileobj(r.raw, f)
  152. WEBUI_NAME = data["name"]
  153. except Exception as e:
  154. log.exception(e)
  155. pass
  156. ####################################
  157. # File Upload DIR
  158. ####################################
  159. UPLOAD_DIR = f"{DATA_DIR}/uploads"
  160. Path(UPLOAD_DIR).mkdir(parents=True, exist_ok=True)
  161. ####################################
  162. # Cache DIR
  163. ####################################
  164. CACHE_DIR = f"{DATA_DIR}/cache"
  165. Path(CACHE_DIR).mkdir(parents=True, exist_ok=True)
  166. ####################################
  167. # Docs DIR
  168. ####################################
  169. DOCS_DIR = os.getenv("DOCS_DIR", f"{DATA_DIR}/docs")
  170. Path(DOCS_DIR).mkdir(parents=True, exist_ok=True)
  171. ####################################
  172. # LITELLM_CONFIG
  173. ####################################
  174. def create_config_file(file_path):
  175. directory = os.path.dirname(file_path)
  176. # Check if directory exists, if not, create it
  177. if not os.path.exists(directory):
  178. os.makedirs(directory)
  179. # Data to write into the YAML file
  180. config_data = {
  181. "general_settings": {},
  182. "litellm_settings": {},
  183. "model_list": [],
  184. "router_settings": {},
  185. }
  186. # Write data to YAML file
  187. with open(file_path, "w") as file:
  188. yaml.dump(config_data, file)
  189. LITELLM_CONFIG_PATH = f"{DATA_DIR}/litellm/config.yaml"
  190. if not os.path.exists(LITELLM_CONFIG_PATH):
  191. log.info("Config file doesn't exist. Creating...")
  192. create_config_file(LITELLM_CONFIG_PATH)
  193. log.info("Config file created successfully.")
  194. ####################################
  195. # OLLAMA_BASE_URL
  196. ####################################
  197. OLLAMA_API_BASE_URL = os.environ.get(
  198. "OLLAMA_API_BASE_URL", "http://localhost:11434/api"
  199. )
  200. OLLAMA_BASE_URL = os.environ.get("OLLAMA_BASE_URL", "")
  201. K8S_FLAG = os.environ.get("K8S_FLAG", "")
  202. USE_OLLAMA_DOCKER = os.environ.get("USE_OLLAMA_DOCKER", "false")
  203. if OLLAMA_BASE_URL == "" and OLLAMA_API_BASE_URL != "":
  204. OLLAMA_BASE_URL = (
  205. OLLAMA_API_BASE_URL[:-4]
  206. if OLLAMA_API_BASE_URL.endswith("/api")
  207. else OLLAMA_API_BASE_URL
  208. )
  209. if ENV == "prod":
  210. if OLLAMA_BASE_URL == "/ollama" and not K8S_FLAG:
  211. if USE_OLLAMA_DOCKER.lower() == "true":
  212. # if you use all-in-one docker container (Open WebUI + Ollama)
  213. # with the docker build arg USE_OLLAMA=true (--build-arg="USE_OLLAMA=true") this only works with http://localhost:11434
  214. OLLAMA_BASE_URL = "http://localhost:11434"
  215. else:
  216. OLLAMA_BASE_URL = "http://host.docker.internal:11434"
  217. elif K8S_FLAG:
  218. OLLAMA_BASE_URL = "http://ollama-service.open-webui.svc.cluster.local:11434"
  219. OLLAMA_BASE_URLS = os.environ.get("OLLAMA_BASE_URLS", "")
  220. OLLAMA_BASE_URLS = OLLAMA_BASE_URLS if OLLAMA_BASE_URLS != "" else OLLAMA_BASE_URL
  221. OLLAMA_BASE_URLS = [url.strip() for url in OLLAMA_BASE_URLS.split(";")]
  222. ####################################
  223. # OPENAI_API
  224. ####################################
  225. OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "")
  226. OPENAI_API_BASE_URL = os.environ.get("OPENAI_API_BASE_URL", "")
  227. if OPENAI_API_BASE_URL == "":
  228. OPENAI_API_BASE_URL = "https://api.openai.com/v1"
  229. OPENAI_API_KEYS = os.environ.get("OPENAI_API_KEYS", "")
  230. OPENAI_API_KEYS = OPENAI_API_KEYS if OPENAI_API_KEYS != "" else OPENAI_API_KEY
  231. OPENAI_API_KEYS = [url.strip() for url in OPENAI_API_KEYS.split(";")]
  232. OPENAI_API_BASE_URLS = os.environ.get("OPENAI_API_BASE_URLS", "")
  233. OPENAI_API_BASE_URLS = (
  234. OPENAI_API_BASE_URLS if OPENAI_API_BASE_URLS != "" else OPENAI_API_BASE_URL
  235. )
  236. OPENAI_API_BASE_URLS = [
  237. url.strip() if url != "" else "https://api.openai.com/v1"
  238. for url in OPENAI_API_BASE_URLS.split(";")
  239. ]
  240. OPENAI_API_KEY = ""
  241. try:
  242. OPENAI_API_KEY = OPENAI_API_KEYS[
  243. OPENAI_API_BASE_URLS.index("https://api.openai.com/v1")
  244. ]
  245. except:
  246. pass
  247. OPENAI_API_BASE_URL = "https://api.openai.com/v1"
  248. ####################################
  249. # WEBUI
  250. ####################################
  251. ENABLE_SIGNUP = os.environ.get("ENABLE_SIGNUP", "True").lower() == "true"
  252. DEFAULT_MODELS = os.environ.get("DEFAULT_MODELS", None)
  253. DEFAULT_PROMPT_SUGGESTIONS = (
  254. CONFIG_DATA["ui"]["prompt_suggestions"]
  255. if "ui" in CONFIG_DATA
  256. and "prompt_suggestions" in CONFIG_DATA["ui"]
  257. and type(CONFIG_DATA["ui"]["prompt_suggestions"]) is list
  258. else [
  259. {
  260. "title": ["Help me study", "vocabulary for a college entrance exam"],
  261. "content": "Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option.",
  262. },
  263. {
  264. "title": ["Give me ideas", "for what to do with my kids' art"],
  265. "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.",
  266. },
  267. {
  268. "title": ["Tell me a fun fact", "about the Roman Empire"],
  269. "content": "Tell me a random fun fact about the Roman Empire",
  270. },
  271. {
  272. "title": ["Show me a code snippet", "of a website's sticky header"],
  273. "content": "Show me a code snippet of a website's sticky header in CSS and JavaScript.",
  274. },
  275. {
  276. "title": [
  277. "Explain options trading",
  278. "if I'm familiar with buying and selling stocks",
  279. ],
  280. "content": "Explain options trading in simple terms if I'm familiar with buying and selling stocks.",
  281. },
  282. {
  283. "title": ["Overcome procrastination", "give me tips"],
  284. "content": "Could you start by asking me about instances when I procrastinate the most and then give me some suggestions to overcome it?",
  285. },
  286. ]
  287. )
  288. DEFAULT_USER_ROLE = os.getenv("DEFAULT_USER_ROLE", "pending")
  289. USER_PERMISSIONS_CHAT_DELETION = (
  290. os.environ.get("USER_PERMISSIONS_CHAT_DELETION", "True").lower() == "true"
  291. )
  292. USER_PERMISSIONS = {"chat": {"deletion": USER_PERMISSIONS_CHAT_DELETION}}
  293. ENABLE_MODEL_FILTER = os.environ.get("ENABLE_MODEL_FILTER", "False").lower() == "true"
  294. MODEL_FILTER_LIST = os.environ.get("MODEL_FILTER_LIST", "")
  295. MODEL_FILTER_LIST = [model.strip() for model in MODEL_FILTER_LIST.split(";")]
  296. WEBHOOK_URL = os.environ.get("WEBHOOK_URL", "")
  297. ENABLE_ADMIN_EXPORT = os.environ.get("ENABLE_ADMIN_EXPORT", "True").lower() == "true"
  298. ####################################
  299. # WEBUI_VERSION
  300. ####################################
  301. WEBUI_VERSION = os.environ.get("WEBUI_VERSION", "v1.0.0-alpha.100")
  302. ####################################
  303. # WEBUI_AUTH (Required for security)
  304. ####################################
  305. WEBUI_AUTH = True
  306. WEBUI_AUTH_TRUSTED_EMAIL_HEADER = os.environ.get(
  307. "WEBUI_AUTH_TRUSTED_EMAIL_HEADER", None
  308. )
  309. ####################################
  310. # WEBUI_SECRET_KEY
  311. ####################################
  312. WEBUI_SECRET_KEY = os.environ.get(
  313. "WEBUI_SECRET_KEY",
  314. os.environ.get(
  315. "WEBUI_JWT_SECRET_KEY", "t0p-s3cr3t"
  316. ), # DEPRECATED: remove at next major version
  317. )
  318. if WEBUI_AUTH and WEBUI_SECRET_KEY == "":
  319. raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND)
  320. ####################################
  321. # RAG
  322. ####################################
  323. CHROMA_DATA_PATH = f"{DATA_DIR}/vector_db"
  324. CHROMA_TENANT = os.environ.get("CHROMA_TENANT", chromadb.DEFAULT_TENANT)
  325. CHROMA_DATABASE = os.environ.get("CHROMA_DATABASE", chromadb.DEFAULT_DATABASE)
  326. CHROMA_HTTP_HOST = os.environ.get("CHROMA_HTTP_HOST", "")
  327. CHROMA_HTTP_PORT = int(os.environ.get("CHROMA_HTTP_PORT", "8000"))
  328. # Comma-separated list of header=value pairs
  329. CHROMA_HTTP_HEADERS = os.environ.get("CHROMA_HTTP_HEADERS", "")
  330. if CHROMA_HTTP_HEADERS:
  331. CHROMA_HTTP_HEADERS = dict(
  332. [pair.split("=") for pair in CHROMA_HTTP_HEADERS.split(",")]
  333. )
  334. else:
  335. CHROMA_HTTP_HEADERS = None
  336. CHROMA_HTTP_SSL = os.environ.get("CHROMA_HTTP_SSL", "false").lower() == "true"
  337. # this uses the model defined in the Dockerfile ENV variable. If you dont use docker or docker based deployments such as k8s, the default embedding model will be used (sentence-transformers/all-MiniLM-L6-v2)
  338. RAG_TOP_K = int(os.environ.get("RAG_TOP_K", "5"))
  339. RAG_RELEVANCE_THRESHOLD = float(os.environ.get("RAG_RELEVANCE_THRESHOLD", "0.0"))
  340. ENABLE_RAG_HYBRID_SEARCH = (
  341. os.environ.get("ENABLE_RAG_HYBRID_SEARCH", "").lower() == "true"
  342. )
  343. ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION = (
  344. os.environ.get("ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION", "True").lower() == "true"
  345. )
  346. RAG_EMBEDDING_ENGINE = os.environ.get("RAG_EMBEDDING_ENGINE", "")
  347. PDF_EXTRACT_IMAGES = os.environ.get("PDF_EXTRACT_IMAGES", "False").lower() == "true"
  348. RAG_EMBEDDING_MODEL = os.environ.get(
  349. "RAG_EMBEDDING_MODEL", "sentence-transformers/all-MiniLM-L6-v2"
  350. )
  351. log.info(f"Embedding model set: {RAG_EMBEDDING_MODEL}"),
  352. RAG_EMBEDDING_MODEL_AUTO_UPDATE = (
  353. os.environ.get("RAG_EMBEDDING_MODEL_AUTO_UPDATE", "").lower() == "true"
  354. )
  355. RAG_EMBEDDING_MODEL_TRUST_REMOTE_CODE = (
  356. os.environ.get("RAG_EMBEDDING_MODEL_TRUST_REMOTE_CODE", "").lower() == "true"
  357. )
  358. RAG_RERANKING_MODEL = os.environ.get("RAG_RERANKING_MODEL", "")
  359. if not RAG_RERANKING_MODEL == "":
  360. log.info(f"Reranking model set: {RAG_RERANKING_MODEL}"),
  361. RAG_RERANKING_MODEL_AUTO_UPDATE = (
  362. os.environ.get("RAG_RERANKING_MODEL_AUTO_UPDATE", "").lower() == "true"
  363. )
  364. RAG_RERANKING_MODEL_TRUST_REMOTE_CODE = (
  365. os.environ.get("RAG_RERANKING_MODEL_TRUST_REMOTE_CODE", "").lower() == "true"
  366. )
  367. # device type embedding models - "cpu" (default), "cuda" (nvidia gpu required) or "mps" (apple silicon) - choosing this right can lead to better performance
  368. USE_CUDA = os.environ.get("USE_CUDA_DOCKER", "false")
  369. if USE_CUDA.lower() == "true":
  370. DEVICE_TYPE = "cuda"
  371. else:
  372. DEVICE_TYPE = "cpu"
  373. if CHROMA_HTTP_HOST != "":
  374. CHROMA_CLIENT = chromadb.HttpClient(
  375. host=CHROMA_HTTP_HOST,
  376. port=CHROMA_HTTP_PORT,
  377. headers=CHROMA_HTTP_HEADERS,
  378. ssl=CHROMA_HTTP_SSL,
  379. tenant=CHROMA_TENANT,
  380. database=CHROMA_DATABASE,
  381. settings=Settings(allow_reset=True, anonymized_telemetry=False),
  382. )
  383. else:
  384. CHROMA_CLIENT = chromadb.PersistentClient(
  385. path=CHROMA_DATA_PATH,
  386. settings=Settings(allow_reset=True, anonymized_telemetry=False),
  387. tenant=CHROMA_TENANT,
  388. database=CHROMA_DATABASE,
  389. )
  390. CHUNK_SIZE = int(os.environ.get("CHUNK_SIZE", "1500"))
  391. CHUNK_OVERLAP = int(os.environ.get("CHUNK_OVERLAP", "100"))
  392. DEFAULT_RAG_TEMPLATE = """Use the following context as your learned knowledge, inside <context></context> XML tags.
  393. <context>
  394. [context]
  395. </context>
  396. When answer to user:
  397. - If you don't know, just say that you don't know.
  398. - If you don't know when you are not sure, ask for clarification.
  399. Avoid mentioning that you obtained the information from the context.
  400. And answer according to the language of the user's question.
  401. Given the context information, answer the query.
  402. Query: [query]"""
  403. RAG_TEMPLATE = os.environ.get("RAG_TEMPLATE", DEFAULT_RAG_TEMPLATE)
  404. RAG_OPENAI_API_BASE_URL = os.getenv("RAG_OPENAI_API_BASE_URL", OPENAI_API_BASE_URL)
  405. RAG_OPENAI_API_KEY = os.getenv("RAG_OPENAI_API_KEY", OPENAI_API_KEY)
  406. ENABLE_RAG_LOCAL_WEB_FETCH = (
  407. os.getenv("ENABLE_RAG_LOCAL_WEB_FETCH", "False").lower() == "true"
  408. )
  409. ####################################
  410. # Transcribe
  411. ####################################
  412. WHISPER_MODEL = os.getenv("WHISPER_MODEL", "base")
  413. WHISPER_MODEL_DIR = os.getenv("WHISPER_MODEL_DIR", f"{CACHE_DIR}/whisper/models")
  414. WHISPER_MODEL_AUTO_UPDATE = (
  415. os.environ.get("WHISPER_MODEL_AUTO_UPDATE", "").lower() == "true"
  416. )
  417. ####################################
  418. # Images
  419. ####################################
  420. IMAGE_GENERATION_ENGINE = os.getenv("IMAGE_GENERATION_ENGINE", "")
  421. ENABLE_IMAGE_GENERATION = (
  422. os.environ.get("ENABLE_IMAGE_GENERATION", "").lower() == "true"
  423. )
  424. AUTOMATIC1111_BASE_URL = os.getenv("AUTOMATIC1111_BASE_URL", "")
  425. COMFYUI_BASE_URL = os.getenv("COMFYUI_BASE_URL", "")
  426. IMAGES_OPENAI_API_BASE_URL = os.getenv(
  427. "IMAGES_OPENAI_API_BASE_URL", OPENAI_API_BASE_URL
  428. )
  429. IMAGES_OPENAI_API_KEY = os.getenv("IMAGES_OPENAI_API_KEY", OPENAI_API_KEY)
  430. IMAGE_SIZE = os.getenv("IMAGE_SIZE", "512x512")
  431. IMAGE_STEPS = int(os.getenv("IMAGE_STEPS", 50))
  432. IMAGE_GENERATION_MODEL = os.getenv("IMAGE_GENERATION_MODEL", "")
  433. ####################################
  434. # Audio
  435. ####################################
  436. AUDIO_OPENAI_API_BASE_URL = os.getenv("AUDIO_OPENAI_API_BASE_URL", OPENAI_API_BASE_URL)
  437. AUDIO_OPENAI_API_KEY = os.getenv("AUDIO_OPENAI_API_KEY", OPENAI_API_KEY)
  438. ####################################
  439. # LiteLLM
  440. ####################################
  441. ENABLE_LITELLM = os.environ.get("ENABLE_LITELLM", "True").lower() == "true"
  442. LITELLM_PROXY_PORT = int(os.getenv("LITELLM_PROXY_PORT", "14365"))
  443. if LITELLM_PROXY_PORT < 0 or LITELLM_PROXY_PORT > 65535:
  444. raise ValueError("Invalid port number for LITELLM_PROXY_PORT")
  445. LITELLM_PROXY_HOST = os.getenv("LITELLM_PROXY_HOST", "127.0.0.1")
  446. ####################################
  447. # Database
  448. ####################################
  449. DATABASE_URL = os.environ.get("DATABASE_URL", f"sqlite:///{DATA_DIR}/webui.db")