dify/api/core/tools/utils/encoder.py
2024-02-01 18:11:57 +08:00

24 lines
510 B
Python

from enum import Enum
from typing import List
from pydantic import BaseModel
def serialize_base_model_array(l: List[BaseModel]) -> str:
class _BaseModel(BaseModel):
__root__: List[BaseModel]
"""
{"__root__": [BaseModel, BaseModel, ...]}
"""
return _BaseModel(__root__=l).json()
def serialize_base_model_dict(b: dict) -> str:
class _BaseModel(BaseModel):
__root__: dict
"""
{"__root__": {BaseModel}}
"""
return _BaseModel(__root__=b).json()