mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-04-23 06:09:43 +08:00

Co-authored-by: chenhe <guchenhe@gmail.com> Co-authored-by: Pascal M <11357019+perzeuss@users.noreply.github.com>
22 lines
508 B
Python
22 lines
508 B
Python
from pydantic import BaseModel
|
|
from enum import Enum
|
|
from typing import List
|
|
|
|
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()
|