fix: serialize non serializable (#589)

This commit is contained in:
cachho
2023-09-12 05:55:46 +02:00
committed by GitHub
parent 7c39d9f0c1
commit 1864f4cb38
2 changed files with 27 additions and 1 deletions

View File

@@ -1,8 +1,9 @@
import random
import unittest
from string import Template
from embedchain import App
from embedchain.config import AppConfig
from embedchain.config import AppConfig, BaseLlmConfig
from embedchain.helper.json_serializable import (JSONSerializable,
register_deserializable)
@@ -69,3 +70,11 @@ class TestJsonSerializable(unittest.TestCase):
self.assertEqual(random_id, new_app.config.id)
# We have proven that a nested class (app.config) can be serialized and deserialized just the same.
# TODO: test deeper recursion
def test_special_subclasses(self):
"""Test special subclasses that are not serializable by default."""
# Template
config = BaseLlmConfig(template=Template("My custom template with $query, $context and $history."))
s = config.serialize()
new_config: BaseLlmConfig = BaseLlmConfig.deserialize(s)
self.assertEqual(config.template.template, new_config.template.template)