kikocis/llama-stack public
| 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | # All rights reserved. |
| 3 | # |
| 4 | # This source code is licensed under the terms described in the LICENSE file in |
| 5 | # the root directory of this source tree. |
| 6 | |
| 7 | import json |
| 8 | from datetime import datetime |
| 9 | from enum import Enum |
| 10 | |
| 11 | |
| 12 | class EnumEncoder(json.JSONEncoder): |
| 13 | def default(self, obj): |
| 14 | if isinstance(obj, Enum): |
| 15 | return obj.value |
| 16 | elif isinstance(obj, datetime): |
| 17 | return obj.isoformat() |
| 18 | return super().default(obj) |