mirror of
https://github.com/hiyouga/LLaMA-Factory.git
synced 2025-11-05 18:32:14 +08:00
2. Added the log of printing requests when deploying using vllm Former-commit-id: 530d4f5d51c13c71d99de5fe2d23805b0aa875a2
21 lines
570 B
Python
21 lines
570 B
Python
import json
|
|
from typing import TYPE_CHECKING, Any, Dict
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
from pydantic import BaseModel
|
|
|
|
|
|
def dictify(data: "BaseModel", **kwargs) -> Dict[str, Any]:
|
|
try: # pydantic v2
|
|
return data.model_dump(**kwargs)
|
|
except AttributeError: # pydantic v1
|
|
return data.dict(**kwargs)
|
|
|
|
|
|
def jsonify(data: "BaseModel") -> str:
|
|
try: # pydantic v2
|
|
return json.dumps(data.model_dump(exclude_unset=True), ensure_ascii=False)
|
|
except AttributeError: # pydantic v1
|
|
return data.json(exclude_unset=True, ensure_ascii=False)
|