From a0a8d7c7e1b8019a19269ba10e9970292345cb63 Mon Sep 17 00:00:00 2001 From: LuoChen Date: Wed, 7 Aug 2024 17:42:52 +0800 Subject: [PATCH] chore: add test for msgspec json schema convertion --- .../ai_powered_decorator/gen_user_info.py | 1 + test/json_schema/annotated.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/json_schema/annotated.py diff --git a/test/examples/ai_powered_decorator/gen_user_info.py b/test/examples/ai_powered_decorator/gen_user_info.py index fa8943e..eacd7ca 100644 --- a/test/examples/ai_powered_decorator/gen_user_info.py +++ b/test/examples/ai_powered_decorator/gen_user_info.py @@ -10,6 +10,7 @@ class UserInfo: @ai_powered def gen_user_info() -> UserInfo: + ''' ramdomly generate user info for testing, None is used for unknown fields ''' ... @ai_powered diff --git a/test/json_schema/annotated.py b/test/json_schema/annotated.py new file mode 100644 index 0000000..963e3cc --- /dev/null +++ b/test/json_schema/annotated.py @@ -0,0 +1,18 @@ +import json +import msgspec +from typing_extensions import Annotated +from pydantic.dataclasses import dataclass +from typing import Optional + +from ai_powered.schema_deref import deref + +@dataclass +class UserInfo: + name: str + country: Annotated[Optional[str], "None is used for unknown cases"] + age: Annotated[Optional[str], "None is used for unknown cases"] + +if __name__ == "__main__": + schema = msgspec.json.schema(UserInfo) + print("schema =", json.dumps(schema, indent=2)) + print("deref(schema) =", json.dumps(deref(schema), indent=2))