mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-19 04:12:03 +03:00
1bf67e3640
# Description Prompt module with Service ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from middlewares.auth import AuthBearer
|
|
from modules.prompt.entity.prompt import (
|
|
CreatePromptProperties,
|
|
Prompt,
|
|
PromptUpdatableProperties,
|
|
)
|
|
from modules.prompt.service import PromptService
|
|
|
|
prompt_router = APIRouter()
|
|
|
|
promptService = PromptService()
|
|
|
|
|
|
@prompt_router.get("/prompts", dependencies=[Depends(AuthBearer())], tags=["Prompt"])
|
|
async def get_prompts() -> list[Prompt]:
|
|
"""
|
|
Retrieve all public prompt
|
|
"""
|
|
return promptService.get_public_prompts()
|
|
|
|
|
|
@prompt_router.get(
|
|
"/prompts/{prompt_id}", dependencies=[Depends(AuthBearer())], tags=["Prompt"]
|
|
)
|
|
async def get_prompt(prompt_id: UUID) -> Prompt | None:
|
|
"""
|
|
Retrieve a prompt by its id
|
|
"""
|
|
|
|
return promptService.get_prompt_by_id(prompt_id)
|
|
|
|
|
|
@prompt_router.put(
|
|
"/prompts/{prompt_id}", dependencies=[Depends(AuthBearer())], tags=["Prompt"]
|
|
)
|
|
async def update_prompt(
|
|
prompt_id: UUID, prompt: PromptUpdatableProperties
|
|
) -> Prompt | None:
|
|
"""
|
|
Update a prompt by its id
|
|
"""
|
|
|
|
return promptService.update_prompt_by_id(prompt_id, prompt)
|
|
|
|
|
|
@prompt_router.post("/prompts", dependencies=[Depends(AuthBearer())], tags=["Prompt"])
|
|
async def create_prompt_route(prompt: CreatePromptProperties) -> Prompt | None:
|
|
"""
|
|
Create a prompt by its id
|
|
"""
|
|
|
|
return promptService.create_prompt(prompt)
|