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