logger.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from typing import List, Optional, Union
  2. from loguru import logger
  3. from aphrodite.common.pooling_params import PoolingParams
  4. from aphrodite.common.sampling_params import SamplingParams
  5. from aphrodite.lora.request import LoRARequest
  6. from aphrodite.prompt_adapter.request import PromptAdapterRequest
  7. class RequestLogger:
  8. def __init__(self, *, max_log_len: Optional[int]) -> None:
  9. super().__init__()
  10. self.max_log_len = max_log_len
  11. def log_inputs(
  12. self,
  13. request_id: str,
  14. prompt: Optional[str],
  15. prompt_token_ids: Optional[List[int]],
  16. params: Optional[Union[SamplingParams, PoolingParams]],
  17. lora_request: Optional[LoRARequest],
  18. prompt_adapter_request: Optional[PromptAdapterRequest],
  19. ) -> None:
  20. max_log_len = self.max_log_len
  21. if max_log_len is not None:
  22. if prompt is not None:
  23. prompt = prompt[:max_log_len]
  24. if prompt_token_ids is not None:
  25. prompt_token_ids = prompt_token_ids[:max_log_len]
  26. logger.info(f"Received request {request_id}: "
  27. f"prompt: {prompt}, "
  28. f"params: {params}, "
  29. f"prompt_token_ids: {prompt_token_ids}, "
  30. f"lora_request: {lora_request}, "
  31. f"prompt_adapter_request: {prompt_adapter_request}.")