1111from google .genai .types import FunctionCall , Part
1212
1313from agents .matmaster_agent .constant import FRONTEND_STATE_KEY
14- from agents .matmaster_agent .model import TransferCheck
15- from agents .matmaster_agent .prompt import get_transfer_check_prompt
14+ from agents .matmaster_agent .model import TransferCheck , UserContent
15+ from agents .matmaster_agent .prompt import get_transfer_check_prompt , get_user_content_lang
1616from agents .matmaster_agent .utils .llm_response_utils import has_function_call
1717
1818logger = logging .getLogger (__name__ )
@@ -25,7 +25,6 @@ async def matmaster_prepare_state(callback_context: CallbackContext) -> Optional
2525
2626 callback_context .state [FRONTEND_STATE_KEY ] = callback_context .state .get (FRONTEND_STATE_KEY , {})
2727 callback_context .state [FRONTEND_STATE_KEY ]['biz' ] = callback_context .state [FRONTEND_STATE_KEY ].get ('biz' , {})
28- callback_context .state ['target_language' ] = callback_context .state [FRONTEND_STATE_KEY ].get ('target_language' , 'zh' )
2928 callback_context .state ['long_running_ids' ] = callback_context .state .get ('long_running_ids' , [])
3029 callback_context .state ['long_running_jobs' ] = callback_context .state .get ('long_running_jobs' , {})
3130 callback_context .state ['long_running_jobs_count' ] = callback_context .state .get ('long_running_jobs_count' , 0 )
@@ -39,6 +38,15 @@ async def matmaster_prepare_state(callback_context: CallbackContext) -> Optional
3938 callback_context .state ['invocation_id_with_tool_call' ] = callback_context .state .get ('invocation_id_with_tool_call' ,
4039 None )
4140
41+ user_content = callback_context .user_content .parts [0 ].text
42+ prompt = get_user_content_lang ().format (user_content = user_content )
43+ response = litellm .completion (model = 'azure/gpt-4o' , messages = [{'role' : 'user' , 'content' : prompt }],
44+ response_format = UserContent )
45+ result : dict = json .loads (response .choices [0 ].message .content )
46+ logger .info (f"[matmaster_prepare_state] user_content = { result } " )
47+ language = str (result .get ('language' , 'zh' ))
48+ callback_context .state ['target_language' ] = language
49+
4250
4351# after_model_callback
4452async def matmaster_check_transfer (callback_context : CallbackContext , llm_response : LlmResponse ) -> Optional [
0 commit comments