Download api_utils/context_init.py from dakl45646/sd: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/dakl45646/sd/resolve/main/api_utils/context_init.py
- Command line
-
hf download hf://spaces/dakl45646/sd/api_utils/context_init.py
-
curl -L -o context_init.py https://huggingface.co/spaces/dakl45646/sd/resolve/main/api_utils/context_init.py
1.18 kB
| from typing import Any | |
| from models import ChatCompletionRequest | |
| from .context_types import RequestContext | |
| async def initialize_request_context(req_id: str, request: ChatCompletionRequest) -> RequestContext: | |
| from server import ( | |
| logger, page_instance, is_page_ready, parsed_model_list, | |
| current_ai_studio_model_id, model_switching_lock, page_params_cache, | |
| params_cache_lock, | |
| ) | |
| logger.info(f"[{req_id}] 开始处理请求...") | |
| logger.info(f"[{req_id}] 请求参数 - Model: {request.model}, Stream: {request.stream}") | |
| context: RequestContext = { | |
| 'logger': logger, | |
| 'page': page_instance, | |
| 'is_page_ready': is_page_ready, | |
| 'parsed_model_list': parsed_model_list, | |
| 'current_ai_studio_model_id': current_ai_studio_model_id, | |
| 'model_switching_lock': model_switching_lock, | |
| 'page_params_cache': page_params_cache, | |
| 'params_cache_lock': params_cache_lock, | |
| 'is_streaming': request.stream, | |
| 'model_actually_switched': False, | |
| 'requested_model': request.model, | |
| 'model_id_to_use': None, | |
| 'needs_model_switching': False, | |
| } | |
| return context | |