2024-06-13 14:31:14 +08:00
|
|
|
|
import json
|
2024-05-29 11:12:59 +08:00
|
|
|
|
import logging
|
2024-06-25 16:58:17 +08:00
|
|
|
|
|
2024-06-13 14:31:14 +08:00
|
|
|
|
from fastapi import APIRouter, HTTPException
|
2024-05-29 11:12:59 +08:00
|
|
|
|
|
|
|
|
|
|
from app.schemas.chat_robot import ChatRobotModel
|
2024-06-13 14:31:14 +08:00
|
|
|
|
from app.schemas.response_template import ResponseModel
|
2024-05-29 11:12:59 +08:00
|
|
|
|
from app.service.chat_robot.script.main import chat
|
|
|
|
|
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/chat_robot")
|
|
|
|
|
|
def chat_robot(request_data: ChatRobotModel):
|
2024-06-25 16:58:17 +08:00
|
|
|
|
"""
|
|
|
|
|
|
对话机器人
|
|
|
|
|
|
创建一个具有以下参数的请求体:
|
|
|
|
|
|
- **gender**: 服装类别
|
|
|
|
|
|
- **message**: 消息
|
|
|
|
|
|
- **session_id**: 会话id
|
|
|
|
|
|
- **user_id**: 用户id
|
|
|
|
|
|
|
|
|
|
|
|
示例参数:
|
|
|
|
|
|
{
|
|
|
|
|
|
"gender": "male",
|
|
|
|
|
|
"message": "你好",
|
|
|
|
|
|
"session_id": "string-89",
|
|
|
|
|
|
"user_id": 89
|
|
|
|
|
|
}
|
|
|
|
|
|
"""
|
2024-05-29 11:12:59 +08:00
|
|
|
|
try:
|
2024-07-04 14:14:57 +08:00
|
|
|
|
logger.info(f"chat_robot request item is : @@@@@@:{json.dumps(request_data.dict())}")
|
2024-05-29 11:12:59 +08:00
|
|
|
|
data = chat(post_data=request_data)
|
2024-07-04 14:14:57 +08:00
|
|
|
|
logger.info(f"chat_robot response @@@@@@:{json.dumps(data)}")
|
2024-05-29 11:12:59 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.warning(f"chat_robot Run Exception @@@@@@:{e}")
|
2024-06-13 14:31:14 +08:00
|
|
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
|
|
|
|
return ResponseModel(data=data)
|