mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
24 lines
510 B
Python
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()
|