feat(sqlalchemy): Replace peewee with sqlalchemy

This commit is contained in:
Jonathan Rohde
2024-06-27 07:48:08 +02:00
parent 8dac2a2140
commit df09d0830a
47 changed files with 2580 additions and 1003 deletions
+21 -11
View File
@@ -6,6 +6,7 @@ from fastapi import APIRouter
from pydantic import BaseModel
import json
from apps.webui.internal.db import get_db
from apps.webui.models.prompts import Prompts, PromptForm, PromptModel
from utils.utils import get_current_user, get_admin_user
@@ -19,8 +20,8 @@ router = APIRouter()
@router.get("/", response_model=List[PromptModel])
async def get_prompts(user=Depends(get_current_user)):
return Prompts.get_prompts()
async def get_prompts(user=Depends(get_current_user), db=Depends(get_db)):
return Prompts.get_prompts(db)
############################
@@ -29,10 +30,12 @@ async def get_prompts(user=Depends(get_current_user)):
@router.post("/create", response_model=Optional[PromptModel])
async def create_new_prompt(form_data: PromptForm, user=Depends(get_admin_user)):
prompt = Prompts.get_prompt_by_command(form_data.command)
async def create_new_prompt(
form_data: PromptForm, user=Depends(get_admin_user), db=Depends(get_db)
):
prompt = Prompts.get_prompt_by_command(db, form_data.command)
if prompt == None:
prompt = Prompts.insert_new_prompt(user.id, form_data)
prompt = Prompts.insert_new_prompt(db, user.id, form_data)
if prompt:
return prompt
@@ -52,8 +55,10 @@ async def create_new_prompt(form_data: PromptForm, user=Depends(get_admin_user))
@router.get("/command/{command}", response_model=Optional[PromptModel])
async def get_prompt_by_command(command: str, user=Depends(get_current_user)):
prompt = Prompts.get_prompt_by_command(f"/{command}")
async def get_prompt_by_command(
command: str, user=Depends(get_current_user), db=Depends(get_db)
):
prompt = Prompts.get_prompt_by_command(db, f"/{command}")
if prompt:
return prompt
@@ -71,9 +76,12 @@ async def get_prompt_by_command(command: str, user=Depends(get_current_user)):
@router.post("/command/{command}/update", response_model=Optional[PromptModel])
async def update_prompt_by_command(
command: str, form_data: PromptForm, user=Depends(get_admin_user)
command: str,
form_data: PromptForm,
user=Depends(get_admin_user),
db=Depends(get_db),
):
prompt = Prompts.update_prompt_by_command(f"/{command}", form_data)
prompt = Prompts.update_prompt_by_command(db, f"/{command}", form_data)
if prompt:
return prompt
else:
@@ -89,6 +97,8 @@ async def update_prompt_by_command(
@router.delete("/command/{command}/delete", response_model=bool)
async def delete_prompt_by_command(command: str, user=Depends(get_admin_user)):
result = Prompts.delete_prompt_by_command(f"/{command}")
async def delete_prompt_by_command(
command: str, user=Depends(get_admin_user), db=Depends(get_db)
):
result = Prompts.delete_prompt_by_command(db, f"/{command}")
return result