Skip to content

Commit

Permalink
chore: add test for msgspec json schema convertion
Browse files Browse the repository at this point in the history
  • Loading branch information
luochen1990 committed Aug 7, 2024
1 parent fa25797 commit a0a8d7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/examples/ai_powered_decorator/gen_user_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/json_schema/annotated.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit a0a8d7c

Please sign in to comment.