42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
from typing import Annotated
|
|
from fastapi import APIRouter, Depends
|
|
from typing import List
|
|
|
|
from enums import TypeMood, TypeModel
|
|
from gigachat import get_chat_completion, giga_token
|
|
from repository import QuestionRepository
|
|
from schemas import SQuestionAdd, SQuestion, SQuestionId
|
|
|
|
router = APIRouter(
|
|
prefix="/questions",
|
|
tags=["Questions"],
|
|
)
|
|
|
|
@router.post("/add")
|
|
async def add_question(
|
|
question: Annotated[SQuestionAdd, Depends()],
|
|
type_mood: TypeMood, # Добавлен параметр type_mood
|
|
type_model: TypeModel, # Добавлен параметр type_model
|
|
) -> SQuestionId:
|
|
question_id, answer = await QuestionRepository.add_one(question, type_mood, type_model) # Передача параметров type_mood и type_model
|
|
return {"question_id": question_id, "answer": answer}
|
|
|
|
@router.get("/get_all")
|
|
async def get_questions() -> list[SQuestion]:
|
|
questions = await QuestionRepository.find_all()
|
|
return questions
|
|
|
|
|
|
@router.get("/get/{email_user}")
|
|
async def get_questions_by_email(email_user: str) -> list[SQuestion]:
|
|
questions = await QuestionRepository.find_by_email(email_user)
|
|
return questions
|
|
|
|
|
|
@router.post("/chat")
|
|
async def add_question(question: str):
|
|
# Получение ответа от нейронной сети
|
|
neural_response = get_chat_completion(giga_token, question)
|
|
|
|
return {"answer": neural_response}
|