11from playwright .async_api import Page as AsyncPage
22
33from api_utils .server_state import state
4+ from logging_utils import set_request_id
45
56from .context_types import RequestContext
67
78
89async def analyze_model_requirements (
910 req_id : str , context : RequestContext , requested_model : str , proxy_model_name : str
1011) -> RequestContext :
12+ set_request_id (req_id )
1113 logger = context ["logger" ]
1214 current_ai_studio_model_id = context ["current_ai_studio_model_id" ]
1315 parsed_model_list = context ["parsed_model_list" ]
1416
1517 if requested_model and requested_model != proxy_model_name :
1618 requested_model_id = requested_model .split ("/" )[- 1 ]
17- logger .info (f"[ { req_id } ] 请求使用模型: { requested_model_id } " )
19+ logger .info (f"请求使用模型: { requested_model_id } " )
1820
1921 if parsed_model_list :
2022 valid_model_ids = [m .get ("id" ) for m in parsed_model_list ]
@@ -30,7 +32,7 @@ async def analyze_model_requirements(
3032 if current_ai_studio_model_id != requested_model_id :
3133 context ["needs_model_switching" ] = True
3234 logger .info (
33- f"[ { req_id } ] 需要切换模型: 当前={ current_ai_studio_model_id } -> 目标={ requested_model_id } "
35+ f"需要切换模型: 当前={ current_ai_studio_model_id } -> 目标={ requested_model_id } "
3436 )
3537
3638 return context
@@ -39,6 +41,7 @@ async def analyze_model_requirements(
3941async def handle_model_switching (
4042 req_id : str , context : RequestContext
4143) -> RequestContext :
44+ set_request_id (req_id )
4245 if not context ["needs_model_switching" ]:
4346 return context
4447
@@ -50,7 +53,7 @@ async def handle_model_switching(
5053 async with model_switching_lock :
5154 if state .current_ai_studio_model_id != model_id_to_use :
5255 logger .info (
53- f"[ { req_id } ] 准备切换模型: { state .current_ai_studio_model_id } -> { model_id_to_use } "
56+ f"准备切换模型: { state .current_ai_studio_model_id } -> { model_id_to_use } "
5457 )
5558 from browser_utils import switch_ai_studio_model
5659
@@ -59,9 +62,7 @@ async def handle_model_switching(
5962 state .current_ai_studio_model_id = model_id_to_use
6063 context ["model_actually_switched" ] = True
6164 context ["current_ai_studio_model_id" ] = model_id_to_use
62- logger .info (
63- f"[{ req_id } ] 模型切换成功: { state .current_ai_studio_model_id } "
64- )
65+ logger .info (f"模型切换成功: { state .current_ai_studio_model_id } " )
6566 else :
6667 await _handle_model_switch_failure (
6768 req_id ,
@@ -77,7 +78,8 @@ async def handle_model_switching(
7778async def _handle_model_switch_failure (
7879 req_id : str , page : AsyncPage , model_id_to_use : str , model_before_switch : str , logger
7980) -> None :
80- logger .warning (f"[{ req_id } ] 模型切换至 { model_id_to_use } 失败。" )
81+ set_request_id (req_id )
82+ logger .warning (f"模型切换至 { model_id_to_use } 失败。" )
8183 state .current_ai_studio_model_id = model_before_switch
8284 from .error_utils import http_error
8385
@@ -87,6 +89,7 @@ async def _handle_model_switch_failure(
8789
8890
8991async def handle_parameter_cache (req_id : str , context : RequestContext ) -> None :
92+ set_request_id (req_id )
9093 logger = context ["logger" ]
9194 params_cache_lock = context ["params_cache_lock" ]
9295 page_params_cache = context ["page_params_cache" ]
@@ -100,7 +103,7 @@ async def handle_parameter_cache(req_id: str, context: RequestContext) -> None:
100103 if model_actually_switched or (
101104 current_ai_studio_model_id != cached_model_for_params
102105 ):
103- logger .info (f"[ { req_id } ] 模型已更改,参数缓存失效。" )
106+ logger .info (" 模型已更改,参数缓存失效。" )
104107 page_params_cache .clear ()
105108 page_params_cache ["last_known_model_id_for_params" ] = (
106109 current_ai_studio_model_id
0 commit comments