mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-25 16:23:22 +08:00
20 lines
571 B
Python
20 lines
571 B
Python
import json
|
|
from typing import TYPE_CHECKING, Any, Dict
|
|
|
|
if TYPE_CHECKING:
|
|
from ..._models import BaseModel
|
|
|
|
|
|
def dictify(data: "BaseModel") -> Dict[str, Any]:
|
|
try: # pydantic v2
|
|
return data.model_dump(exclude_unset=True)
|
|
except Exception: # 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 Exception: # pydantic v1
|
|
return data.json(exclude_unset=True, ensure_ascii=False)
|