refac: convert str var to f-string

This commit is contained in:
Timothy J. Baek 2024-01-22 01:47:07 -08:00
parent 5b26d2a686
commit d2c5f3d591
4 changed files with 14 additions and 9 deletions

View file

@ -2,5 +2,5 @@ from peewee import *
from config import DATA_DIR from config import DATA_DIR
DB = SqliteDatabase(str(DATA_DIR / "ollama.db")) DB = SqliteDatabase(f"{DATA_DIR}/ollama.db")
DB.connect() DB.connect()

View file

@ -96,7 +96,7 @@ async def download(
file_name = parse_huggingface_url(url) file_name = parse_huggingface_url(url)
if file_name: if file_name:
file_path = str(UPLOAD_DIR / file_name) file_path = f"{UPLOAD_DIR}/{file_name}"
return StreamingResponse( return StreamingResponse(
download_file_stream(url, file_path, file_name), download_file_stream(url, file_path, file_name),
@ -108,7 +108,7 @@ async def download(
@router.post("/upload") @router.post("/upload")
def upload(file: UploadFile = File(...)): def upload(file: UploadFile = File(...)):
file_path = UPLOAD_DIR / file.filename file_path = f"{UPLOAD_DIR}/{file.filename}"
# Save file in chunks # Save file in chunks
with file_path.open("wb+") as f: with file_path.open("wb+") as f:

View file

@ -15,6 +15,7 @@ from pathlib import Path
try: try:
from dotenv import load_dotenv, find_dotenv from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv("../.env")) load_dotenv(find_dotenv("../.env"))
except ImportError: except ImportError:
print("dotenv not installed, skipping...") print("dotenv not installed, skipping...")
@ -24,12 +25,12 @@ except ImportError:
# File Upload # File Upload
#################################### ####################################
DATA_DIR = Path(os.getenv("DATA_DIR", './data')).resolve() DATA_DIR = Path(os.getenv("DATA_DIR", "./data")).resolve()
UPLOAD_DIR = DATA_DIR / "uploads" UPLOAD_DIR = f"{DATA_DIR}/uploads"
UPLOAD_DIR.mkdir(parents=True, exist_ok=True) UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
WEB_DIR = Path(os.getenv("WEB_DIR", "../build")) FRONTEND_BUILD_DIR = Path(os.getenv("FRONTEND_BUILD_DIR", "../build"))
#################################### ####################################
# ENV (dev,test,prod) # ENV (dev,test,prod)
@ -84,7 +85,7 @@ if WEBUI_AUTH and WEBUI_JWT_SECRET_KEY == "":
# RAG # RAG
#################################### ####################################
CHROMA_DATA_PATH = DATA_DIR / "vector_db" CHROMA_DATA_PATH = f"{DATA_DIR}/vector_db"
EMBED_MODEL = "all-MiniLM-L6-v2" EMBED_MODEL = "all-MiniLM-L6-v2"
CHROMA_CLIENT = chromadb.PersistentClient( CHROMA_CLIENT = chromadb.PersistentClient(
path=str(CHROMA_DATA_PATH), settings=Settings(allow_reset=True) path=str(CHROMA_DATA_PATH), settings=Settings(allow_reset=True)

View file

@ -14,7 +14,7 @@ from apps.openai.main import app as openai_app
from apps.web.main import app as webui_app from apps.web.main import app as webui_app
from apps.rag.main import app as rag_app from apps.rag.main import app as rag_app
from config import ENV, WEB_DIR from config import ENV, FRONTEND_BUILD_DIR
class SPAStaticFiles(StaticFiles): class SPAStaticFiles(StaticFiles):
@ -58,4 +58,8 @@ app.mount("/openai/api", openai_app)
app.mount("/rag/api/v1", rag_app) app.mount("/rag/api/v1", rag_app)
app.mount("/", SPAStaticFiles(directory=str(WEB_DIR), html=True), name="spa-static-files") app.mount(
"/",
SPAStaticFiles(directory=str(FRONTEND_BUILD_DIR), html=True),
name="spa-static-files",
)