/
slack.py
28 lines (20 loc) · 996 Bytes
/
slack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from fastapi import APIRouter
from starlette.background import BackgroundTasks
from starlette.responses import Response
from app.config.constants import LLMModel
from app.services.slack import message_process
router = APIRouter()
@router.post("/gpt")
async def slack(message: dict, background_tasks: BackgroundTasks):
if message.get("challenge"):
return message.get("challenge")
# Because Slack is constrained to give a response in 3 seconds, ChatGPT processing is handled by background_tasks.
background_tasks.add_task(message_process, message, LLMModel.GPT)
return Response("ok")
@router.post("/gemini")
async def slack(message: dict, background_tasks: BackgroundTasks):
if message.get("challenge"):
return message.get("challenge")
# Because Slack is constrained to give a response in 3 seconds, ChatGPT processing is handled by background_tasks.
background_tasks.add_task(message_process, message, LLMModel.GEMINI)
return Response("ok")