Download LLaMA-Factory/src/llamafactory/api/common.py from LittleCxwx/CER_SRLM: direct link, hf CLI and curl.
- Browser
- Download file 580 Bytes
-
https://huggingface.co/LittleCxwx/CER_SRLM/resolve/main/LLaMA-Factory/src/llamafactory/api/common.py
- Command line
-
hf download hf://LittleCxwx/CER_SRLM/LLaMA-Factory/src/llamafactory/api/common.py
-
curl -L -o common.py https://huggingface.co/LittleCxwx/CER_SRLM/resolve/main/LLaMA-Factory/src/llamafactory/api/common.py
580 Bytes
| import json | |
| from typing import TYPE_CHECKING, Any, Dict | |
| if TYPE_CHECKING: | |
| from pydantic import BaseModel | |
| def dictify(data: "BaseModel") -> Dict[str, Any]: | |
| try: # pydantic v2 | |
| return data.model_dump(exclude_unset=True) | |
| except AttributeError: # pydantic v1 | |
| return data.dict(exclude_unset=True) | |
| 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) | |