2024-04-02 04:40:56 +03:00
|
|
|
from typing import List
|
|
|
|
|
2024-04-11 19:31:16 +03:00
|
|
|
from fastapi import APIRouter, Depends, HTTPException, UploadFile
|
2024-04-02 04:40:56 +03:00
|
|
|
from logger import get_logger
|
|
|
|
from middlewares.auth import AuthBearer, get_current_user
|
2024-04-11 19:31:16 +03:00
|
|
|
from modules.assistant.dto.inputs import InputAssistant
|
2024-04-10 14:28:22 +03:00
|
|
|
from modules.assistant.dto.outputs import AssistantOutput
|
2024-04-19 11:36:36 +03:00
|
|
|
from modules.assistant.ito.difference import DifferenceAssistant
|
2024-04-10 14:28:22 +03:00
|
|
|
from modules.assistant.ito.summary import SummaryAssistant, summary_inputs
|
|
|
|
from modules.assistant.service.assistant import Assistant
|
2024-04-02 04:40:56 +03:00
|
|
|
from modules.user.entity.user_identity import UserIdentity
|
|
|
|
|
2024-04-10 14:28:22 +03:00
|
|
|
assistant_router = APIRouter()
|
2024-04-02 04:40:56 +03:00
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
2024-04-10 14:28:22 +03:00
|
|
|
assistant_service = Assistant()
|
2024-04-02 04:40:56 +03:00
|
|
|
|
|
|
|
|
2024-04-10 14:28:22 +03:00
|
|
|
@assistant_router.get(
|
|
|
|
"/assistants", dependencies=[Depends(AuthBearer())], tags=["Assistant"]
|
2024-04-02 04:40:56 +03:00
|
|
|
)
|
2024-04-10 14:28:22 +03:00
|
|
|
async def list_assistants(
|
2024-04-02 04:40:56 +03:00
|
|
|
current_user: UserIdentity = Depends(get_current_user),
|
2024-04-10 14:28:22 +03:00
|
|
|
) -> List[AssistantOutput]:
|
2024-04-02 04:40:56 +03:00
|
|
|
"""
|
|
|
|
Retrieve and list all the knowledge in a brain.
|
|
|
|
"""
|
|
|
|
|
2024-04-10 14:28:22 +03:00
|
|
|
summary = summary_inputs()
|
2024-04-12 19:06:50 +03:00
|
|
|
# difference = difference_inputs()
|
2024-04-11 23:35:35 +03:00
|
|
|
# crawler = crawler_inputs()
|
|
|
|
# audio_transcript = audio_transcript_inputs()
|
|
|
|
return [summary]
|
2024-04-02 04:40:56 +03:00
|
|
|
|
|
|
|
|
2024-04-10 14:28:22 +03:00
|
|
|
@assistant_router.post(
|
2024-04-11 19:31:16 +03:00
|
|
|
"/assistant/process",
|
2024-04-02 04:40:56 +03:00
|
|
|
dependencies=[Depends(AuthBearer())],
|
2024-04-10 14:28:22 +03:00
|
|
|
tags=["Assistant"],
|
2024-04-02 04:40:56 +03:00
|
|
|
)
|
2024-04-10 14:28:22 +03:00
|
|
|
async def process_assistant(
|
2024-04-11 19:31:16 +03:00
|
|
|
input: InputAssistant,
|
|
|
|
files: List[UploadFile] = None,
|
2024-04-02 04:40:56 +03:00
|
|
|
current_user: UserIdentity = Depends(get_current_user),
|
|
|
|
):
|
2024-04-19 11:36:36 +03:00
|
|
|
if input.name.lower() == "summary":
|
2024-04-11 19:31:16 +03:00
|
|
|
summary_assistant = SummaryAssistant(
|
|
|
|
input=input, files=files, current_user=current_user
|
2024-04-02 04:40:56 +03:00
|
|
|
)
|
2024-04-11 19:31:16 +03:00
|
|
|
try:
|
|
|
|
summary_assistant.check_input()
|
|
|
|
return await summary_assistant.process_assistant()
|
|
|
|
except ValueError as e:
|
|
|
|
raise HTTPException(status_code=400, detail=str(e))
|
2024-04-19 11:36:36 +03:00
|
|
|
elif input.name.lower() == "difference":
|
2024-04-12 19:06:50 +03:00
|
|
|
difference_assistant = DifferenceAssistant(
|
|
|
|
input=input, files=files, current_user=current_user
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
difference_assistant.check_input()
|
|
|
|
return await difference_assistant.process_assistant()
|
|
|
|
except ValueError as e:
|
|
|
|
raise HTTPException(status_code=400, detail=str(e))
|
2024-04-11 19:31:16 +03:00
|
|
|
return {"message": "Assistant not found"}
|