You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					60 lines
				
				2.8 KiB
			
		
		
			
		
	
	
					60 lines
				
				2.8 KiB
			| 
											10 months ago
										 | import uuid | ||
|  | 
 | ||
|  | from typing import Optional | ||
|  | from sqlalchemy.ext.asyncio import AsyncSession | ||
|  | from module_admin.entity.vo.aichat_vo import * | ||
|  | from module_admin.entity.vo.common_vo import CrudResponseModel | ||
|  | from module_admin.dao.aichat_dao import * | ||
|  | from module_admin.entity.vo.user_vo import CurrentUserModel | ||
|  | from datetime import datetime | ||
|  | from utils.common_util import CamelCaseUtil | ||
|  | 
 | ||
|  | 
 | ||
|  | class AiChatService: | ||
|  |     """
 | ||
|  |     智能问答服务层 | ||
|  |     """
 | ||
|  | 
 | ||
|  |     @classmethod | ||
|  |     async def get_ai_session_list_services(cls, result_db: AsyncSession, sessionId: str, | ||
|  |                                      current_user: Optional[CurrentUserModel] = None): | ||
|  |         ai_session_list = await AiChatDao.get_ai_session_list(result_db, sessionId, current_user.user.user_id)  # 查询最新的20条 | ||
|  |         return ai_session_list | ||
|  | 
 | ||
|  |     @classmethod | ||
|  |     async def get_ai_chat_list_services(cls, result_db: AsyncSession, sessionId: str, | ||
|  |                                   current_user: Optional[CurrentUserModel] = None): | ||
|  |         ai_session_list = await AiChatDao.get_ai_chat_list(result_db, sessionId, current_user.user.user_id)  # 查询最新的20条 | ||
|  |         return CamelCaseUtil.transform_result(ai_session_list) | ||
|  | 
 | ||
|  |     @classmethod | ||
|  |     async def delete_chat_session(cls, result_db: AsyncSession, sessionId: str, | ||
|  |                             current_user: Optional[CurrentUserModel] = None): | ||
|  |         await AiChatDao.delete_chat_session(result_db, sessionId, current_user.user.user_id) | ||
|  |         await result_db.commit() | ||
|  |         return CrudResponseModel(is_success=True, message='删除成功') | ||
|  | 
 | ||
|  |     @classmethod | ||
|  |     async def add_chat(cls, result_db: AsyncSession, add_chat: AiChatModel, | ||
|  |                             current_user: Optional[CurrentUserModel] = None): | ||
|  |         chat_session = await AiChatDao.get_ai_chat_by_id(add_chat.sessionId, result_db, current_user.user.user_id) | ||
|  |         print(chat_session) | ||
|  |         add_chat.user = current_user.user.user_id | ||
|  |         if add_chat.time is None: | ||
|  |             add_chat.time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | ||
|  |         if chat_session is None: | ||
|  |             await AiChatDao.add_ai_chat_session(add_chat.sessionId, add_chat.sessionName, | ||
|  |                                           add_chat.time, result_db, current_user.user.user_id) | ||
|  |             await result_db.commit() | ||
|  |         chat_history = AiChatHistory(**add_chat.dict()) | ||
|  |         chat_history.chatId = uuid.uuid4() | ||
|  |         await AiChatDao.add_ai_chat_history(chat_history, result_db) | ||
|  |         await result_db.commit() | ||
|  |         return CrudResponseModel(is_success=True, message='操作成功') | ||
|  | 
 | ||
|  |     @classmethod | ||
|  |     async def update_chat(cls, result_db: AsyncSession, update_chat: AiChatModel): | ||
|  |         await AiChatDao.update_ai_chat_history(update_chat, result_db) | ||
|  |         await result_db.commit() | ||
|  |         return CrudResponseModel(is_success=True, message='操作成功') |