22import json
33import logging
44from datetime import datetime
5- from typing import List , Optional , Dict , Any
5+ from typing import Any , Dict , List , Optional
66
77from fastapi import Header
88from jinja2 import StrictUndefined , Template
9+ from nexent .core .utils .observer import ProcessType
910from smolagents import OpenAIServerModel
1011
11- from consts .model import MessageRequest , ConversationResponse , AgentRequest , MessageUnit
12- from database .conversation_db import create_conversation_message , create_source_search , create_message_units , \
13- create_source_image , rename_conversation , get_conversation_list , get_conversation_history , \
14- get_source_images_by_message , \
15- get_source_images_by_conversation , get_source_searches_by_message , get_source_searches_by_conversation , \
16- delete_conversation , get_conversation , create_conversation , update_message_opinion , get_message_id_by_index
17- from nexent .core .utils .observer import ProcessType
12+ from consts .model import AgentRequest , ConversationResponse , MessageRequest , MessageUnit
13+ from database .conversation_db import (
14+ create_conversation ,
15+ create_conversation_message ,
16+ create_message_units ,
17+ create_source_image ,
18+ create_source_search ,
19+ delete_conversation ,
20+ get_conversation ,
21+ get_conversation_history ,
22+ get_conversation_list ,
23+ get_message_id_by_index ,
24+ get_source_images_by_conversation ,
25+ get_source_images_by_message ,
26+ get_source_searches_by_conversation ,
27+ get_source_searches_by_message ,
28+ rename_conversation ,
29+ update_message_opinion
30+ )
1831from utils .auth_utils import get_current_user_id
19- from utils .config_utils import tenant_config_manager , get_model_name_from_config
32+ from utils .config_utils import get_model_name_from_config , tenant_config_manager
2033from utils .prompt_template_utils import get_generate_title_prompt_template
21- from utils .str_utils import remove_think_tags , add_no_think_token
34+ from utils .str_utils import add_no_think_token , remove_think_tags
2235
2336logger = logging .getLogger ("conversation_management_service" )
2437
@@ -56,7 +69,8 @@ def save_message(request: MessageRequest, authorization: Optional[str] = Header(
5669 # Validate conversation_id
5770 conversation_id = message_data .get ('conversation_id' )
5871 if not conversation_id :
59- raise Exception ("conversation_id is required, please call /conversation/create to create a conversation first" )
72+ raise Exception (
73+ "conversation_id is required, please call /conversation/create to create a conversation first" )
6074
6175 # Process different types of message units
6276 message_units = message_data ['message' ]
@@ -289,7 +303,8 @@ def update_conversation_title(conversation_id: int, title: str, user_id: str = N
289303 """
290304 success = rename_conversation (conversation_id , title , user_id )
291305 if not success :
292- raise Exception (f"Conversation { conversation_id } does not exist or has been deleted" )
306+ raise Exception (
307+ f"Conversation { conversation_id } does not exist or has been deleted" )
293308 return success
294309
295310
@@ -342,7 +357,8 @@ def rename_conversation_service(conversation_id: int, name: str, user_id: str) -
342357 try :
343358 success = rename_conversation (conversation_id , name , user_id )
344359 if not success :
345- raise Exception (f"Conversation { conversation_id } does not exist or has been deleted" )
360+ raise Exception (
361+ f"Conversation { conversation_id } does not exist or has been deleted" )
346362 return True
347363 except Exception as e :
348364 logging .error (f"Failed to rename conversation: { str (e )} " )
@@ -363,7 +379,8 @@ def delete_conversation_service(conversation_id: int, user_id: str) -> bool:
363379 try :
364380 success = delete_conversation (conversation_id , user_id )
365381 if not success :
366- raise Exception (f"Conversation { conversation_id } does not exist or has been deleted" )
382+ raise Exception (
383+ f"Conversation { conversation_id } does not exist or has been deleted" )
367384 return True
368385 except Exception as e :
369386 logging .error (f"Failed to delete conversation: { str (e )} " )
@@ -688,4 +705,4 @@ async def get_message_id_by_index_impl(conversation_id: int, message_index: int)
688705 message_id = get_message_id_by_index (conversation_id , message_index )
689706 if message_id is None :
690707 raise Exception ("Message not found." )
691- return message_id
708+ return message_id
0 commit comments