Spaces:
Sleeping
Sleeping
Download app/api/chatbot.py from Alpha-Team/CyberArena: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/Alpha-Team/CyberArena/resolve/main/app/api/chatbot.py
- Command line
-
hf download hf://spaces/Alpha-Team/CyberArena/app/api/chatbot.py
-
curl -L -o chatbot.py https://huggingface.co/spaces/Alpha-Team/CyberArena/resolve/main/app/api/chatbot.py
1.18 kB
| """``/api/chatbot`` — Global AI chatbot endpoint. | |
| Accessible from every page (except training sessions which have their | |
| own AI Mentor). Helps users understand the platform, navigate features, | |
| and learn about cybersecurity concepts. | |
| """ | |
| from typing import Optional | |
| from fastapi import APIRouter, Depends, HTTPException, Request | |
| from pydantic import BaseModel | |
| from app.core.auth import get_current_user | |
| from app.services.chatbot_service import get_chatbot_response | |
| router = APIRouter() | |
| class ChatbotRequest(BaseModel): | |
| message: str | |
| page: str = "" | |
| lang: str = "ar" | |
| conversationHistory: Optional[list[dict[str, str]]] = None | |
| class ChatbotResponse(BaseModel): | |
| response: str | |
| async def ask_chatbot( | |
| req: ChatbotRequest, | |
| request: Request, | |
| user: dict = Depends(get_current_user), | |
| ): | |
| if not req.message: | |
| raise HTTPException(status_code=400, detail="الرسالة مطلوبة") | |
| result = await get_chatbot_response( | |
| message=req.message, | |
| conversation_history=req.conversationHistory, | |
| page=req.page, | |
| lang=req.lang, | |
| ) | |
| return ChatbotResponse(response=result) | |